-
-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = function containsOneItem() { | ||
return this.count() === 1; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# `containsOneItem()` | ||
|
||
The containsOneItem method returns true if the collection contains exactly one item; otherwise, false is returned: | ||
|
||
```js | ||
collect([1]).containsOneItem(); | ||
// true | ||
|
||
collect({ firstname: 'Luis' }).containsOneItem(); | ||
// true | ||
|
||
collect('value').containsOneItem(); | ||
// true | ||
|
||
collect([1, 2, 3]).containsOneItem(); | ||
// false | ||
|
||
collect({ firstname: 'Luis', lastname: 'Díaz' }).containsOneItem(); | ||
// false | ||
|
||
collect().containsOneItem(); | ||
// false | ||
|
||
collect([]).containsOneItem(); | ||
// false | ||
|
||
collect({}).containsOneItem(); | ||
// false | ||
``` | ||
|
||
[View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/containsOneItem.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = function containsOneItem() { | ||
return this.count() === 1; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
module.exports = (it, expect, collect) => { | ||
it('should test if collection contains one item', () => { | ||
expect(collect().containsOneItem()).to.eql(false); | ||
expect(collect([]).containsOneItem()).to.eql(false); | ||
expect(collect({}).containsOneItem()).to.eql(false); | ||
|
||
expect(collect([1]).containsOneItem()).to.eql(true); | ||
expect(collect('').containsOneItem()).to.eql(true); | ||
expect(collect('xo').containsOneItem()).to.eql(true); | ||
expect(collect(['']).containsOneItem()).to.eql(true); | ||
expect(collect('a', 'b').containsOneItem()).to.eql(true); | ||
expect(collect('value').containsOneItem()).to.eql(true); | ||
expect(collect(['value']).containsOneItem()).to.eql(true); | ||
expect(collect({ key: 'value' }).containsOneItem()).to.eql(true); | ||
|
||
expect(collect([1, 2, 3]).containsOneItem()).to.eql(false); | ||
expect(collect({ key: 'value', value: 'key' }).containsOneItem()).to.eql(false); | ||
expect(collect([{ key: 'value' }, { key: 'value' }]).containsOneItem()).to.eql(false); | ||
}); | ||
}; |