-
-
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
e885589
commit 1c91304
Showing
4 changed files
with
64 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 - isJsonPrimitive | ||
* @module tutils/guards/tests/unit-d/isJsonPrimitive | ||
*/ | ||
|
||
import type { JsonPrimitive } from '#src/types' | ||
import type testSubject from '../is-json-primitive' | ||
|
||
describe('unit-d:guards/isJsonPrimitive', () => { | ||
it('should guard JsonPrimitive', () => { | ||
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<JsonPrimitive>() | ||
}) | ||
}) |
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 Unit Tests - isJsonPrimitive | ||
* @module tutils/guards/tests/unit/isJsonPrimitive | ||
*/ | ||
|
||
import testSubject from '../is-json-primitive' | ||
|
||
describe('unit:guards/isJsonPrimitive', () => { | ||
it('should return false if value is not JSON primitive', () => { | ||
expect(testSubject(faker.datatype.array())).to.be.false | ||
}) | ||
|
||
it('should return true if value is JSON primitive', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [ | ||
[faker.datatype.boolean()], | ||
[faker.number.int()], | ||
[faker.string.uuid()], | ||
[null] | ||
] | ||
|
||
// 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,25 @@ | ||
/** | ||
* @file Type Guards - isJsonPrimitive | ||
* @module tutils/guards/isJsonPrimitive | ||
*/ | ||
|
||
import type { JsonPrimitive } from '#src/types' | ||
import isBoolean from './is-boolean' | ||
import isNull from './is-null' | ||
import isNumber from './is-number' | ||
import isString from './is-string' | ||
|
||
/** | ||
* Checks if the given `value` is a [primitive][1] [`JSON` value][2]. | ||
* | ||
* [1]: https://developer.mozilla.org/docs/Glossary/Primitive | ||
* [2]: https://restfulapi.net/json-data-types | ||
* | ||
* @param {unknown} value - Value to evaluate | ||
* @return {value is JsonPrimitive} `true` if `value` is primitive JSON value | ||
*/ | ||
const isJsonPrimitive = (value: unknown): value is JsonPrimitive => { | ||
return isBoolean(value) || isNumber(value) || isNull(value) || isString(value) | ||
} | ||
|
||
export default isJsonPrimitive |