Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
86 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { either } from 'ramda'; | ||
import curry1 from 'ramda/src/internal/_curry1'; | ||
|
||
import isArray from './isArray'; | ||
import isString from './isString'; | ||
|
||
/** | ||
* Determine if input value is an indexed data type. | ||
* | ||
* @func isIndexed | ||
* @memberOf RA | ||
* @since {@link https://char0n.github.io/ramda-adjunct/2.26.0|v2.26.0} | ||
* @category Type | ||
* @sig * -> Boolean | ||
* @param {*} val The value to test | ||
* @return {boolean} | ||
* @example | ||
* | ||
* RA.isIndexed([1]) //=> true | ||
* RA.isIndexed('test') //=> true | ||
*/ | ||
|
||
const isIndexed = curry1(either(isString, isArray)); | ||
|
||
export default isIndexed; |
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,37 @@ | ||
import { assert } from 'chai'; | ||
import * as R from 'ramda'; | ||
|
||
import * as RA from '../src'; | ||
|
||
describe('isIndexed', function() { | ||
context('given a `String` value', function() { | ||
specify('should return true', function() { | ||
assert.isTrue(RA.isIndexed('test')); | ||
assert.isTrue(RA.isIndexed(Object('test'))); | ||
assert.isTrue(RA.isIndexed('')); | ||
}); | ||
}); | ||
|
||
context('given array value', function() { | ||
specify('should return true', function() { | ||
assert.isTrue(RA.isIndexed([])); | ||
assert.isTrue(RA.isIndexed([1, 2])); | ||
}); | ||
}); | ||
|
||
context('given a non `String` or `Array` value', function() { | ||
specify('should return false', function() { | ||
assert.isFalse(RA.isIndexed(true)); | ||
assert.isFalse(RA.isIndexed(new Date())); | ||
assert.isFalse(RA.isIndexed(new Error())); | ||
assert.isFalse(RA.isIndexed({ 0: 1, length: 1 })); | ||
assert.isFalse(RA.isIndexed(1)); | ||
}); | ||
}); | ||
|
||
it('should support placeholder to specify "gaps"', function() { | ||
const isIndexed = RA.isIndexed(R.__); | ||
|
||
assert.isTrue(isIndexed([])); | ||
}); | ||
}); |
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,18 @@ | ||
import * as RA from 'ramda-adjunct'; | ||
|
||
RA.isIndexed(-0); // $ExpectType boolean | ||
RA.isIndexed(+0); // $ExpectType boolean | ||
RA.isIndexed(null); // $ExpectType boolean | ||
RA.isIndexed(true); // $ExpectType boolean | ||
RA.isIndexed(NaN); // $ExpectType boolean | ||
RA.isIndexed({}); // $ExpectType boolean | ||
RA.isIndexed([]); // $ExpectType boolean | ||
RA.isIndexed(() => {}); // $ExpectType boolean | ||
RA.isIndexed('string'); // $ExpectType boolean | ||
RA.isIndexed(1); // $ExpectType boolean | ||
RA.isIndexed(0.1); // $ExpectType boolean | ||
RA.isIndexed(Object(0.1)); // $ExpectType boolean | ||
RA.isIndexed(NaN); // $ExpectType boolean | ||
RA.isIndexed(Infinity); // $ExpectType boolean | ||
RA.isIndexed(Number.MAX_VALUE); // $ExpectType boolean | ||
RA.isIndexed(Number.MIN_VALUE); // $ExpectType boolean |