Skip to content

Commit

Permalink
✨ Add isNaN function
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Apr 29, 2021
1 parent 0bf929e commit 10e6e57
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ module.exports = {
children: members[0]?.members
.filter((a) => a.kind === 'Variable')
.map(({ name }) => {
const fName = name === 'length_2' ? 'length' : name
console.log(fName)
const fName = name
.replace('length_2', 'length')
.replace('isNaN_2', 'isNaN')
return {
text: fName,
link: `/api/${lowerCase(fName)}/`
Expand Down
30 changes: 30 additions & 0 deletions docs/api/isnan/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->



## isNaN 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.
>
Whatever argument is `NaN` or not.

<b>Signature:</b>

```typescript
isNaN: (val: unknown) => val is number
```

## Remarks

`NaN` is primitive `number`<!-- -->.

## Example


```ts
isNaN(NaN) // true
isNaN(100) // false

```

8 changes: 7 additions & 1 deletion scripts/gen-api-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const getFileInfo = (path: string): FileInfo => {
return {
path,
content,
name: name.replace(/fonction\.?/, '').replace('length_2', 'length'),
name: name
.replace(/fonction\.?/, '')
.replace('length_2', 'length')
.replace('isnan_2', 'isnan'),
ext
}
}
Expand Down Expand Up @@ -37,6 +40,9 @@ const run = () => {
.replace(/\.\/fonction\.(.+)\.md/g, `./$1/`)
.replace(/length\\_2/g, 'length')
.replace(/length_2/g, 'length')
.replace(/isNaN\\_2/g, 'isNaN')
.replace(/isnan_2/g, 'isnan')

// .replace(/\r?\n```/g, '```')
const to = resolve('docs', 'api', name, 'index.md')
outputFileSync(to, replaced)
Expand Down
21 changes: 21 additions & 0 deletions src/isNaN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Whatever argument is `NaN` or not.
*
* @param val - input any value
* @returns The result of `Number.isNaN(val)`
*
* @remarks
* `NaN` is primitive `number`.
*
* @example
* ```ts
* isNaN(NaN) // true
* isNaN(100) // false
* ```
*
* @beta
*
*/
const isNaN = (val: unknown): val is typeof NaN => Number.isNaN(val)

export { isNaN }
50 changes: 50 additions & 0 deletions test/isNaN.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
BIG1,
DATE,
EMPTY_ARRAY,
EMPTY_OBJECT,
EMPTY_STRING,
MAP,
ONE,
SET,
SYMBOL,
VOID_FN,
VOID_PROMISE,
WEAK_MAP,
WEAK_SET,
ZERO
} from '@test'

import { isNaN } from '@/isNaN'
describe('isNaN', () => {
const table: [unknown, boolean][] = [
[NaN, true],
[Infinity, false],
[-Infinity, false],
[null, false],
[undefined, false],
[ZERO, false],
[ONE, false],
[EMPTY_STRING, false],
['test', false],
[false, false],
[true, false],
[BIG1, false],
[SYMBOL, false],
[EMPTY_OBJECT, false],
[{ nest: {} }, false],
[EMPTY_ARRAY, false],
[[[]], false],
[MAP, false],
[SET, false],
[WEAK_MAP, false],
[WEAK_SET, false],
[VOID_FN, false],
[VOID_PROMISE, false],
[DATE, false]
]

it.each(table)('isNaN(%s) -> %s', (val, expected) => {
expect(isNaN(val)).toEqual(expected)
})
})

0 comments on commit 10e6e57

Please sign in to comment.