-
-
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
07d08b2
commit 349e81e
Showing
4 changed files
with
91 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,13 @@ | ||
/** | ||
* @file Type Tests - isTypedArray | ||
* @module tutils/utils/tests/unit-d/isTypedArray | ||
*/ | ||
|
||
import type { TypedArray } from '#src/types' | ||
import type testSubject from '../is-typed-array' | ||
|
||
describe('unit-d:utils/isTypedArray', () => { | ||
it('should guard TypedArray', () => { | ||
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<TypedArray>() | ||
}) | ||
}) |
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,32 @@ | ||
/** | ||
* @file Unit Tests - isTypedArray | ||
* @module tutils/utils/tests/unit/isTypedArray | ||
*/ | ||
|
||
import testSubject from '../is-typed-array' | ||
|
||
describe('unit:utils/isTypedArray', () => { | ||
it('should return false if value is not TypedArray instance', () => { | ||
expect(testSubject(new ArrayBuffer(8))).to.be.false | ||
}) | ||
|
||
it('should return true if value is TypedArray instance', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [ | ||
[new BigInt64Array()], | ||
[new BigUint64Array()], | ||
[new Float32Array()], | ||
[new Float64Array()], | ||
[new Int8Array()], | ||
[new Int16Array()], | ||
[new Int32Array()], | ||
[new Uint8Array()], | ||
[new Uint8ClampedArray()], | ||
[new Uint16Array()], | ||
[new Uint32Array()] | ||
] | ||
|
||
// Act + Expect | ||
cases.forEach(([value]) => expect(testSubject(value)).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,45 @@ | ||
/** | ||
* @file Utilities - isTypedArray | ||
* @module tutils/utils/isTypedArray | ||
*/ | ||
|
||
import type { TypedArray } from '#src/types' | ||
import isBigInt64Array from './is-big-int64-array' | ||
import isBigUint64Array from './is-big-uint64-array' | ||
import isFloat32Array from './is-float32-array' | ||
import isFloat64Array from './is-float64-array' | ||
import isInt16Array from './is-int16-array' | ||
import isInt32Array from './is-int32-array' | ||
import isInt8Array from './is-int8-array' | ||
import isUint16Array from './is-uint16-array' | ||
import isUint32Array from './is-uint32-array' | ||
import isUint8Array from './is-uint8-array' | ||
import isUint8ClampedArray from './is-uint8-clamped-array' | ||
|
||
/** | ||
* Checks if `value` is a {@linkcode TypedArray} instance. | ||
* | ||
* @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||
* | ||
* @todo examples | ||
* | ||
* @param {unknown} value - Value to check | ||
* @return {value is TypedArray} `true` if `value` is `TypedArray` instance | ||
*/ | ||
const isTypedArray = (value: unknown): value is TypedArray => { | ||
return ( | ||
isBigInt64Array(value) || | ||
isBigUint64Array(value) || | ||
isFloat32Array(value) || | ||
isFloat64Array(value) || | ||
isInt8Array(value) || | ||
isInt16Array(value) || | ||
isInt32Array(value) || | ||
isUint8Array(value) || | ||
isUint8ClampedArray(value) || | ||
isUint16Array(value) || | ||
isUint32Array(value) | ||
) | ||
} | ||
|
||
export default isTypedArray |