Skip to content

Commit

Permalink
feat(utils): isInt8Array, isInt16Array, isInt32Array
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Jul 20, 2023
1 parent dfaa227 commit a8d1f1d
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils/__tests__/is-int16-array.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file Type Tests - isInt16Array
* @module tutils/utils/tests/unit-d/isInt16Array
*/

import type testSubject from '../is-int16-array'

describe('unit-d:utils/isInt16Array', () => {
it('should guard Int16Array', () => {
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<Int16Array>()
})
})
16 changes: 16 additions & 0 deletions src/utils/__tests__/is-int16-array.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file Unit Tests - isInt16Array
* @module tutils/utils/tests/unit/isInt16Array
*/

import testSubject from '../is-int16-array'

describe('unit:utils/isInt16Array', () => {
it('should return false if value is not Int16Array instance', () => {
expect(testSubject(new Uint16Array())).to.be.false
})

it('should return true if value is Int16Array instance', () => {
expect(testSubject(new Int16Array())).to.be.true
})
})
12 changes: 12 additions & 0 deletions src/utils/__tests__/is-int32-array.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file Type Tests - isInt32Array
* @module tutils/utils/tests/unit-d/isInt32Array
*/

import type testSubject from '../is-int32-array'

describe('unit-d:utils/isInt32Array', () => {
it('should guard Int32Array', () => {
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<Int32Array>()
})
})
16 changes: 16 additions & 0 deletions src/utils/__tests__/is-int32-array.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file Unit Tests - isInt32Array
* @module tutils/utils/tests/unit/isInt32Array
*/

import testSubject from '../is-int32-array'

describe('unit:utils/isInt32Array', () => {
it('should return false if value is not Int32Array instance', () => {
expect(testSubject(new Uint32Array())).to.be.false
})

it('should return true if value is Int32Array instance', () => {
expect(testSubject(new Int32Array())).to.be.true
})
})
12 changes: 12 additions & 0 deletions src/utils/__tests__/is-int8-array.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file Type Tests - isInt8Array
* @module tutils/utils/tests/unit-d/isInt8Array
*/

import type testSubject from '../is-int8-array'

describe('unit-d:utils/isInt8Array', () => {
it('should guard Int8Array', () => {
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<Int8Array>()
})
})
16 changes: 16 additions & 0 deletions src/utils/__tests__/is-int8-array.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file Unit Tests - isInt8Array
* @module tutils/utils/tests/unit/isInt8Array
*/

import testSubject from '../is-int8-array'

describe('unit:utils/isInt8Array', () => {
it('should return false if value is not Int8Array instance', () => {
expect(testSubject(new Uint8Array())).to.be.false
})

it('should return true if value is Int8Array instance', () => {
expect(testSubject(new Int8Array())).to.be.true
})
})
3 changes: 3 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export { default as isFloat } from './is-float'
export { default as isFloat32Array } from './is-float32-array'
export { default as isFloat64Array } from './is-float64-array'
export { default as isFunction } from './is-function'
export { default as isInt16Array } from './is-int16-array'
export { default as isInt32Array } from './is-int32-array'
export { default as isInt8Array } from './is-int8-array'
export { default as isInteger } from './is-integer'
export { default as isJsonPrimitive } from './is-json-primitive'
export { default as isLowercase } from './is-lowercase'
Expand Down
23 changes: 23 additions & 0 deletions src/utils/is-int16-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @file Utilities - isInt16Array
* @module tutils/utils/isInt16Array
*/

import equal from './equal'
import isObject from './is-object'

/**
* Checks if `value` is an {@linkcode Int16Array} instance.
*
* @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
*
* @todo examples
*
* @param {unknown} value - Value to check
* @return {value is Int16Array} `true` if `value` is a `Int16Array`
*/
const isInt16Array = (value: unknown): value is Int16Array => {
return isObject(value) && equal(value.constructor, Int16Array)
}

export default isInt16Array
23 changes: 23 additions & 0 deletions src/utils/is-int32-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @file Utilities - isInt32Array
* @module tutils/utils/isInt32Array
*/

import equal from './equal'
import isObject from './is-object'

/**
* Checks if `value` is an {@linkcode Int32Array} instance.
*
* @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
*
* @todo examples
*
* @param {unknown} value - Value to check
* @return {value is Int32Array} `true` if `value` is a `Int32Array`
*/
const isInt32Array = (value: unknown): value is Int32Array => {
return isObject(value) && equal(value.constructor, Int32Array)
}

export default isInt32Array
23 changes: 23 additions & 0 deletions src/utils/is-int8-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @file Utilities - isInt8Array
* @module tutils/utils/isInt8Array
*/

import equal from './equal'
import isObject from './is-object'

/**
* Checks if `value` is an {@linkcode Int8Array} instance.
*
* @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
*
* @todo examples
*
* @param {unknown} value - Value to check
* @return {value is Int8Array} `true` if `value` is a `Int8Array`
*/
const isInt8Array = (value: unknown): value is Int8Array => {
return isObject(value) && equal(value.constructor, Int8Array)
}

export default isInt8Array

0 comments on commit a8d1f1d

Please sign in to comment.