-
-
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.
- Loading branch information
1 parent
d41389f
commit ac95f4c
Showing
7 changed files
with
119 additions
and
1 deletion.
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,16 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
|
||
|
||
## Falsy type | ||
|
||
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. | ||
> | ||
Alias for Falsy values | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
type Falsy = false | "" | 0 | null | undefined; | ||
``` |
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,36 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
|
||
|
||
## not variable | ||
|
||
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. | ||
> | ||
Returns the `!` of its argument. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
not: <T>(val: T) => T extends Falsy ? true : boolean | ||
``` | ||
|
||
## Remarks | ||
|
||
The Definition of Falsy - `''` - `false` - `0` - `NaN` - `undefined` - `null` | ||
|
||
## Example | ||
|
||
|
||
```ts | ||
not('') // true | ||
not(false) // true | ||
not(0) // true | ||
not(NaN) // true | ||
not(undefined) // true | ||
not(null) // true | ||
|
||
not({}) // 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
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,33 @@ | ||
import { Falsy } from './types/index.ts' | ||
/** | ||
* Returns the `!` of its argument. | ||
* | ||
* @param val - input any value | ||
* @returns The result of `!val` | ||
* | ||
* @remarks | ||
* The Definition of Falsy | ||
* - `''` | ||
* - `false` | ||
* - `0` | ||
* - `NaN` | ||
* - `undefined` | ||
* - `null` | ||
* | ||
* @example | ||
* ```ts | ||
* not('') // true | ||
* not(false) // true | ||
* not(0) // true | ||
* not(NaN) // true | ||
* not(undefined) // true | ||
* not(null) // true | ||
* | ||
* not({}) // false | ||
* ``` | ||
* | ||
* @beta | ||
*/ | ||
const not = <T>(val: T): T extends Falsy ? true : boolean => | ||
!val as T extends Falsy ? true : boolean | ||
export { not } |
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,23 @@ | ||
import { not } from '@/not' | ||
|
||
describe('not', () => { | ||
const table: [unknown, boolean][] = [ | ||
['', true], | ||
[undefined, true], | ||
[null, true], | ||
[0, true], | ||
[NaN, true], | ||
[false, true], | ||
[[], false], | ||
[{}, false], | ||
['hello', false], | ||
[Infinity, false], | ||
[1, false], | ||
[-1, false], | ||
[true, false] | ||
] | ||
|
||
it.each(table)('not(%s) -> %s', (val, expected) => { | ||
expect(not(val)).toBe(expected) | ||
}) | ||
}) |