-
-
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
d24644a
commit fd1f980
Showing
4 changed files
with
221 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
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,84 @@ | ||
import { Callout } from "nextra/components"; | ||
import REPL from "../../components/REPL"; | ||
|
||
> Checks if the given value is empty. | ||
<Callout type="info"> | ||
The following type of values are supported: | ||
|
||
- Array | ||
|
||
- Plain Object | ||
|
||
- String | ||
|
||
- Map | ||
|
||
- Set | ||
|
||
- ArrayBuffer | ||
</Callout> | ||
|
||
## Syntax | ||
|
||
```ts | ||
import { isEmpty } from '@opentf/utils'; | ||
|
||
isEmpty(val: unknown): Boolean; | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
// Truthy cases | ||
// ********* | ||
isEmpty('') //=> true | ||
|
||
isEmpty([]) //=> true | ||
|
||
isEmpty({}) //=> true | ||
|
||
isEmpty(new Map()) //=> true | ||
|
||
isEmpty(new Set()) //=> true | ||
|
||
isEmpty(new ArrayBuffer(0)) //=> true | ||
|
||
|
||
// Falsy cases | ||
// ********* | ||
|
||
isEmpty() //=> false | ||
|
||
isEmpty(undefined) //=> false | ||
|
||
isEmpty(null) //=> false | ||
|
||
isEmpty(1) //=> false | ||
|
||
isEmpty(1.5) //=> false | ||
|
||
isEmpty(1n) //=> false | ||
|
||
isEmpty(false) //=> false | ||
|
||
isEmpty(true) //=> false | ||
|
||
isEmpty(' ') //=> false | ||
|
||
isEmpty('a') //=> false | ||
|
||
isEmpty([1]) //=> false | ||
|
||
isEmpty({ length: 0, size: 0, byteLength: 0 }) //=> false | ||
|
||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { isEmpty } = require('@opentf/utils'); | ||
log(isEmpty([])); | ||
log(isEmpty({})); | ||
isEmpty(null); | ||
`} /> |
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,40 @@ | ||
import { Callout } from "nextra/components"; | ||
import REPL from "../../components/REPL"; | ||
|
||
> Checks if the given value is Nil / Noting. | ||
<Callout type="info"> | ||
The `undefined` & `null` values are considered `Nil` here. | ||
</Callout> | ||
|
||
## Syntax | ||
|
||
```ts | ||
import { isNil } from '@opentf/utils'; | ||
|
||
isNil(val: unknown): Boolean; | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
isNil('') //=> false | ||
|
||
isNil([]) //=> false | ||
|
||
isNil({}) //=> false | ||
|
||
isNil() //=> true | ||
|
||
isNil(undefined) //=> true | ||
|
||
isNil(null) //=> true | ||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { isNil } = require('@opentf/utils'); | ||
const arr = [1, null, 2, undefined, 3] | ||
arr.filter((i) => !isNil(i)); | ||
`} /> |
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,93 @@ | ||
import { Callout } from "nextra/components"; | ||
import REPL from "../../components/REPL"; | ||
|
||
> Returns the size of the given value or null. | ||
<Callout type="info"> | ||
The following type of values are supported: | ||
|
||
- Array | ||
|
||
- Plain Object | ||
|
||
- String | ||
|
||
- Map | ||
|
||
- Set | ||
|
||
- ArrayBuffer | ||
</Callout> | ||
|
||
## Syntax | ||
|
||
```ts | ||
import { size } from '@opentf/utils'; | ||
|
||
size(val: unknown): number | null; | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
// Invalid objs | ||
// ************ | ||
|
||
size() //=> null | ||
|
||
size(undefined) //=> null | ||
|
||
size(null) //=> null | ||
|
||
size(1) //=> null | ||
|
||
size(1.5) //=> null | ||
|
||
size(1n) //=> null | ||
|
||
size(false) //=> null | ||
|
||
size(true) //=> null | ||
|
||
// Eempty objs | ||
// *********** | ||
|
||
size('') //=> 0 | ||
|
||
size([]) //=> 0 | ||
|
||
size({}) //=> 0 | ||
|
||
size(new Map()) //=> 0 | ||
|
||
size(new Set()) //=> 0 | ||
|
||
size(new ArrayBuffer(0)) //=> 0 | ||
|
||
// Non empty objs | ||
// ************** | ||
|
||
size(' ') //=> 1 | ||
|
||
size('abc') //=> 3 | ||
|
||
size([1]) //=> 1 | ||
|
||
size({ length: 0, size: 0, byteLength: 0 }) //=> 3 | ||
|
||
size(new Map([[1, 1]])) //=> 1 | ||
|
||
size(new Set(['a', 'b'])) //=> 2 | ||
|
||
size(new ArrayBuffer(8)) //=> 8 | ||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { size } = require('@opentf/utils'); | ||
log(size(true)); | ||
log(size([])); | ||
log(size({a: 1, b: 2})); | ||
size('Hello World'); | ||
`} /> |