-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
703fd70
commit 469f4ac
Showing
4 changed files
with
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* @file Type Tests - isArray | ||
* @module tutils/utils/tests/unit-d/isArray | ||
*/ | ||
|
||
import type testSubject from '../is-array' | ||
|
||
describe('unit-d:utils/isArray', () => { | ||
it('should guard T[] | readonly T[]', () => { | ||
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf< | ||
unknown[] | readonly unknown[] | ||
>() | ||
}) | ||
}) |
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,16 @@ | ||
/** | ||
* @file Unit Tests - isArray | ||
* @module tutils/utils/tests/unit/isArray | ||
*/ | ||
|
||
import testSubject from '../is-array' | ||
|
||
describe('unit:utils/isArray', () => { | ||
it('should return false if value is not an array', () => { | ||
expect(testSubject(faker.datatype.boolean())).to.be.false | ||
}) | ||
|
||
it('should return true if value is an array', () => { | ||
expect(testSubject([0, 1, 2, 3, 4])).to.be.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @file Utilities - isArray | ||
* @module tutils/utils/isArray | ||
*/ | ||
|
||
import isObject from './is-object' | ||
|
||
/** | ||
* Checks if `value` is an array. | ||
* | ||
* @template T - Array item type | ||
* | ||
* @param {unknown} value - Value to check | ||
* @return {value is ReadonlyArray<T> | T[]} `true` if `value` is an array | ||
*/ | ||
function isArray<T>(value: unknown): value is T[] | readonly T[] { | ||
return isObject(value) && Reflect.get(value, 'constructor') === Array | ||
} | ||
|
||
export default isArray |