-
-
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 <unicornware@flexdevelopment.llc>
- Loading branch information
1 parent
10fa0a9
commit 9bec8ac
Showing
8 changed files
with
121 additions
and
29 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,17 @@ | ||
/** | ||
* @file Type Tests - isObjectLike | ||
* @module tutils/utils/tests/unit-d/isObjectLike | ||
*/ | ||
|
||
import type { ObjectCurly } from '#src/types' | ||
import type testSubject from '../is-object-like' | ||
|
||
describe('unit-d:utils/isObjectLike', () => { | ||
it('should guard ObjectCurly | unknown[]', () => { | ||
// Arrange | ||
type Expect = ObjectCurly | unknown[] | ||
|
||
// Expect | ||
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<Expect>() | ||
}) | ||
}) |
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,43 @@ | ||
/** | ||
* @file Unit Tests - isObjectLike | ||
* @module tutils/utils/tests/unit/isObjectLike | ||
*/ | ||
|
||
import INTEGER from '#fixtures/integer' | ||
import TODAY from '#fixtures/today' | ||
import VEHICLE from '#fixtures/vehicle' | ||
import testSubject from '../is-object-like' | ||
|
||
describe('unit:utils/isObjectLike', () => { | ||
it('should return false if value is function', () => { | ||
expect(testSubject(vi.fn())).to.be.false | ||
}) | ||
|
||
it('should return false if value is a primitive', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [ | ||
[INTEGER], | ||
[VEHICLE.vin], | ||
[faker.datatype.boolean()], | ||
[faker.number.bigInt()], | ||
[faker.string.sample()], | ||
[null], | ||
[undefined] | ||
] | ||
|
||
// Act + Expect | ||
cases.forEach(([value]) => expect(testSubject(value)).to.be.false) | ||
}) | ||
|
||
it('should return true if value is array', () => { | ||
expect(testSubject([])).to.be.true | ||
}) | ||
|
||
it('should return true if value is instance object', () => { | ||
expect(testSubject(TODAY)).to.be.true | ||
}) | ||
|
||
it('should return true if value is plain object', () => { | ||
expect(testSubject(VEHICLE)).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
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,24 @@ | ||
/** | ||
* @file Utilities - isObjectLike | ||
* @module tutils/utils/isObjectLike | ||
*/ | ||
|
||
import type { ObjectCurly } from '#src/types' | ||
import isNull from './is-null' | ||
|
||
/** | ||
* Checks if `value` is object-like. | ||
* | ||
* A value is object-like if it has a `typeof` result of `'object'` and is not | ||
* `null`. | ||
* | ||
* @todo examples | ||
* | ||
* @param {unknown} value - Value to check | ||
* @return {value is ObjectCurly | unknown[]} `true` if `value` is object-like | ||
*/ | ||
const isObjectLike = (value: unknown): value is ObjectCurly | unknown[] => { | ||
return !isNull(value) && typeof value === 'object' | ||
} | ||
|
||
export default isObjectLike |
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