-
Notifications
You must be signed in to change notification settings - Fork 0
/
isEmpty.ts
42 lines (36 loc) · 907 Bytes
/
isEmpty.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { isArray } from './isArray'
import { isNil } from './isNil'
/**
* Check whether `args` is empty.
*
* @example
* ```typescript
* isEmpty({}) // true
* isEmpty([]) // true
* isEmpty(null) // true
* isEmpty(undefined) // true
* isEmpty("") // true
*
* isEmpty(0) // false
* isEmpty(false) // false
* isEmpty(function(){}) // false
* isEmpty(Symbol("")) // false
* isEmpty(new Date()) // false
* ```
*
* {@link https://github.com/niuiic/fx-flow/blob/main/packages/test/src/pipe/strict/isEmpty.spec.ts | More examples}
*/
function isEmpty<A>(args: A): boolean {
if (isNil(args)) return true
if (
typeof args === 'object' &&
(args as object)['constructor'] === Object &&
Object.getOwnPropertyNames(args).length === 0
) {
return true
}
if (isArray(args) && args.length === 0) return true
if (args === '') return true
return false
}
export { isEmpty }