Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/arrify/index.d.ts
1126 views
1
/**
2
Convert a value to an array.
3
4
_Supplying `null` or `undefined` results in an empty array._
5
6
@example
7
```
8
import arrify = require('arrify');
9
10
arrify('🦄');
11
//=> ['🦄']
12
13
arrify(['🦄']);
14
//=> ['🦄']
15
16
arrify(new Set(['🦄']));
17
//=> ['🦄']
18
19
arrify(null);
20
//=> []
21
22
arrify(undefined);
23
//=> []
24
```
25
*/
26
declare function arrify<ValueType>(
27
value: ValueType
28
): ValueType extends (null | undefined)
29
? []
30
: ValueType extends string
31
? [string]
32
: ValueType extends ReadonlyArray<unknown> // TODO: Use 'readonly unknown[]' in the next major version
33
? ValueType
34
: ValueType extends Iterable<infer T>
35
? T[]
36
: [ValueType];
37
38
export = arrify;
39
40