-
-
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
6405450
commit d1ed123
Showing
10 changed files
with
136 additions
and
2 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 - isJoinable | ||
* @module tutils/utils/tests/unit-d/isJoinable | ||
*/ | ||
|
||
import type { Joinable } from '#src/types' | ||
import type testSubject from '../is-joinable' | ||
|
||
describe('unit-d:utils/isJoinable', () => { | ||
it('should guard Joinable', () => { | ||
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<Joinable>() | ||
}) | ||
}) |
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 - isJoinable | ||
* @module tutils/utils/tests/unit/isJoinable | ||
*/ | ||
|
||
import VEHICLE from '#fixtures/vehicle' | ||
import testSubject from '../is-joinable' | ||
|
||
describe('unit:utils/isJoinable', () => { | ||
it('should return false if value is not joinable', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [[VEHICLE], [Symbol('.')]] | ||
|
||
// Act + Expect | ||
cases.forEach(([value]) => expect(testSubject(value)).to.be.false) | ||
}) | ||
|
||
it('should return true if value is joinable', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [ | ||
[faker.number.bigInt()], | ||
[faker.datatype.boolean()], | ||
[faker.number.int()], | ||
[faker.string.nanoid()], | ||
[null], | ||
[undefined] | ||
] | ||
|
||
// 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @file Type Tests - isPromise | ||
* @module tutils/utils/tests/unit-d/isPromise | ||
*/ | ||
|
||
import type testSubject from '../is-promise' | ||
|
||
describe('unit-d:utils/isPromise', () => { | ||
it('should guard Promise<T>', () => { | ||
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<Promise<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,17 @@ | ||
/** | ||
* @file Unit Tests - isPromise | ||
* @module tutils/utils/tests/unit/isPromise | ||
*/ | ||
|
||
import testSubject from '../is-promise' | ||
import tryit from '../tryit' | ||
|
||
describe('unit:utils/isPromise', () => { | ||
it('should return false if value is not Promise instance', () => { | ||
expect(testSubject(faker.string.nanoid())).to.be.false | ||
}) | ||
|
||
it('should return true if value is Promise instance', () => { | ||
expect(testSubject(tryit(vi.fn(() => faker.string.uuid()))())).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
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 @@ | ||
/** | ||
* @file Utilities - isJoinable | ||
* @module tutils/utils/isJoinable | ||
*/ | ||
|
||
import type { Joinable } from '#src/types' | ||
import isBigInt from './is-big-int' | ||
import isJsonPrimitive from './is-json-primitive' | ||
import isUndefined from './is-undefined' | ||
|
||
/** | ||
* Checks if `value` is joinable. | ||
* | ||
* @see {@linkcode Joinable} | ||
* | ||
* @todo examples | ||
* | ||
* @param {unknown} value - Value to check | ||
* @return {value is Joinable} `true` if `value` is joinable | ||
*/ | ||
const isJoinable = (value: unknown): value is Joinable => { | ||
return isBigInt(value) || isJsonPrimitive(value) || isUndefined(value) | ||
} | ||
|
||
export default isJoinable |
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 @@ | ||
/** | ||
* @file Utilities - isPromise | ||
* @module tutils/utils/isPromise | ||
*/ | ||
|
||
import equal from './equal' | ||
import isObject from './is-object' | ||
|
||
/** | ||
* Checks if `value` is a {@linkcode Promise}. | ||
* | ||
* @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise | ||
* | ||
* @todo examples | ||
* | ||
* @template T - Resolved promise type | ||
* | ||
* @param {unknown} value - Value to check | ||
* @return {value is Promise<T>} `true` if `value` is a promise | ||
*/ | ||
const isPromise = <T>(value: unknown): value is Promise<T> => { | ||
return isObject(value) && equal(value.constructor, Promise) | ||
} | ||
|
||
export default isPromise |
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