-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add lengthLt, lengthGt, lengthLte, lengthGte
- Loading branch information
1 parent
cc12528
commit 47d4560
Showing
11 changed files
with
264 additions
and
1 deletion.
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,7 @@ | ||
import { curry, compose, length } from 'ramda'; | ||
|
||
const compareLength = curry((comparator, value, list) => | ||
compose(comparator(value), length)(list) | ||
); | ||
|
||
export default compareLength; |
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 { gt, flip } from 'ramda'; | ||
|
||
import compareLength from './internal/compareLength'; | ||
|
||
/** | ||
* Returns `true` if the supplied list or string has a length greater than `valueLength`. | ||
* | ||
* @func lengthGt | ||
* @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 {number} value The list or string | ||
* @return {boolean} | ||
* @see {@link http://ramdajs.com/docs/#gt|gt}, {@link http://ramdajs.com/docs/#length|length} | ||
* @example | ||
* | ||
* RA.lengthGt(3, [1,2,3,4]); //=> true | ||
* RA.lengthGt(3, [1,2,3]); //=> false | ||
*/ | ||
const lengthGt = compareLength(flip(gt)); | ||
|
||
export default lengthGt; |
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,26 @@ | ||
import { gte, flip } from 'ramda'; | ||
|
||
import compareLength from './internal/compareLength'; | ||
|
||
/** | ||
* Returns `true` if the supplied list or string has a length greater than or equal to | ||
* `valueLength`. | ||
* | ||
* @func lengthGte | ||
* @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 {number} value The list or string | ||
* @return {boolean} | ||
* @see {@link http://ramdajs.com/docs/#gte|gte}, {@link http://ramdajs.com/docs/#length|length} | ||
* @example | ||
* | ||
* RA.lengthGte(3, [1,2,3,4]); //=> true | ||
* RA.lengthGte(3, [1,2,3]); //=> true | ||
* RA.lengthGte(3, [1,2,3]); //=> false | ||
*/ | ||
const lengthGte = compareLength(flip(gte)); | ||
|
||
export default lengthGte; |
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 { lt, flip } from 'ramda'; | ||
|
||
import compareLength from './internal/compareLength'; | ||
|
||
/** | ||
* Returns `true` if the supplied list or string has a length less than `valueLength`. | ||
* | ||
* @func lengthLt | ||
* @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 {number} value The list or string | ||
* @return {boolean} | ||
* @see {@link http://ramdajs.com/docs/#lt|lt}, {@link http://ramdajs.com/docs/#length|length} | ||
* @example | ||
* | ||
* RA.lengthLt(3, [1,2]); //=> true | ||
* RA.lengthLt(3, [1,2,3]); //=> false | ||
*/ | ||
const lengthLt = compareLength(flip(lt)); | ||
|
||
export default lengthLt; |
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,25 @@ | ||
import { lte, flip } from 'ramda'; | ||
|
||
import compareLength from './internal/compareLength'; | ||
|
||
/** | ||
* Returns `true` if the supplied list or string has a length less than or equal to `valueLength`. | ||
* | ||
* @func lengthLte | ||
* @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 {number} value The list or string | ||
* @return {boolean} | ||
* @see {@link http://ramdajs.com/docs/#lte|lte}, {@link http://ramdajs.com/docs/#length|length} | ||
* @example | ||
* | ||
* RA.lengthLte(3, [1,2]); //=> true | ||
* RA.lengthLte(3, [1,2,3]); //=> true | ||
* RA.lengthLte(3, [1,2,3,4]); //=> false | ||
*/ | ||
const lengthLte = compareLength(flip(lte)); | ||
|
||
export default lengthLte; |
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 @@ | ||
import * as RA from '../src/index'; | ||
import eq from './shared/eq'; | ||
|
||
describe('lengthGt', function() { | ||
it(`should return true if the length of a list is greater than supplied length`, function() { | ||
eq(RA.lengthGt(3, [1, 2, 3, 4]), true); | ||
eq(RA.lengthGt(3, [1, 2, 3]), false); | ||
eq(RA.lengthGt(0, []), false); | ||
}); | ||
|
||
it(`should return true if the length of a string is greater than supplied length`, function() { | ||
eq(RA.lengthGt(3, 'abcd'), true); | ||
eq(RA.lengthGt(3, 'abc'), false); | ||
eq(RA.lengthGt(0, ''), false); | ||
}); | ||
|
||
it(`should return false for values without a length property`, function() { | ||
eq(RA.lengthGt(1, NaN), false); | ||
eq(RA.lengthGt(1, undefined), false); | ||
eq(RA.lengthGt(1, null), false); | ||
eq(RA.lengthGt(1, {}), false); | ||
eq(RA.lengthGt(1, true), false); | ||
eq(RA.lengthGt(1, false), false); | ||
eq(RA.lengthGt(1, 5), false); | ||
}); | ||
|
||
it(`should be curried`, function() { | ||
eq(RA.lengthGt(1, [1, 2]), true); | ||
eq(RA.lengthGt(1)([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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as RA from '../src/index'; | ||
import eq from './shared/eq'; | ||
|
||
describe('lengthGte', function() { | ||
it(`should return true if the length of a list is greater than or equal to the supplied length`, function() { | ||
eq(RA.lengthGte(3, [1, 2, 3, 4]), true); | ||
eq(RA.lengthGte(3, [1, 2, 3]), true); | ||
eq(RA.lengthGte(3, [1, 2]), false); | ||
eq(RA.lengthGte(0, []), true); | ||
}); | ||
|
||
it(`should return true if the length of a string is greater than or equal to the supplied length`, function() { | ||
eq(RA.lengthGte(3, 'abcd'), true); | ||
eq(RA.lengthGte(3, 'abc'), true); | ||
eq(RA.lengthGte(3, 'ab'), false); | ||
eq(RA.lengthGte(0, ''), true); | ||
}); | ||
|
||
it(`should return false for values without a length property`, function() { | ||
eq(RA.lengthGte(1, NaN), false); | ||
eq(RA.lengthGte(1, undefined), false); | ||
eq(RA.lengthGte(1, null), false); | ||
eq(RA.lengthGte(1, {}), false); | ||
eq(RA.lengthGte(1, true), false); | ||
eq(RA.lengthGte(1, false), false); | ||
eq(RA.lengthGte(1, 5), false); | ||
}); | ||
|
||
it(`should be curried`, function() { | ||
eq(RA.lengthGte(1, [1]), true); | ||
eq(RA.lengthGte(1)([1]), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as RA from '../src/index'; | ||
import eq from './shared/eq'; | ||
|
||
describe('lengthLt', function() { | ||
it(`should return true if the length of a list is less than supplied length`, function() { | ||
eq(RA.lengthLt(3, [1, 2]), true); | ||
eq(RA.lengthLt(3, [1, 2, 3]), false); | ||
eq(RA.lengthLt(0, []), false); | ||
}); | ||
|
||
it(`should return true if the length of a string is less than supplied length`, function() { | ||
eq(RA.lengthLt(3, 'ab'), true); | ||
eq(RA.lengthLt(3, 'abc'), false); | ||
eq(RA.lengthLt(0, ''), false); | ||
}); | ||
|
||
it(`should return false for values without a length property`, function() { | ||
eq(RA.lengthLt(1, NaN), false); | ||
eq(RA.lengthLt(1, undefined), false); | ||
eq(RA.lengthLt(1, null), false); | ||
eq(RA.lengthLt(1, {}), false); | ||
eq(RA.lengthLt(1, true), false); | ||
eq(RA.lengthLt(1, false), false); | ||
eq(RA.lengthLt(1, 5), false); | ||
}); | ||
|
||
it(`should be curried`, function() { | ||
eq(RA.lengthLt(2, [1]), true); | ||
eq(RA.lengthLt(2)([1]), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as RA from '../src/index'; | ||
import eq from './shared/eq'; | ||
|
||
describe('lengthLte', function() { | ||
it(`should return true if the length of a list is less than or equal to the supplied length`, function() { | ||
eq(RA.lengthLte(3, [1, 2]), true); | ||
eq(RA.lengthLte(3, [1, 2, 3]), true); | ||
eq(RA.lengthLte(3, [1, 2, 3, 4]), false); | ||
eq(RA.lengthLte(0, []), true); | ||
}); | ||
|
||
it(`should return true if the length of a string is less than or equal to the supplied length`, function() { | ||
eq(RA.lengthLte(3, 'ab'), true); | ||
eq(RA.lengthLte(3, 'abc'), true); | ||
eq(RA.lengthLte(3, 'abcd'), false); | ||
eq(RA.lengthLte(0, ''), true); | ||
}); | ||
|
||
it(`should return false for values without a length property`, function() { | ||
eq(RA.lengthLte(1, NaN), false); | ||
eq(RA.lengthLte(1, undefined), false); | ||
eq(RA.lengthLte(1, null), false); | ||
eq(RA.lengthLte(1, {}), false); | ||
eq(RA.lengthLte(1, true), false); | ||
eq(RA.lengthLte(1, false), false); | ||
eq(RA.lengthLte(1, 5), false); | ||
}); | ||
|
||
it(`should be curried`, function() { | ||
eq(RA.lengthLte(1, [1]), true); | ||
eq(RA.lengthLte(1)([1]), true); | ||
}); | ||
}); |