-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add lengthEq and lengthNotEq (#552)
Closes #444
- Loading branch information
1 parent
92ba7b5
commit f71ad1e
Showing
14 changed files
with
288 additions
and
88 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
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,24 @@ | ||
import { equals } from 'ramda'; | ||
|
||
import compareLength from './internal/compareLength'; | ||
|
||
/** | ||
* Returns `true` if the supplied list or string has a length equal to `valueLength`. | ||
* | ||
* @func lengthEq | ||
* @memberOf RA | ||
* @since {@link https://char0n.github.io/ramda-adjunct/2.8.0|v2.8.0} | ||
* @category List | ||
* @sig Number -> [*] -> Boolean | ||
* @param {number} valueLength The length of the list or string | ||
* @param {Array|string} value The list or string | ||
* @return {boolean} | ||
* @see {@link RA.lengthNotEq|lengthNotEq}, {@link RA.lengthLt|lengthLt}, {@link RA.lengthGt|lengthGt}, {@link RA.lengthLte|lengthLte}, {@link RA.lengthGte|lengthGte},, {@link http://ramdajs.com/docs/#equals|equals}, {@link http://ramdajs.com/docs/#length|length} | ||
* @example | ||
* | ||
* RA.lengthEq(3, [1,2,3]); //=> true | ||
* RA.lengthEq(3, [1,2,3,4]); //=> false | ||
*/ | ||
const lengthEq = compareLength(equals); | ||
|
||
export default lengthEq; |
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
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,24 @@ | ||
import { complement, equals } from 'ramda'; | ||
|
||
import compareLength from './internal/compareLength'; | ||
|
||
/** | ||
* Returns `true` if the supplied list or string has a length not equal to `valueLength`. | ||
* | ||
* @func lengthNotEq | ||
* @memberOf RA | ||
* @since {@link https://char0n.github.io/ramda-adjunct/2.8.0|v2.8.0} | ||
* @category List | ||
* @sig Number -> [*] -> Boolean | ||
* @param {number} valueLength The length of the list or string | ||
* @param {Array|string} value The list or string | ||
* @return {boolean} | ||
* @see {@link RA.lengthEq|lengthEq}, {@link RA.lengthLt|lengthLt}, {@link RA.lengthGt|lengthGt}, {@link RA.lengthLte|lengthLte}, {@link RA.lengthGte|lengthGte}, {@link http://ramdajs.com/docs/#equals|equals}, {@link http://ramdajs.com/docs/#length|length} | ||
* @example | ||
* | ||
* RA.lengthNotEq(3, [1,2,3,4]); //=> true | ||
* RA.lengthNotEq(3, [1,2,3]); //=> false | ||
*/ | ||
const lengthNotEq = compareLength(complement(equals)); | ||
|
||
export default lengthNotEq; |
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,45 @@ | ||
import * as RA from '../src/index'; | ||
import eq from './shared/eq'; | ||
|
||
describe('lengthEq', function() { | ||
context( | ||
`when the length of a list is equal to the supplied length`, | ||
function() { | ||
specify(`should return true`, function() { | ||
eq(RA.lengthEq(3, [1, 2, 3]), true); | ||
eq(RA.lengthEq(3, [1, 2, 3, 4]), false); | ||
eq(RA.lengthEq(3, [1, 2]), false); | ||
eq(RA.lengthEq(0, []), true); | ||
}); | ||
} | ||
); | ||
|
||
context( | ||
`when the length of a string is equal to the supplied length`, | ||
function() { | ||
specify(`should return true`, function() { | ||
eq(RA.lengthEq(3, 'abc'), true); | ||
eq(RA.lengthEq(3, 'abcd'), false); | ||
eq(RA.lengthEq(3, 'ab'), false); | ||
eq(RA.lengthEq(0, ''), true); | ||
}); | ||
} | ||
); | ||
|
||
context(`when a value doesn't have a length property`, function() { | ||
specify(`should return true`, function() { | ||
eq(RA.lengthEq(1, NaN), false); | ||
eq(RA.lengthEq(1, undefined), false); | ||
eq(RA.lengthEq(1, null), false); | ||
eq(RA.lengthEq(1, {}), false); | ||
eq(RA.lengthEq(1, true), false); | ||
eq(RA.lengthEq(1, false), false); | ||
eq(RA.lengthEq(1, 5), false); | ||
}); | ||
}); | ||
|
||
it(`should be curried`, function() { | ||
eq(RA.lengthEq(2, [1, 2]), true); | ||
eq(RA.lengthEq(2)([1, 2]), true); | ||
}); | ||
}); |
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
Oops, something went wrong.