-
-
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.
feat(utils):
isFalse
, isFalsy
, isNaN
, isTrue
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
1edffc0
commit 13c941a
Showing
14 changed files
with
251 additions
and
19 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,12 @@ | ||
/** | ||
* @file Type Tests - isFalse | ||
* @module tutils/utils/tests/unit-d/isFalse | ||
*/ | ||
|
||
import type testSubject from '../is-false' | ||
|
||
describe('unit-d:utils/isFalse', () => { | ||
it('should guard false', () => { | ||
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<false>() | ||
}) | ||
}) |
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,16 @@ | ||
/** | ||
* @file Unit Tests - isFalse | ||
* @module tutils/utils/tests/unit/isFalse | ||
*/ | ||
|
||
import testSubject from '../is-false' | ||
|
||
describe('unit:utils/isFalse', () => { | ||
it('should return false if value is not false', () => { | ||
expect(testSubject(0)).to.be.false | ||
}) | ||
|
||
it('should return true if value is false', () => { | ||
expect(testSubject(false)).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,13 @@ | ||
/** | ||
* @file Type Tests - isFalsy | ||
* @module tutils/utils/tests/unit-d/isFalsy | ||
*/ | ||
|
||
import type { Falsy } from '#src/types' | ||
import type testSubject from '../is-falsy' | ||
|
||
describe('unit-d:utils/isFalsy', () => { | ||
it('should guard Falsy', () => { | ||
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<Falsy>() | ||
}) | ||
}) |
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,38 @@ | ||
/** | ||
* @file Unit Tests - isFalsy | ||
* @module tutils/utils/tests/unit/isFalsy | ||
*/ | ||
|
||
import VEHICLE from '#fixtures/vehicle' | ||
import testSubject from '../is-falsy' | ||
|
||
describe('unit:utils/isFalsy', () => { | ||
it('should return false if value is not falsy', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [ | ||
[1], | ||
[true], | ||
[VEHICLE], | ||
[() => 'hello, world'] | ||
] | ||
|
||
// Act + Expect | ||
cases.forEach(([value]) => expect(testSubject(value)).to.be.false) | ||
}) | ||
|
||
it('should return true if value is falsy', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [ | ||
[0], | ||
[0n], | ||
[''], | ||
[null], | ||
[false], | ||
[undefined], | ||
[Number.NaN] | ||
] | ||
|
||
// 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,22 @@ | ||
/** | ||
* @file Unit Tests - isNaN | ||
* @module tutils/utils/tests/unit/isNaN | ||
*/ | ||
|
||
import FLOAT from '#fixtures/float' | ||
import INTEGER from '#fixtures/integer' | ||
import testSubject from '../is-nan' | ||
|
||
describe('unit:utils/isNaN', () => { | ||
it('should return false if value is not Number.NaN', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [[FLOAT], [INTEGER]] | ||
|
||
// Act + Expect | ||
cases.forEach(([value]) => expect(testSubject(value)).to.be.false) | ||
}) | ||
|
||
it('should return true if value is Number.NaN', () => { | ||
expect(testSubject(Number.NaN)).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 - isTrue | ||
* @module tutils/utils/tests/unit-d/isTrue | ||
*/ | ||
|
||
import type testSubject from '../is-true' | ||
|
||
describe('unit-d:utils/isTrue', () => { | ||
it('should guard true', () => { | ||
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<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,16 @@ | ||
/** | ||
* @file Unit Tests - isTrue | ||
* @module tutils/utils/tests/unit/isTrue | ||
*/ | ||
|
||
import testSubject from '../is-true' | ||
|
||
describe('unit:utils/isTrue', () => { | ||
it('should return false if value is not true', () => { | ||
expect(testSubject(1)).to.be.false | ||
}) | ||
|
||
it('should return true if value is true', () => { | ||
expect(testSubject(true)).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,18 @@ | ||
/** | ||
* @file Utilities - isFalse | ||
* @module tutils/utils/isFalse | ||
*/ | ||
|
||
import equal from './equal' | ||
|
||
/** | ||
* Checks if `value` is `false`. | ||
* | ||
* @todo examples | ||
* | ||
* @param {unknown} value - Value to check | ||
* @return {value is false} `true` if `value` is `false` | ||
*/ | ||
const isFalse = (value: unknown): value is false => equal(false, value) | ||
|
||
export default isFalse |
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,39 @@ | ||
/** | ||
* @file Utilities - isFalsy | ||
* @module tutils/utils/isFalsy | ||
*/ | ||
|
||
import type { Falsy } from '#src/types' | ||
import includes from './includes' | ||
import isEmptyValue from './is-empty-value' | ||
import isFalse from './is-false' | ||
import isNaN from './is-nan' | ||
|
||
/** | ||
* Checks if `value` is {@linkcode Falsy}. | ||
* | ||
* Falsy values include: | ||
* | ||
* - `''` | ||
* - `0` | ||
* - `0n` | ||
* - `Number.NaN` | ||
* - `false` | ||
* - `null` | ||
* - `undefined` | ||
* | ||
* @todo examples | ||
* | ||
* @param {unknown} value - Value to check | ||
* @return {value is Falsy} `true` if `value` is falsy | ||
*/ | ||
const isFalsy = (value: unknown): value is Falsy => { | ||
return ( | ||
isEmptyValue(value) || | ||
isFalse(value) || | ||
isNaN(value) || | ||
includes([0, 0n], value) | ||
) | ||
} | ||
|
||
export default isFalsy |
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,18 @@ | ||
/** | ||
* @file Utilities - isNaN | ||
* @module tutils/utils/isNaN | ||
*/ | ||
|
||
import equal from './equal' | ||
|
||
/** | ||
* Checks if `value` is {@linkcode Number.NaN}. | ||
* | ||
* @todo examples | ||
* | ||
* @param {unknown} value - Value to check | ||
* @return {boolean} `true` if `value` is `Number.NaN` | ||
*/ | ||
const isNaN = (value: unknown): boolean => equal(Number.NaN, value) | ||
|
||
export default isNaN |
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,18 @@ | ||
/** | ||
* @file Utilities - isTrue | ||
* @module tutils/utils/isTrue | ||
*/ | ||
|
||
import equal from './equal' | ||
|
||
/** | ||
* Checks if `value` is `true`. | ||
* | ||
* @todo examples | ||
* | ||
* @param {unknown} value - Value to check | ||
* @return {value is true} `true` if `value` is `true` | ||
*/ | ||
const isTrue = (value: unknown): value is true => equal(true, value) | ||
|
||
export default isTrue |