@nejs/basic-extensions 2.21.0 → 2.22.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/markdown.xml +8 -0
- package/.idea/modules.xml +8 -0
- package/.idea/ne-basic-extensions.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/CODE_STYLE.md +393 -0
- package/CODING_PHILOSOPHY.md +36 -0
- package/DOCUMENTATION_GUIDELINES.md +221 -0
- package/README.md +78 -4
- package/dist/@nejs/basic-extensions.bundle.2.22.6.js +25 -0
- package/dist/@nejs/basic-extensions.bundle.2.22.6.js.map +7 -0
- package/dist/cjs/classes/index.cjs +11129 -0
- package/dist/cjs/classes/index.cjs.map +7 -0
- package/dist/cjs/index.cjs +15191 -0
- package/dist/cjs/index.cjs.map +7 -0
- package/dist/cjs/utils/index.cjs +3954 -0
- package/dist/cjs/utils/index.cjs.map +7 -0
- package/dist/esm/basic-extensions.mjs +25 -0
- package/dist/esm/basic-extensions.mjs.map +7 -0
- package/package.json +16 -22
- package/repl.bootstrap.js +4 -7
- package/repl.history +30 -30
- package/src/big.int.extension.js +171 -45
- package/src/classes/enumeration.js +466 -0
- package/src/classes/index.js +5 -1
- package/src/index.js +5 -1
- package/src/math.extension.js +73 -0
- package/src/number.extension.js +18 -0
- package/src/regular.expression.extensions.js +0 -35
- package/src/utils/toolkit.js +699 -516
- package/tests/arrayextensions.test.js +3 -3
- package/tests/index.test.js +3 -1
- package/tests/newClasses/asyncIterable.test.js +3 -3
- package/tests/newClasses/deferred.test.js +3 -3
- package/tests/newClasses/descriptor.test.js +3 -3
- package/tests/newClasses/iterable.test.js +3 -3
- package/tests/newClasses/refmap.test.js +3 -3
- package/tests/newClasses/refset.test.js +3 -3
- package/tests/objectextensions.test.js +3 -3
- package/tests/setextensions.test.js +3 -3
- package/tests/stringextensions.test.js +3 -2
- package/tests/utils/descriptor.utils.test.js +1 -1
- package/tests/utils/toolkit.test.js +429 -163
- package/.esdoc.json +0 -9
- package/.vscode/settings.json +0 -5
- package/bin/build +0 -27
- package/bin/clean +0 -14
- package/bin/esbuild +0 -91
- package/bin/fixup +0 -13
- package/bin/repl.basics.js +0 -584
- package/bin/repl.signature.js +0 -63
- package/bin/version +0 -100
- package/dist/@nejs/basic-extensions.bundle.2.21.0.js +0 -25
- package/dist/@nejs/basic-extensions.bundle.2.21.0.js.map +0 -7
- package/dist/cjs/array.extensions.d.ts +0 -39
- package/dist/cjs/array.extensions.js +0 -477
- package/dist/cjs/array.extensions.js.map +0 -1
- package/dist/cjs/big.int.extension.d.ts +0 -31
- package/dist/cjs/big.int.extension.js +0 -165
- package/dist/cjs/big.int.extension.js.map +0 -1
- package/dist/cjs/classes/asyncIterable.d.ts +0 -126
- package/dist/cjs/classes/asyncIterable.js +0 -209
- package/dist/cjs/classes/asyncIterable.js.map +0 -1
- package/dist/cjs/classes/deferred.d.ts +0 -146
- package/dist/cjs/classes/deferred.js +0 -291
- package/dist/cjs/classes/deferred.js.map +0 -1
- package/dist/cjs/classes/descriptor.d.ts +0 -334
- package/dist/cjs/classes/descriptor.js +0 -537
- package/dist/cjs/classes/descriptor.js.map +0 -1
- package/dist/cjs/classes/enum.d.ts +0 -50
- package/dist/cjs/classes/enum.js +0 -405
- package/dist/cjs/classes/enum.js.map +0 -1
- package/dist/cjs/classes/index.d.ts +0 -15
- package/dist/cjs/classes/index.js +0 -63
- package/dist/cjs/classes/index.js.map +0 -1
- package/dist/cjs/classes/introspector.d.ts +0 -20
- package/dist/cjs/classes/introspector.js +0 -130
- package/dist/cjs/classes/introspector.js.map +0 -1
- package/dist/cjs/classes/iterable.d.ts +0 -169
- package/dist/cjs/classes/iterable.js +0 -268
- package/dist/cjs/classes/iterable.js.map +0 -1
- package/dist/cjs/classes/param.parser.d.ts +0 -221
- package/dist/cjs/classes/param.parser.js +0 -242
- package/dist/cjs/classes/param.parser.js.map +0 -1
- package/dist/cjs/classes/pluggable.proxy.d.ts +0 -153
- package/dist/cjs/classes/pluggable.proxy.js +0 -444
- package/dist/cjs/classes/pluggable.proxy.js.map +0 -1
- package/dist/cjs/classes/property.d.ts +0 -79
- package/dist/cjs/classes/property.js +0 -284
- package/dist/cjs/classes/property.js.map +0 -1
- package/dist/cjs/classes/refmap.d.ts +0 -238
- package/dist/cjs/classes/refmap.js +0 -421
- package/dist/cjs/classes/refmap.js.map +0 -1
- package/dist/cjs/classes/refset.d.ts +0 -186
- package/dist/cjs/classes/refset.js +0 -370
- package/dist/cjs/classes/refset.js.map +0 -1
- package/dist/cjs/classes/symkeys.d.ts +0 -349
- package/dist/cjs/classes/symkeys.js +0 -510
- package/dist/cjs/classes/symkeys.js.map +0 -1
- package/dist/cjs/classes/type.d.ts +0 -56
- package/dist/cjs/classes/type.js +0 -405
- package/dist/cjs/classes/type.js.map +0 -1
- package/dist/cjs/function.extensions.d.ts +0 -12
- package/dist/cjs/function.extensions.js +0 -758
- package/dist/cjs/function.extensions.js.map +0 -1
- package/dist/cjs/global.this.d.ts +0 -2
- package/dist/cjs/global.this.js +0 -300
- package/dist/cjs/global.this.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -31
- package/dist/cjs/index.js +0 -226
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json.extensions.d.ts +0 -2
- package/dist/cjs/json.extensions.js +0 -109
- package/dist/cjs/json.extensions.js.map +0 -1
- package/dist/cjs/map.extensions.d.ts +0 -3
- package/dist/cjs/map.extensions.js +0 -143
- package/dist/cjs/map.extensions.js.map +0 -1
- package/dist/cjs/number.extension.d.ts +0 -44
- package/dist/cjs/number.extension.js +0 -261
- package/dist/cjs/number.extension.js.map +0 -1
- package/dist/cjs/object.extensions.d.ts +0 -33
- package/dist/cjs/object.extensions.js +0 -1091
- package/dist/cjs/object.extensions.js.map +0 -1
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/proxy.extensions.d.ts +0 -2
- package/dist/cjs/proxy.extensions.js +0 -207
- package/dist/cjs/proxy.extensions.js.map +0 -1
- package/dist/cjs/reflect.extensions.d.ts +0 -14
- package/dist/cjs/reflect.extensions.js +0 -316
- package/dist/cjs/reflect.extensions.js.map +0 -1
- package/dist/cjs/regular.expression.extensions.d.ts +0 -2
- package/dist/cjs/regular.expression.extensions.js +0 -423
- package/dist/cjs/regular.expression.extensions.js.map +0 -1
- package/dist/cjs/set.extensions.d.ts +0 -40
- package/dist/cjs/set.extensions.js +0 -355
- package/dist/cjs/set.extensions.js.map +0 -1
- package/dist/cjs/string.extensions.d.ts +0 -23
- package/dist/cjs/string.extensions.js +0 -704
- package/dist/cjs/string.extensions.js.map +0 -1
- package/dist/cjs/symbol.extensions.d.ts +0 -11
- package/dist/cjs/symbol.extensions.js +0 -735
- package/dist/cjs/symbol.extensions.js.map +0 -1
- package/dist/cjs/utils/copy.object.d.ts +0 -408
- package/dist/cjs/utils/copy.object.js +0 -720
- package/dist/cjs/utils/copy.object.js.map +0 -1
- package/dist/cjs/utils/descriptor.utils.d.ts +0 -298
- package/dist/cjs/utils/descriptor.utils.js +0 -889
- package/dist/cjs/utils/descriptor.utils.js.map +0 -1
- package/dist/cjs/utils/index.d.ts +0 -75
- package/dist/cjs/utils/index.js +0 -61
- package/dist/cjs/utils/index.js.map +0 -1
- package/dist/cjs/utils/stdout.d.ts +0 -742
- package/dist/cjs/utils/stdout.js +0 -1042
- package/dist/cjs/utils/stdout.js.map +0 -1
- package/dist/cjs/utils/toolkit.d.ts +0 -1898
- package/dist/cjs/utils/toolkit.js +0 -1378
- package/dist/cjs/utils/toolkit.js.map +0 -1
- package/dist/cjs/weakref.extensions.d.ts +0 -2
- package/dist/cjs/weakref.extensions.js +0 -19
- package/dist/cjs/weakref.extensions.js.map +0 -1
- package/dist/mjs/array.extensions.d.ts +0 -39
- package/dist/mjs/array.extensions.js +0 -474
- package/dist/mjs/array.extensions.js.map +0 -1
- package/dist/mjs/big.int.extension.d.ts +0 -31
- package/dist/mjs/big.int.extension.js +0 -162
- package/dist/mjs/big.int.extension.js.map +0 -1
- package/dist/mjs/classes/asyncIterable.d.ts +0 -126
- package/dist/mjs/classes/asyncIterable.js +0 -204
- package/dist/mjs/classes/asyncIterable.js.map +0 -1
- package/dist/mjs/classes/deferred.d.ts +0 -146
- package/dist/mjs/classes/deferred.js +0 -287
- package/dist/mjs/classes/deferred.js.map +0 -1
- package/dist/mjs/classes/descriptor.d.ts +0 -334
- package/dist/mjs/classes/descriptor.js +0 -533
- package/dist/mjs/classes/descriptor.js.map +0 -1
- package/dist/mjs/classes/enum.d.ts +0 -50
- package/dist/mjs/classes/enum.js +0 -400
- package/dist/mjs/classes/enum.js.map +0 -1
- package/dist/mjs/classes/index.d.ts +0 -15
- package/dist/mjs/classes/index.js +0 -46
- package/dist/mjs/classes/index.js.map +0 -1
- package/dist/mjs/classes/introspector.d.ts +0 -20
- package/dist/mjs/classes/introspector.js +0 -126
- package/dist/mjs/classes/introspector.js.map +0 -1
- package/dist/mjs/classes/iterable.d.ts +0 -169
- package/dist/mjs/classes/iterable.js +0 -263
- package/dist/mjs/classes/iterable.js.map +0 -1
- package/dist/mjs/classes/param.parser.d.ts +0 -221
- package/dist/mjs/classes/param.parser.js +0 -238
- package/dist/mjs/classes/param.parser.js.map +0 -1
- package/dist/mjs/classes/pluggable.proxy.d.ts +0 -153
- package/dist/mjs/classes/pluggable.proxy.js +0 -438
- package/dist/mjs/classes/pluggable.proxy.js.map +0 -1
- package/dist/mjs/classes/property.d.ts +0 -79
- package/dist/mjs/classes/property.js +0 -280
- package/dist/mjs/classes/property.js.map +0 -1
- package/dist/mjs/classes/refmap.d.ts +0 -238
- package/dist/mjs/classes/refmap.js +0 -417
- package/dist/mjs/classes/refmap.js.map +0 -1
- package/dist/mjs/classes/refset.d.ts +0 -186
- package/dist/mjs/classes/refset.js +0 -366
- package/dist/mjs/classes/refset.js.map +0 -1
- package/dist/mjs/classes/symkeys.d.ts +0 -349
- package/dist/mjs/classes/symkeys.js +0 -506
- package/dist/mjs/classes/symkeys.js.map +0 -1
- package/dist/mjs/classes/type.d.ts +0 -56
- package/dist/mjs/classes/type.js +0 -401
- package/dist/mjs/classes/type.js.map +0 -1
- package/dist/mjs/function.extensions.d.ts +0 -12
- package/dist/mjs/function.extensions.js +0 -755
- package/dist/mjs/function.extensions.js.map +0 -1
- package/dist/mjs/global.this.d.ts +0 -2
- package/dist/mjs/global.this.js +0 -264
- package/dist/mjs/global.this.js.map +0 -1
- package/dist/mjs/index.d.ts +0 -31
- package/dist/mjs/index.js +0 -204
- package/dist/mjs/index.js.map +0 -1
- package/dist/mjs/json.extensions.d.ts +0 -2
- package/dist/mjs/json.extensions.js +0 -106
- package/dist/mjs/json.extensions.js.map +0 -1
- package/dist/mjs/map.extensions.d.ts +0 -3
- package/dist/mjs/map.extensions.js +0 -140
- package/dist/mjs/map.extensions.js.map +0 -1
- package/dist/mjs/number.extension.d.ts +0 -44
- package/dist/mjs/number.extension.js +0 -258
- package/dist/mjs/number.extension.js.map +0 -1
- package/dist/mjs/object.extensions.d.ts +0 -33
- package/dist/mjs/object.extensions.js +0 -1088
- package/dist/mjs/object.extensions.js.map +0 -1
- package/dist/mjs/package.json +0 -3
- package/dist/mjs/proxy.extensions.d.ts +0 -2
- package/dist/mjs/proxy.extensions.js +0 -204
- package/dist/mjs/proxy.extensions.js.map +0 -1
- package/dist/mjs/reflect.extensions.d.ts +0 -14
- package/dist/mjs/reflect.extensions.js +0 -313
- package/dist/mjs/reflect.extensions.js.map +0 -1
- package/dist/mjs/regular.expression.extensions.d.ts +0 -2
- package/dist/mjs/regular.expression.extensions.js +0 -420
- package/dist/mjs/regular.expression.extensions.js.map +0 -1
- package/dist/mjs/set.extensions.d.ts +0 -40
- package/dist/mjs/set.extensions.js +0 -352
- package/dist/mjs/set.extensions.js.map +0 -1
- package/dist/mjs/string.extensions.d.ts +0 -23
- package/dist/mjs/string.extensions.js +0 -701
- package/dist/mjs/string.extensions.js.map +0 -1
- package/dist/mjs/symbol.extensions.d.ts +0 -11
- package/dist/mjs/symbol.extensions.js +0 -732
- package/dist/mjs/symbol.extensions.js.map +0 -1
- package/dist/mjs/utils/copy.object.d.ts +0 -408
- package/dist/mjs/utils/copy.object.js +0 -702
- package/dist/mjs/utils/copy.object.js.map +0 -1
- package/dist/mjs/utils/descriptor.utils.d.ts +0 -298
- package/dist/mjs/utils/descriptor.utils.js +0 -875
- package/dist/mjs/utils/descriptor.utils.js.map +0 -1
- package/dist/mjs/utils/index.d.ts +0 -75
- package/dist/mjs/utils/index.js +0 -45
- package/dist/mjs/utils/index.js.map +0 -1
- package/dist/mjs/utils/stdout.d.ts +0 -742
- package/dist/mjs/utils/stdout.js +0 -1037
- package/dist/mjs/utils/stdout.js.map +0 -1
- package/dist/mjs/utils/toolkit.d.ts +0 -1898
- package/dist/mjs/utils/toolkit.js +0 -1373
- package/dist/mjs/utils/toolkit.js.map +0 -1
- package/dist/mjs/weakref.extensions.d.ts +0 -2
- package/dist/mjs/weakref.extensions.js +0 -16
- package/dist/mjs/weakref.extensions.js.map +0 -1
- package/jsdoc-config.json +0 -31
- package/tsconfig.base.json +0 -28
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.esm.json +0 -8
- package/vitest.config.js +0 -7
|
@@ -1,1898 +0,0 @@
|
|
|
1
|
-
export function createToolkit(): {
|
|
2
|
-
si: {
|
|
3
|
-
/**
|
|
4
|
-
* Checks if a value matches a specified type or class.
|
|
5
|
-
*
|
|
6
|
-
* This function determines if the provided value matches the specified
|
|
7
|
-
* type or class. It supports both primitive types and class constructors.
|
|
8
|
-
*
|
|
9
|
-
* @param {*} value - The value to check.
|
|
10
|
-
* @param {*} typeOrClass - The type or class to compare against.
|
|
11
|
-
* @param {boolean} [alreadyReversed=false] - Internal flag to prevent
|
|
12
|
-
* infinite recursion. Not intended for external use.
|
|
13
|
-
* @returns {boolean} True if the value matches the type or class,
|
|
14
|
-
* false otherwise.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* // Returns true
|
|
18
|
-
* is.a(42, 'number')
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* // Returns true
|
|
22
|
-
* is.a(new Date(), Date)
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* // Returns false
|
|
26
|
-
* is.a('string', Number)
|
|
27
|
-
*/
|
|
28
|
-
a(value: any, typeOrClass: any, thenValue: any, elseValue: any): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Check if a value is an accessor descriptor.
|
|
31
|
-
*
|
|
32
|
-
* An accessor descriptor is an object that describes the configuration of a
|
|
33
|
-
* property on an object, specifically focusing on the 'get' and 'set'
|
|
34
|
-
* attributes. Computed accessor descriptors are invalid if they also have
|
|
35
|
-
* a `value` and/or `writable` property.
|
|
36
|
-
*
|
|
37
|
-
* @param value The value to check.
|
|
38
|
-
* @returns True if the value is an accessor descriptor, false otherwise.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* // Returns true
|
|
42
|
-
* is.accessorDescriptor({ get: () => 42, set: () => {} });
|
|
43
|
-
*
|
|
44
|
-
* // Returns false
|
|
45
|
-
* is.accessorDescriptor({ value: 42, writable: true });
|
|
46
|
-
*/
|
|
47
|
-
accessorDescriptor(value: any, thenValue: any, elseValue: any): any;
|
|
48
|
-
/**
|
|
49
|
-
* Check if a value is an array.
|
|
50
|
-
*
|
|
51
|
-
* @param value The value to check.
|
|
52
|
-
* @returns True if the value is an array, false otherwise.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* is.array([1, 2, 3]); // true
|
|
56
|
-
* is.array('string'); // false
|
|
57
|
-
*/
|
|
58
|
-
array(value: any, thenValue: any, elseValue: any): any;
|
|
59
|
-
/**
|
|
60
|
-
* Check if a value is a bigint.
|
|
61
|
-
*
|
|
62
|
-
* @param value The value to check.
|
|
63
|
-
* @returns True if the value is a bigint, false otherwise.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* is.bigint(123n); // true
|
|
67
|
-
* is.bigint(123); // false
|
|
68
|
-
*/
|
|
69
|
-
bigint(value: any, thenValue: any, elseValue: any): any;
|
|
70
|
-
/**
|
|
71
|
-
* Checks if a value is strictly a boolean (true or false).
|
|
72
|
-
*
|
|
73
|
-
* This method verifies if the provided value is either `true` or `false`.
|
|
74
|
-
*
|
|
75
|
-
* @param {*} value - The value to check.
|
|
76
|
-
* @returns {boolean} True if the value is a boolean, false otherwise.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* is.boolean(true); // true
|
|
80
|
-
* is.boolean(false); // true
|
|
81
|
-
* is.boolean(1); // false
|
|
82
|
-
* is.boolean("true"); // false
|
|
83
|
-
*/
|
|
84
|
-
boolean(value: any, thenValue: any, elseValue: any): boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Check if an object is callable. This function is more or less a
|
|
87
|
-
* synonym or alias for `is.function()`.
|
|
88
|
-
*
|
|
89
|
-
* @param object The object to check.
|
|
90
|
-
* @returns True if the object is callable, false otherwise.
|
|
91
|
-
*
|
|
92
|
-
* @note if you wish to know if a descriptor has a callable `value`,
|
|
93
|
-
* `get`, or `set` function, use `is.callableDescriptor` instead.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* is.callable(function() {}); // true
|
|
97
|
-
*/
|
|
98
|
-
callable(object: any, thenValue: any, elseValue: any): any;
|
|
99
|
-
/**
|
|
100
|
-
* Check if an object is callable. It looks to see if the object
|
|
101
|
-
* represents a descriptor that is callable by checking object
|
|
102
|
-
* properties named `value`, `get`, and `set`. If any three variations
|
|
103
|
-
* yields a function type, true is returned.
|
|
104
|
-
*
|
|
105
|
-
* @param object The object to check.
|
|
106
|
-
* @returns True if the object is callable, false otherwise.
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* is.callable({ get: function() {} }); // true
|
|
110
|
-
* is.callable(123); // false
|
|
111
|
-
*
|
|
112
|
-
* // Note the differences between these
|
|
113
|
-
* const object = { get name() { return "Brie"; } };
|
|
114
|
-
* const descriptor = Object.getOwnPropertyDescriptor(object, 'name');
|
|
115
|
-
* is.callable(object); // false
|
|
116
|
-
* is.callable(descriptor); // true
|
|
117
|
-
*/
|
|
118
|
-
callableDescriptor(object: any, thenValue: any, elseValue: any): any;
|
|
119
|
-
/**
|
|
120
|
-
* Check if a value is a data property descriptor.
|
|
121
|
-
*
|
|
122
|
-
* A data descriptor is an object that describes the configuration of a
|
|
123
|
-
* property on an object, specifically focusing on the 'value' and
|
|
124
|
-
* 'writable' attributes. The descriptor is invalid if it contains
|
|
125
|
-
* thew accessor descriptors `get` or `set`.
|
|
126
|
-
*
|
|
127
|
-
* @param value The value to check.
|
|
128
|
-
* @returns True if the value is a data descriptor, false otherwise.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* // Returns true
|
|
132
|
-
* is.dataDescriptor({ value: 42, writable: true });
|
|
133
|
-
*
|
|
134
|
-
* // Returns false
|
|
135
|
-
* is.dataDescriptor({ get: () => 42, set: () => {} });
|
|
136
|
-
*/
|
|
137
|
-
dataDescriptor(value: any, thenValue: any, elseValue: any): any;
|
|
138
|
-
/**
|
|
139
|
-
* Check if a value is a property descriptor.
|
|
140
|
-
*
|
|
141
|
-
* A property descriptor is an object that describes the configuration of a
|
|
142
|
-
* property on an object. This function checks if the provided value is an
|
|
143
|
-
* object and contains any of the standard property descriptor keys.
|
|
144
|
-
*
|
|
145
|
-
* @param value The value to check.
|
|
146
|
-
* @returns True if the value is a property descriptor, false otherwise.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* is.descriptor({ configurable: true, enumerable: false }); // true
|
|
150
|
-
* is.descriptor({ get: () => {}, set: () => {} }); // true
|
|
151
|
-
* is.descriptor({}); // false
|
|
152
|
-
*/
|
|
153
|
-
descriptor(value: any, thenValue: any, elseValue: any): any;
|
|
154
|
-
/**
|
|
155
|
-
* Checks if a value is strictly false.
|
|
156
|
-
*
|
|
157
|
-
* This method verifies if the provided value is strictly `false`.
|
|
158
|
-
*
|
|
159
|
-
* @param {*} value - The value to check.
|
|
160
|
-
* @returns {boolean} True if the value is strictly false, false otherwise.
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* is.false(false); // true
|
|
164
|
-
* is.false(true); // false
|
|
165
|
-
* is.false(0); // false
|
|
166
|
-
*/
|
|
167
|
-
false(value: any, thenValue: any, elseValue: any): boolean;
|
|
168
|
-
/**
|
|
169
|
-
* Checks if a value is falsy.
|
|
170
|
-
*
|
|
171
|
-
* This method converts the provided value to a boolean and returns
|
|
172
|
-
* `true` if the value is falsy (i.e., false, 0, "", null, undefined,
|
|
173
|
-
* or NaN).
|
|
174
|
-
*
|
|
175
|
-
* @param {*} value - The value to check.
|
|
176
|
-
* @returns {boolean} True if the value is falsy, false otherwise.
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* is.falsy(0); // true
|
|
180
|
-
* is.falsy(""); // true
|
|
181
|
-
* is.falsy(1); // false
|
|
182
|
-
* is.falsy("hello"); // false
|
|
183
|
-
*/
|
|
184
|
-
falsy(value: any, thenValue: any, elseValue: any): boolean;
|
|
185
|
-
/**
|
|
186
|
-
* Alias for the `falsy` method.
|
|
187
|
-
*
|
|
188
|
-
* This method is an alias for `is.falsy` and performs the same check.
|
|
189
|
-
*
|
|
190
|
-
* @param {*} value - The value to check.
|
|
191
|
-
* @returns {boolean} True if the value is falsy, false otherwise.
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* is.falsey(0); // true
|
|
195
|
-
* is.falsey(""); // true
|
|
196
|
-
* is.falsey(1); // false
|
|
197
|
-
* is.falsey("hello"); // false
|
|
198
|
-
*/
|
|
199
|
-
falsey(value: any, thenValue: any, elseValue: any): boolean;
|
|
200
|
-
/**
|
|
201
|
-
* Check if a value is a function.
|
|
202
|
-
*
|
|
203
|
-
* @param value The value to check.
|
|
204
|
-
* @returns True if the value is a function, false otherwise.
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* is.function(function() {}); // true
|
|
208
|
-
* is.function(123); // false
|
|
209
|
-
*/
|
|
210
|
-
function(value: any, thenValue: any, elseValue: any): any;
|
|
211
|
-
/**
|
|
212
|
-
* Check if a value is iterable. Depending on the environment, JavaScript
|
|
213
|
-
* will permit `'string'[Symbol.iterator]()` whereas in some places, you
|
|
214
|
-
* will need to wrap string in an object first. Since other JSVM provided
|
|
215
|
-
* environments may or may not be leniant with this, we play it safe by
|
|
216
|
-
* implicitly object converting values before checking for the symbol. If
|
|
217
|
-
* a value is already an object, it will simply be passed through.
|
|
218
|
-
*
|
|
219
|
-
* @param value The value to check.
|
|
220
|
-
* @returns True if the value is iterable, false otherwise.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* is.iterable([1, 2, 3]); // true
|
|
224
|
-
* is.iterable('string'); // true
|
|
225
|
-
* is.iterable(123); // false
|
|
226
|
-
*/
|
|
227
|
-
iterable(value: any, thenValue: any, elseValue: any): any;
|
|
228
|
-
/**
|
|
229
|
-
* Check if a value is null or undefined.
|
|
230
|
-
*
|
|
231
|
-
* @param value The value to check.
|
|
232
|
-
* @returns True if the value is null or undefined, false otherwise.
|
|
233
|
-
*
|
|
234
|
-
* @example
|
|
235
|
-
* is.nullish(null); // true
|
|
236
|
-
* is.nullish(undefined); // true
|
|
237
|
-
* is.nullish('value'); // false
|
|
238
|
-
*/
|
|
239
|
-
nullish(value: any, thenValue: any, elseValue: any): any;
|
|
240
|
-
/**
|
|
241
|
-
* Check if a value is a number.
|
|
242
|
-
*
|
|
243
|
-
* @param value The value to check.
|
|
244
|
-
* @returns True if the value is a number, false otherwise.
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* is.number(123); // true
|
|
248
|
-
* is.number('123'); // false
|
|
249
|
-
*/
|
|
250
|
-
number(value: any, thenValue: any, elseValue: any): any;
|
|
251
|
-
/**
|
|
252
|
-
* Check if a value is an object.
|
|
253
|
-
*
|
|
254
|
-
* @param value The value to check.
|
|
255
|
-
* @returns True if the value is an object, false otherwise.
|
|
256
|
-
*
|
|
257
|
-
* @example
|
|
258
|
-
* is.object({}); // true
|
|
259
|
-
* is.object(null); // false
|
|
260
|
-
*/
|
|
261
|
-
object(value: any, thenValue: any, elseValue: any): any;
|
|
262
|
-
/**
|
|
263
|
-
* Check if a value is a primitive type.
|
|
264
|
-
*
|
|
265
|
-
* This function determines if the provided value is one of the JavaScript
|
|
266
|
-
* primitive types: string, number, boolean, bigint, or symbol.
|
|
267
|
-
*
|
|
268
|
-
* @param value The value to check.
|
|
269
|
-
* @returns True if the value is a primitive type, false otherwise.
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* // Returns true
|
|
273
|
-
* is.primitive('hello');
|
|
274
|
-
*
|
|
275
|
-
* // Returns true
|
|
276
|
-
* is.primitive(123);
|
|
277
|
-
*
|
|
278
|
-
* // Returns true
|
|
279
|
-
* is.primitive(true);
|
|
280
|
-
*
|
|
281
|
-
* // Returns true
|
|
282
|
-
* is.primitive(123n);
|
|
283
|
-
*
|
|
284
|
-
* // Returns true
|
|
285
|
-
* is.primitive(Symbol('symbol'));
|
|
286
|
-
*
|
|
287
|
-
* // Returns false
|
|
288
|
-
* is.primitive({});
|
|
289
|
-
*
|
|
290
|
-
* // Returns false
|
|
291
|
-
* is.primitive([]);
|
|
292
|
-
*/
|
|
293
|
-
primitive(value: any, thenValue: any, elseValue: any): any;
|
|
294
|
-
/**
|
|
295
|
-
* The use of `typeof` is not a safe guarantor when it comes to Reflect
|
|
296
|
-
* supported values. Any non-null value that returns a `typeof` either
|
|
297
|
-
* `object` or `function` should suffice. Note that arrays return 'object'
|
|
298
|
-
* when run through `typeof`. Shiny is clearly a reference to something
|
|
299
|
-
* reflective and is much shorter to type. Also, Mal says shiny. :)
|
|
300
|
-
*
|
|
301
|
-
* @param value The value to check.
|
|
302
|
-
* @returns True if the value is an object or a function, false otherwise.
|
|
303
|
-
*
|
|
304
|
-
* @example
|
|
305
|
-
* is.shiny({}); // true
|
|
306
|
-
* is.shiny(function() {}); // true
|
|
307
|
-
* is.shiny(123); // false
|
|
308
|
-
*/
|
|
309
|
-
shiny(value: any, thenValue: any, elseValue: any): any;
|
|
310
|
-
/**
|
|
311
|
-
* Check if a value is a string.
|
|
312
|
-
*
|
|
313
|
-
* @param value The value to check.
|
|
314
|
-
* @returns True if the value is a string, false otherwise.
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* is.string('hello'); // true
|
|
318
|
-
* is.string(123); // false
|
|
319
|
-
*/
|
|
320
|
-
string(value: any, thenValue: any, elseValue: any): any;
|
|
321
|
-
/**
|
|
322
|
-
* Checks if a value is a symbol.
|
|
323
|
-
*
|
|
324
|
-
* This function determines whether the provided value is of type
|
|
325
|
-
* 'symbol' or an instance of the Symbol object.
|
|
326
|
-
*
|
|
327
|
-
* @param value - The value to check.
|
|
328
|
-
* @returns True if the value is a symbol, false otherwise.
|
|
329
|
-
*
|
|
330
|
-
* @example
|
|
331
|
-
* is.symbol(Symbol('foo')); // Returns true
|
|
332
|
-
* is.symbol('foo'); // Returns false
|
|
333
|
-
*/
|
|
334
|
-
symbol(value: any, thenValue: any, elseValue: any): any;
|
|
335
|
-
then(condition: any, thenValue: any, elseValue: any): any;
|
|
336
|
-
/**
|
|
337
|
-
* Checks if a value is strictly true.
|
|
338
|
-
*
|
|
339
|
-
* This method verifies if the provided value is strictly `true`.
|
|
340
|
-
*
|
|
341
|
-
* @param {*} value - The value to check.
|
|
342
|
-
* @returns {boolean} True if the value is strictly true, false otherwise.
|
|
343
|
-
*
|
|
344
|
-
* @example
|
|
345
|
-
* is.true(true); // true
|
|
346
|
-
* is.true(false); // false
|
|
347
|
-
* is.true(1); // false
|
|
348
|
-
*/
|
|
349
|
-
true(value: any, thenValue: any, elseValue: any): boolean;
|
|
350
|
-
/**
|
|
351
|
-
* Checks if a value is truthy.
|
|
352
|
-
*
|
|
353
|
-
* This method converts the provided value to a boolean and returns
|
|
354
|
-
* `true` if the value is truthy (i.e., not false, 0, "", null, undefined,
|
|
355
|
-
* or NaN).
|
|
356
|
-
*
|
|
357
|
-
* @param {*} value - The value to check.
|
|
358
|
-
* @returns {boolean} True if the value is truthy, false otherwise.
|
|
359
|
-
*
|
|
360
|
-
* @example
|
|
361
|
-
* is.truthy(1); // true
|
|
362
|
-
* is.truthy("hello"); // true
|
|
363
|
-
* is.truthy(0); // false
|
|
364
|
-
* is.truthy(""); // false
|
|
365
|
-
*/
|
|
366
|
-
truthy(value: any, thenValue: any, elseValue: any): boolean;
|
|
367
|
-
};
|
|
368
|
-
is: {
|
|
369
|
-
/**
|
|
370
|
-
* Checks if a value matches a specified type or class.
|
|
371
|
-
*
|
|
372
|
-
* This function determines if the provided value matches the specified
|
|
373
|
-
* type or class. It supports both primitive types and class constructors.
|
|
374
|
-
*
|
|
375
|
-
* @param {*} value - The value to check.
|
|
376
|
-
* @param {*} typeOrClass - The type or class to compare against.
|
|
377
|
-
* @param {boolean} [alreadyReversed=false] - Internal flag to prevent
|
|
378
|
-
* infinite recursion. Not intended for external use.
|
|
379
|
-
* @returns {boolean} True if the value matches the type or class,
|
|
380
|
-
* false otherwise.
|
|
381
|
-
*
|
|
382
|
-
* @example
|
|
383
|
-
* // Returns true
|
|
384
|
-
* is.a(42, 'number')
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* // Returns true
|
|
388
|
-
* is.a(new Date(), Date)
|
|
389
|
-
*
|
|
390
|
-
* @example
|
|
391
|
-
* // Returns false
|
|
392
|
-
* is.a('string', Number)
|
|
393
|
-
*/
|
|
394
|
-
a(value: any, typeOrClass: any): boolean;
|
|
395
|
-
/**
|
|
396
|
-
* Check if a value is an accessor descriptor.
|
|
397
|
-
*
|
|
398
|
-
* An accessor descriptor is an object that describes the configuration of a
|
|
399
|
-
* property on an object, specifically focusing on the 'get' and 'set'
|
|
400
|
-
* attributes. Computed accessor descriptors are invalid if they also have
|
|
401
|
-
* a `value` and/or `writable` property.
|
|
402
|
-
*
|
|
403
|
-
* @param value The value to check.
|
|
404
|
-
* @returns True if the value is an accessor descriptor, false otherwise.
|
|
405
|
-
*
|
|
406
|
-
* @example
|
|
407
|
-
* // Returns true
|
|
408
|
-
* is.accessorDescriptor({ get: () => 42, set: () => {} });
|
|
409
|
-
*
|
|
410
|
-
* // Returns false
|
|
411
|
-
* is.accessorDescriptor({ value: 42, writable: true });
|
|
412
|
-
*/
|
|
413
|
-
accessorDescriptor(value: any): boolean;
|
|
414
|
-
/**
|
|
415
|
-
* Check if a value is an array.
|
|
416
|
-
*
|
|
417
|
-
* @param value The value to check.
|
|
418
|
-
* @returns True if the value is an array, false otherwise.
|
|
419
|
-
*
|
|
420
|
-
* @example
|
|
421
|
-
* is.array([1, 2, 3]); // true
|
|
422
|
-
* is.array('string'); // false
|
|
423
|
-
*/
|
|
424
|
-
array(value: any): value is any[];
|
|
425
|
-
/**
|
|
426
|
-
* Check if a value is a bigint.
|
|
427
|
-
*
|
|
428
|
-
* @param value The value to check.
|
|
429
|
-
* @returns True if the value is a bigint, false otherwise.
|
|
430
|
-
*
|
|
431
|
-
* @example
|
|
432
|
-
* is.bigint(123n); // true
|
|
433
|
-
* is.bigint(123); // false
|
|
434
|
-
*/
|
|
435
|
-
bigint(value: any): value is bigint | BigInt;
|
|
436
|
-
/**
|
|
437
|
-
* Checks if a value is strictly a boolean (true or false).
|
|
438
|
-
*
|
|
439
|
-
* This method verifies if the provided value is either `true` or `false`.
|
|
440
|
-
*
|
|
441
|
-
* @param {*} value - The value to check.
|
|
442
|
-
* @returns {boolean} True if the value is a boolean, false otherwise.
|
|
443
|
-
*
|
|
444
|
-
* @example
|
|
445
|
-
* is.boolean(true); // true
|
|
446
|
-
* is.boolean(false); // true
|
|
447
|
-
* is.boolean(1); // false
|
|
448
|
-
* is.boolean("true"); // false
|
|
449
|
-
*/
|
|
450
|
-
boolean(value: any): boolean;
|
|
451
|
-
/**
|
|
452
|
-
* Check if an object is callable. This function is more or less a
|
|
453
|
-
* synonym or alias for `is.function()`.
|
|
454
|
-
*
|
|
455
|
-
* @param object The object to check.
|
|
456
|
-
* @returns True if the object is callable, false otherwise.
|
|
457
|
-
*
|
|
458
|
-
* @note if you wish to know if a descriptor has a callable `value`,
|
|
459
|
-
* `get`, or `set` function, use `is.callableDescriptor` instead.
|
|
460
|
-
*
|
|
461
|
-
* @example
|
|
462
|
-
* is.callable(function() {}); // true
|
|
463
|
-
*/
|
|
464
|
-
callable(object: any): boolean;
|
|
465
|
-
/**
|
|
466
|
-
* Check if an object is callable. It looks to see if the object
|
|
467
|
-
* represents a descriptor that is callable by checking object
|
|
468
|
-
* properties named `value`, `get`, and `set`. If any three variations
|
|
469
|
-
* yields a function type, true is returned.
|
|
470
|
-
*
|
|
471
|
-
* @param object The object to check.
|
|
472
|
-
* @returns True if the object is callable, false otherwise.
|
|
473
|
-
*
|
|
474
|
-
* @example
|
|
475
|
-
* is.callable({ get: function() {} }); // true
|
|
476
|
-
* is.callable(123); // false
|
|
477
|
-
*
|
|
478
|
-
* // Note the differences between these
|
|
479
|
-
* const object = { get name() { return "Brie"; } };
|
|
480
|
-
* const descriptor = Object.getOwnPropertyDescriptor(object, 'name');
|
|
481
|
-
* is.callable(object); // false
|
|
482
|
-
* is.callable(descriptor); // true
|
|
483
|
-
*/
|
|
484
|
-
callableDescriptor(object: any): boolean;
|
|
485
|
-
/**
|
|
486
|
-
* Check if a value is a data property descriptor.
|
|
487
|
-
*
|
|
488
|
-
* A data descriptor is an object that describes the configuration of a
|
|
489
|
-
* property on an object, specifically focusing on the 'value' and
|
|
490
|
-
* 'writable' attributes. The descriptor is invalid if it contains
|
|
491
|
-
* thew accessor descriptors `get` or `set`.
|
|
492
|
-
*
|
|
493
|
-
* @param value The value to check.
|
|
494
|
-
* @returns True if the value is a data descriptor, false otherwise.
|
|
495
|
-
*
|
|
496
|
-
* @example
|
|
497
|
-
* // Returns true
|
|
498
|
-
* is.dataDescriptor({ value: 42, writable: true });
|
|
499
|
-
*
|
|
500
|
-
* // Returns false
|
|
501
|
-
* is.dataDescriptor({ get: () => 42, set: () => {} });
|
|
502
|
-
*/
|
|
503
|
-
dataDescriptor(value: any): any;
|
|
504
|
-
/**
|
|
505
|
-
* Check if a value is a property descriptor.
|
|
506
|
-
*
|
|
507
|
-
* A property descriptor is an object that describes the configuration of a
|
|
508
|
-
* property on an object. This function checks if the provided value is an
|
|
509
|
-
* object and contains any of the standard property descriptor keys.
|
|
510
|
-
*
|
|
511
|
-
* @param value The value to check.
|
|
512
|
-
* @returns True if the value is a property descriptor, false otherwise.
|
|
513
|
-
*
|
|
514
|
-
* @example
|
|
515
|
-
* is.descriptor({ configurable: true, enumerable: false }); // true
|
|
516
|
-
* is.descriptor({ get: () => {}, set: () => {} }); // true
|
|
517
|
-
* is.descriptor({}); // false
|
|
518
|
-
*/
|
|
519
|
-
descriptor(value: any): boolean;
|
|
520
|
-
/**
|
|
521
|
-
* Checks if a value is strictly false.
|
|
522
|
-
*
|
|
523
|
-
* This method verifies if the provided value is strictly `false`.
|
|
524
|
-
*
|
|
525
|
-
* @param {*} value - The value to check.
|
|
526
|
-
* @returns {boolean} True if the value is strictly false, false otherwise.
|
|
527
|
-
*
|
|
528
|
-
* @example
|
|
529
|
-
* is.false(false); // true
|
|
530
|
-
* is.false(true); // false
|
|
531
|
-
* is.false(0); // false
|
|
532
|
-
*/
|
|
533
|
-
false(value: any): boolean;
|
|
534
|
-
/**
|
|
535
|
-
* Checks if a value is falsy.
|
|
536
|
-
*
|
|
537
|
-
* This method converts the provided value to a boolean and returns
|
|
538
|
-
* `true` if the value is falsy (i.e., false, 0, "", null, undefined,
|
|
539
|
-
* or NaN).
|
|
540
|
-
*
|
|
541
|
-
* @param {*} value - The value to check.
|
|
542
|
-
* @returns {boolean} True if the value is falsy, false otherwise.
|
|
543
|
-
*
|
|
544
|
-
* @example
|
|
545
|
-
* is.falsy(0); // true
|
|
546
|
-
* is.falsy(""); // true
|
|
547
|
-
* is.falsy(1); // false
|
|
548
|
-
* is.falsy("hello"); // false
|
|
549
|
-
*/
|
|
550
|
-
falsy(value: any): boolean;
|
|
551
|
-
/**
|
|
552
|
-
* Alias for the `falsy` method.
|
|
553
|
-
*
|
|
554
|
-
* This method is an alias for `is.falsy` and performs the same check.
|
|
555
|
-
*
|
|
556
|
-
* @param {*} value - The value to check.
|
|
557
|
-
* @returns {boolean} True if the value is falsy, false otherwise.
|
|
558
|
-
*
|
|
559
|
-
* @example
|
|
560
|
-
* is.falsey(0); // true
|
|
561
|
-
* is.falsey(""); // true
|
|
562
|
-
* is.falsey(1); // false
|
|
563
|
-
* is.falsey("hello"); // false
|
|
564
|
-
*/
|
|
565
|
-
falsey(value: any): boolean;
|
|
566
|
-
/**
|
|
567
|
-
* Check if a value is a function.
|
|
568
|
-
*
|
|
569
|
-
* @param value The value to check.
|
|
570
|
-
* @returns True if the value is a function, false otherwise.
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* is.function(function() {}); // true
|
|
574
|
-
* is.function(123); // false
|
|
575
|
-
*/
|
|
576
|
-
function(value: any): boolean;
|
|
577
|
-
/**
|
|
578
|
-
* Check if a value is iterable. Depending on the environment, JavaScript
|
|
579
|
-
* will permit `'string'[Symbol.iterator]()` whereas in some places, you
|
|
580
|
-
* will need to wrap string in an object first. Since other JSVM provided
|
|
581
|
-
* environments may or may not be leniant with this, we play it safe by
|
|
582
|
-
* implicitly object converting values before checking for the symbol. If
|
|
583
|
-
* a value is already an object, it will simply be passed through.
|
|
584
|
-
*
|
|
585
|
-
* @param value The value to check.
|
|
586
|
-
* @returns True if the value is iterable, false otherwise.
|
|
587
|
-
*
|
|
588
|
-
* @example
|
|
589
|
-
* is.iterable([1, 2, 3]); // true
|
|
590
|
-
* is.iterable('string'); // true
|
|
591
|
-
* is.iterable(123); // false
|
|
592
|
-
*/
|
|
593
|
-
iterable(value: any): any;
|
|
594
|
-
/**
|
|
595
|
-
* Check if a value is null or undefined.
|
|
596
|
-
*
|
|
597
|
-
* @param value The value to check.
|
|
598
|
-
* @returns True if the value is null or undefined, false otherwise.
|
|
599
|
-
*
|
|
600
|
-
* @example
|
|
601
|
-
* is.nullish(null); // true
|
|
602
|
-
* is.nullish(undefined); // true
|
|
603
|
-
* is.nullish('value'); // false
|
|
604
|
-
*/
|
|
605
|
-
nullish(value: any): boolean;
|
|
606
|
-
/**
|
|
607
|
-
* Check if a value is a number.
|
|
608
|
-
*
|
|
609
|
-
* @param value The value to check.
|
|
610
|
-
* @returns True if the value is a number, false otherwise.
|
|
611
|
-
*
|
|
612
|
-
* @example
|
|
613
|
-
* is.number(123); // true
|
|
614
|
-
* is.number('123'); // false
|
|
615
|
-
*/
|
|
616
|
-
number(value: any): value is number | Number;
|
|
617
|
-
/**
|
|
618
|
-
* Check if a value is an object.
|
|
619
|
-
*
|
|
620
|
-
* @param value The value to check.
|
|
621
|
-
* @returns True if the value is an object, false otherwise.
|
|
622
|
-
*
|
|
623
|
-
* @example
|
|
624
|
-
* is.object({}); // true
|
|
625
|
-
* is.object(null); // false
|
|
626
|
-
*/
|
|
627
|
-
object(value: any): boolean;
|
|
628
|
-
/**
|
|
629
|
-
* Check if a value is a primitive type.
|
|
630
|
-
*
|
|
631
|
-
* This function determines if the provided value is one of the JavaScript
|
|
632
|
-
* primitive types: string, number, boolean, bigint, or symbol.
|
|
633
|
-
*
|
|
634
|
-
* @param value The value to check.
|
|
635
|
-
* @returns True if the value is a primitive type, false otherwise.
|
|
636
|
-
*
|
|
637
|
-
* @example
|
|
638
|
-
* // Returns true
|
|
639
|
-
* is.primitive('hello');
|
|
640
|
-
*
|
|
641
|
-
* // Returns true
|
|
642
|
-
* is.primitive(123);
|
|
643
|
-
*
|
|
644
|
-
* // Returns true
|
|
645
|
-
* is.primitive(true);
|
|
646
|
-
*
|
|
647
|
-
* // Returns true
|
|
648
|
-
* is.primitive(123n);
|
|
649
|
-
*
|
|
650
|
-
* // Returns true
|
|
651
|
-
* is.primitive(Symbol('symbol'));
|
|
652
|
-
*
|
|
653
|
-
* // Returns false
|
|
654
|
-
* is.primitive({});
|
|
655
|
-
*
|
|
656
|
-
* // Returns false
|
|
657
|
-
* is.primitive([]);
|
|
658
|
-
*/
|
|
659
|
-
primitive(value: any): boolean;
|
|
660
|
-
/**
|
|
661
|
-
* The use of `typeof` is not a safe guarantor when it comes to Reflect
|
|
662
|
-
* supported values. Any non-null value that returns a `typeof` either
|
|
663
|
-
* `object` or `function` should suffice. Note that arrays return 'object'
|
|
664
|
-
* when run through `typeof`. Shiny is clearly a reference to something
|
|
665
|
-
* reflective and is much shorter to type. Also, Mal says shiny. :)
|
|
666
|
-
*
|
|
667
|
-
* @param value The value to check.
|
|
668
|
-
* @returns True if the value is an object or a function, false otherwise.
|
|
669
|
-
*
|
|
670
|
-
* @example
|
|
671
|
-
* is.shiny({}); // true
|
|
672
|
-
* is.shiny(function() {}); // true
|
|
673
|
-
* is.shiny(123); // false
|
|
674
|
-
*/
|
|
675
|
-
shiny(value: any): boolean;
|
|
676
|
-
/**
|
|
677
|
-
* Check if a value is a string.
|
|
678
|
-
*
|
|
679
|
-
* @param value The value to check.
|
|
680
|
-
* @returns True if the value is a string, false otherwise.
|
|
681
|
-
*
|
|
682
|
-
* @example
|
|
683
|
-
* is.string('hello'); // true
|
|
684
|
-
* is.string(123); // false
|
|
685
|
-
*/
|
|
686
|
-
string(value: any): value is string | String;
|
|
687
|
-
/**
|
|
688
|
-
* Checks if a value is a symbol.
|
|
689
|
-
*
|
|
690
|
-
* This function determines whether the provided value is of type
|
|
691
|
-
* 'symbol' or an instance of the Symbol object.
|
|
692
|
-
*
|
|
693
|
-
* @param value - The value to check.
|
|
694
|
-
* @returns True if the value is a symbol, false otherwise.
|
|
695
|
-
*
|
|
696
|
-
* @example
|
|
697
|
-
* is.symbol(Symbol('foo')); // Returns true
|
|
698
|
-
* is.symbol('foo'); // Returns false
|
|
699
|
-
*/
|
|
700
|
-
symbol(value: any): value is symbol | Symbol;
|
|
701
|
-
/**
|
|
702
|
-
* Checks if a value is strictly true.
|
|
703
|
-
*
|
|
704
|
-
* This method verifies if the provided value is strictly `true`.
|
|
705
|
-
*
|
|
706
|
-
* @param {*} value - The value to check.
|
|
707
|
-
* @returns {boolean} True if the value is strictly true, false otherwise.
|
|
708
|
-
*
|
|
709
|
-
* @example
|
|
710
|
-
* is.true(true); // true
|
|
711
|
-
* is.true(false); // false
|
|
712
|
-
* is.true(1); // false
|
|
713
|
-
*/
|
|
714
|
-
true(value: any): boolean;
|
|
715
|
-
/**
|
|
716
|
-
* Checks if a value is truthy.
|
|
717
|
-
*
|
|
718
|
-
* This method converts the provided value to a boolean and returns
|
|
719
|
-
* `true` if the value is truthy (i.e., not false, 0, "", null, undefined,
|
|
720
|
-
* or NaN).
|
|
721
|
-
*
|
|
722
|
-
* @param {*} value - The value to check.
|
|
723
|
-
* @returns {boolean} True if the value is truthy, false otherwise.
|
|
724
|
-
*
|
|
725
|
-
* @example
|
|
726
|
-
* is.truthy(1); // true
|
|
727
|
-
* is.truthy("hello"); // true
|
|
728
|
-
* is.truthy(0); // false
|
|
729
|
-
* is.truthy(""); // false
|
|
730
|
-
*/
|
|
731
|
-
truthy(value: any): boolean;
|
|
732
|
-
};
|
|
733
|
-
has: (object: any, key: any) => any;
|
|
734
|
-
as: {
|
|
735
|
-
/**
|
|
736
|
-
* Converts a value to an array if it is iterable.
|
|
737
|
-
*
|
|
738
|
-
* @param value The value to convert.
|
|
739
|
-
* @returns The converted array if the value is iterable, otherwise undefined.
|
|
740
|
-
*
|
|
741
|
-
* @example
|
|
742
|
-
* // Returns [1, 2, 3]
|
|
743
|
-
* as.array([1, 2, 3]);
|
|
744
|
-
*
|
|
745
|
-
* @example
|
|
746
|
-
* // Returns ['s', 't', 'r', 'i', 'n', 'g']
|
|
747
|
-
* as.array('string');
|
|
748
|
-
*
|
|
749
|
-
* @example
|
|
750
|
-
* // Returns undefined
|
|
751
|
-
* as.array(123);
|
|
752
|
-
*/
|
|
753
|
-
array(value: any): any;
|
|
754
|
-
/**
|
|
755
|
-
* Converts a value to an object. If the supplied value is a primitive
|
|
756
|
-
* value, in many cases, this will convert it to an object instance of
|
|
757
|
-
* that type. Numbers, strings, symbols, and big integers, all have
|
|
758
|
-
* object instance variants. Wrapping them in a call to `Object()` will
|
|
759
|
-
* convert the primitive into this instance variant.
|
|
760
|
-
*
|
|
761
|
-
* @param value The value to convert.
|
|
762
|
-
* @returns The converted object.
|
|
763
|
-
*
|
|
764
|
-
* @example
|
|
765
|
-
* // Returns { key: 'value' }
|
|
766
|
-
* as.object({ key: 'value' });
|
|
767
|
-
*
|
|
768
|
-
* @example
|
|
769
|
-
* // String instance as oppposed to primitive string
|
|
770
|
-
* typeof as.object('string') // 'object'
|
|
771
|
-
* as.object('string') instanceof String // true
|
|
772
|
-
* 'string' instanceof String // false
|
|
773
|
-
*
|
|
774
|
-
* @example
|
|
775
|
-
* // Returns {}
|
|
776
|
-
* as.object(null);
|
|
777
|
-
*/
|
|
778
|
-
object(value: any): any;
|
|
779
|
-
/**
|
|
780
|
-
* Converts a given value to a string. This function handles various types
|
|
781
|
-
* of values, including null, undefined, objects with custom
|
|
782
|
-
* [Symbol.toPrimitive] methods, and objects with toString or valueOf
|
|
783
|
-
* methods.
|
|
784
|
-
*
|
|
785
|
-
* @param value The value to convert to a string.
|
|
786
|
-
* @param use Optional configuration object:
|
|
787
|
-
* - description: If true, returns the description of a Symbol.
|
|
788
|
-
* - stringTag: If true, returns the [Symbol.toStringTag] value if present.
|
|
789
|
-
* @returns The string representation of the value.
|
|
790
|
-
*
|
|
791
|
-
* @example
|
|
792
|
-
* // Returns 'null'
|
|
793
|
-
* as.string(null);
|
|
794
|
-
*
|
|
795
|
-
* @example
|
|
796
|
-
* // Returns '123'
|
|
797
|
-
* as.string(123);
|
|
798
|
-
*
|
|
799
|
-
* @example
|
|
800
|
-
* // Returns 'custom'
|
|
801
|
-
* const obj = {
|
|
802
|
-
* [Symbol.toPrimitive](hint) {
|
|
803
|
-
* if (hint === 'string') return 'custom';
|
|
804
|
-
* return null;
|
|
805
|
-
* }
|
|
806
|
-
* };
|
|
807
|
-
* as.string(obj);
|
|
808
|
-
*
|
|
809
|
-
* @example
|
|
810
|
-
* // Returns 'mySymbol'
|
|
811
|
-
* as.string(Symbol('mySymbol'), { description: true });
|
|
812
|
-
*
|
|
813
|
-
* @example
|
|
814
|
-
* // Returns 'Array'
|
|
815
|
-
* as.string([], { stringTag: true });
|
|
816
|
-
*/
|
|
817
|
-
string(value: any, use?: {
|
|
818
|
-
description: boolean;
|
|
819
|
-
stringTag: boolean;
|
|
820
|
-
}): any;
|
|
821
|
-
/**
|
|
822
|
-
* Converts a given value to a string representing an integer.
|
|
823
|
-
*
|
|
824
|
-
* This method first converts the value to a number string and then extracts
|
|
825
|
-
* the integer part by splitting the string at the decimal point.
|
|
826
|
-
*
|
|
827
|
-
* @param value The value to convert to an integer string.
|
|
828
|
-
* @returns The integer part of the value as a string.
|
|
829
|
-
*
|
|
830
|
-
* @example
|
|
831
|
-
* // Returns '123'
|
|
832
|
-
* as.integerString(123.456);
|
|
833
|
-
*
|
|
834
|
-
* @example
|
|
835
|
-
* // Returns '0'
|
|
836
|
-
* as.integerString('0.789');
|
|
837
|
-
*/
|
|
838
|
-
integerString(value: any): any;
|
|
839
|
-
/**
|
|
840
|
-
* Converts a given value to a string representing a number.
|
|
841
|
-
*
|
|
842
|
-
* This method first converts the value to a string, trims any whitespace,
|
|
843
|
-
* and removes any non-numeric characters except for '.', 'e', 'E', '+',
|
|
844
|
-
* and '-'. It then uses a regular expression to match a floating-point
|
|
845
|
-
* number, allowing an optional leading '+' or '-' sign, digits before
|
|
846
|
-
* and after a single decimal point.
|
|
847
|
-
*
|
|
848
|
-
* @param value The value to convert to a number string.
|
|
849
|
-
* @returns The sanitized number string or an empty string if no valid
|
|
850
|
-
* float was found.
|
|
851
|
-
*
|
|
852
|
-
* @example
|
|
853
|
-
* // Returns '123.456'
|
|
854
|
-
* numberString(' 123.456abc ');
|
|
855
|
-
*
|
|
856
|
-
* @example
|
|
857
|
-
* // Returns '-0.789'
|
|
858
|
-
* numberString('-0.789xyz');
|
|
859
|
-
*/
|
|
860
|
-
numberString(value: any): any;
|
|
861
|
-
/**
|
|
862
|
-
* Converts a given value to a number.
|
|
863
|
-
*
|
|
864
|
-
* This method uses the `numberString` method to sanitize the input value
|
|
865
|
-
* and then converts it to a number.
|
|
866
|
-
*
|
|
867
|
-
* @param value The value to convert to a number.
|
|
868
|
-
* @returns The numeric representation of the value.
|
|
869
|
-
*
|
|
870
|
-
* @example
|
|
871
|
-
* // Returns 123.456
|
|
872
|
-
* number('123.456abc');
|
|
873
|
-
*
|
|
874
|
-
* @example
|
|
875
|
-
* // Returns -0.789
|
|
876
|
-
* number('-0.789xyz');
|
|
877
|
-
*/
|
|
878
|
-
number(value: any): number;
|
|
879
|
-
/**
|
|
880
|
-
* Converts a given value to a bigint.
|
|
881
|
-
*
|
|
882
|
-
* This method uses the `integerString` method to sanitize the input value
|
|
883
|
-
* and then converts it to a bigint.
|
|
884
|
-
*
|
|
885
|
-
* @param value The value to convert to a bigint.
|
|
886
|
-
* @returns The bigint representation of the value.
|
|
887
|
-
*
|
|
888
|
-
* @example
|
|
889
|
-
* // Returns 123n
|
|
890
|
-
* bigint('123.456abc');
|
|
891
|
-
*
|
|
892
|
-
* @example
|
|
893
|
-
* // Returns 0n
|
|
894
|
-
* bigint('0.789xyz');
|
|
895
|
-
*/
|
|
896
|
-
bigint(value: any): bigint;
|
|
897
|
-
/**
|
|
898
|
-
* Converts a given value to a boolean.
|
|
899
|
-
*
|
|
900
|
-
* This method takes a value, converts it to a string, and then checks
|
|
901
|
-
* if it matches common representations of boolean values. It returns
|
|
902
|
-
* `true` for "1", "yes", and "true" (case insensitive), and `false`
|
|
903
|
-
* for "0", "no", and "false" (case insensitive). For any other values,
|
|
904
|
-
* it returns the boolean representation of the value.
|
|
905
|
-
*
|
|
906
|
-
* @param {*} value - The value to convert to a boolean.
|
|
907
|
-
* @returns {boolean} The boolean representation of the value.
|
|
908
|
-
*
|
|
909
|
-
* @example
|
|
910
|
-
* // Returns true
|
|
911
|
-
* is.boolean("yes")
|
|
912
|
-
*
|
|
913
|
-
* @example
|
|
914
|
-
* // Returns false
|
|
915
|
-
* is.boolean("no")
|
|
916
|
-
*
|
|
917
|
-
* @example
|
|
918
|
-
* // Returns true
|
|
919
|
-
* is.boolean(1)
|
|
920
|
-
*
|
|
921
|
-
* @example
|
|
922
|
-
* // Returns false
|
|
923
|
-
* is.boolean(0)
|
|
924
|
-
*
|
|
925
|
-
* @example
|
|
926
|
-
* // Returns true
|
|
927
|
-
* is.boolean("true")
|
|
928
|
-
*
|
|
929
|
-
* @example
|
|
930
|
-
* // Returns false
|
|
931
|
-
* is.boolean("false")
|
|
932
|
-
*
|
|
933
|
-
* @example
|
|
934
|
-
* // Returns true
|
|
935
|
-
* is.boolean({})
|
|
936
|
-
*
|
|
937
|
-
* @example
|
|
938
|
-
* // Returns false
|
|
939
|
-
* is.boolean(null)
|
|
940
|
-
*/
|
|
941
|
-
boolean(value: any): boolean;
|
|
942
|
-
};
|
|
943
|
-
};
|
|
944
|
-
export namespace is {
|
|
945
|
-
/**
|
|
946
|
-
* Checks if a value matches a specified type or class.
|
|
947
|
-
*
|
|
948
|
-
* This function determines if the provided value matches the specified
|
|
949
|
-
* type or class. It supports both primitive types and class constructors.
|
|
950
|
-
*
|
|
951
|
-
* @param {*} value - The value to check.
|
|
952
|
-
* @param {*} typeOrClass - The type or class to compare against.
|
|
953
|
-
* @param {boolean} [alreadyReversed=false] - Internal flag to prevent
|
|
954
|
-
* infinite recursion. Not intended for external use.
|
|
955
|
-
* @returns {boolean} True if the value matches the type or class,
|
|
956
|
-
* false otherwise.
|
|
957
|
-
*
|
|
958
|
-
* @example
|
|
959
|
-
* // Returns true
|
|
960
|
-
* is.a(42, 'number')
|
|
961
|
-
*
|
|
962
|
-
* @example
|
|
963
|
-
* // Returns true
|
|
964
|
-
* is.a(new Date(), Date)
|
|
965
|
-
*
|
|
966
|
-
* @example
|
|
967
|
-
* // Returns false
|
|
968
|
-
* is.a('string', Number)
|
|
969
|
-
*/
|
|
970
|
-
export function a(value: any, typeOrClass: any): boolean;
|
|
971
|
-
/**
|
|
972
|
-
* Check if a value is an accessor descriptor.
|
|
973
|
-
*
|
|
974
|
-
* An accessor descriptor is an object that describes the configuration of a
|
|
975
|
-
* property on an object, specifically focusing on the 'get' and 'set'
|
|
976
|
-
* attributes. Computed accessor descriptors are invalid if they also have
|
|
977
|
-
* a `value` and/or `writable` property.
|
|
978
|
-
*
|
|
979
|
-
* @param value The value to check.
|
|
980
|
-
* @returns True if the value is an accessor descriptor, false otherwise.
|
|
981
|
-
*
|
|
982
|
-
* @example
|
|
983
|
-
* // Returns true
|
|
984
|
-
* is.accessorDescriptor({ get: () => 42, set: () => {} });
|
|
985
|
-
*
|
|
986
|
-
* // Returns false
|
|
987
|
-
* is.accessorDescriptor({ value: 42, writable: true });
|
|
988
|
-
*/
|
|
989
|
-
export function accessorDescriptor(value: any): boolean;
|
|
990
|
-
/**
|
|
991
|
-
* Check if a value is an array.
|
|
992
|
-
*
|
|
993
|
-
* @param value The value to check.
|
|
994
|
-
* @returns True if the value is an array, false otherwise.
|
|
995
|
-
*
|
|
996
|
-
* @example
|
|
997
|
-
* is.array([1, 2, 3]); // true
|
|
998
|
-
* is.array('string'); // false
|
|
999
|
-
*/
|
|
1000
|
-
export function array(value: any): value is any[];
|
|
1001
|
-
/**
|
|
1002
|
-
* Check if a value is a bigint.
|
|
1003
|
-
*
|
|
1004
|
-
* @param value The value to check.
|
|
1005
|
-
* @returns True if the value is a bigint, false otherwise.
|
|
1006
|
-
*
|
|
1007
|
-
* @example
|
|
1008
|
-
* is.bigint(123n); // true
|
|
1009
|
-
* is.bigint(123); // false
|
|
1010
|
-
*/
|
|
1011
|
-
export function bigint(value: any): value is bigint | BigInt;
|
|
1012
|
-
/**
|
|
1013
|
-
* Checks if a value is strictly a boolean (true or false).
|
|
1014
|
-
*
|
|
1015
|
-
* This method verifies if the provided value is either `true` or `false`.
|
|
1016
|
-
*
|
|
1017
|
-
* @param {*} value - The value to check.
|
|
1018
|
-
* @returns {boolean} True if the value is a boolean, false otherwise.
|
|
1019
|
-
*
|
|
1020
|
-
* @example
|
|
1021
|
-
* is.boolean(true); // true
|
|
1022
|
-
* is.boolean(false); // true
|
|
1023
|
-
* is.boolean(1); // false
|
|
1024
|
-
* is.boolean("true"); // false
|
|
1025
|
-
*/
|
|
1026
|
-
export function boolean(value: any): boolean;
|
|
1027
|
-
/**
|
|
1028
|
-
* Check if an object is callable. This function is more or less a
|
|
1029
|
-
* synonym or alias for `is.function()`.
|
|
1030
|
-
*
|
|
1031
|
-
* @param object The object to check.
|
|
1032
|
-
* @returns True if the object is callable, false otherwise.
|
|
1033
|
-
*
|
|
1034
|
-
* @note if you wish to know if a descriptor has a callable `value`,
|
|
1035
|
-
* `get`, or `set` function, use `is.callableDescriptor` instead.
|
|
1036
|
-
*
|
|
1037
|
-
* @example
|
|
1038
|
-
* is.callable(function() {}); // true
|
|
1039
|
-
*/
|
|
1040
|
-
export function callable(object: any): boolean;
|
|
1041
|
-
/**
|
|
1042
|
-
* Check if an object is callable. It looks to see if the object
|
|
1043
|
-
* represents a descriptor that is callable by checking object
|
|
1044
|
-
* properties named `value`, `get`, and `set`. If any three variations
|
|
1045
|
-
* yields a function type, true is returned.
|
|
1046
|
-
*
|
|
1047
|
-
* @param object The object to check.
|
|
1048
|
-
* @returns True if the object is callable, false otherwise.
|
|
1049
|
-
*
|
|
1050
|
-
* @example
|
|
1051
|
-
* is.callable({ get: function() {} }); // true
|
|
1052
|
-
* is.callable(123); // false
|
|
1053
|
-
*
|
|
1054
|
-
* // Note the differences between these
|
|
1055
|
-
* const object = { get name() { return "Brie"; } };
|
|
1056
|
-
* const descriptor = Object.getOwnPropertyDescriptor(object, 'name');
|
|
1057
|
-
* is.callable(object); // false
|
|
1058
|
-
* is.callable(descriptor); // true
|
|
1059
|
-
*/
|
|
1060
|
-
export function callableDescriptor(object: any): boolean;
|
|
1061
|
-
/**
|
|
1062
|
-
* Check if a value is a data property descriptor.
|
|
1063
|
-
*
|
|
1064
|
-
* A data descriptor is an object that describes the configuration of a
|
|
1065
|
-
* property on an object, specifically focusing on the 'value' and
|
|
1066
|
-
* 'writable' attributes. The descriptor is invalid if it contains
|
|
1067
|
-
* thew accessor descriptors `get` or `set`.
|
|
1068
|
-
*
|
|
1069
|
-
* @param value The value to check.
|
|
1070
|
-
* @returns True if the value is a data descriptor, false otherwise.
|
|
1071
|
-
*
|
|
1072
|
-
* @example
|
|
1073
|
-
* // Returns true
|
|
1074
|
-
* is.dataDescriptor({ value: 42, writable: true });
|
|
1075
|
-
*
|
|
1076
|
-
* // Returns false
|
|
1077
|
-
* is.dataDescriptor({ get: () => 42, set: () => {} });
|
|
1078
|
-
*/
|
|
1079
|
-
export function dataDescriptor(value: any): any;
|
|
1080
|
-
/**
|
|
1081
|
-
* Check if a value is a property descriptor.
|
|
1082
|
-
*
|
|
1083
|
-
* A property descriptor is an object that describes the configuration of a
|
|
1084
|
-
* property on an object. This function checks if the provided value is an
|
|
1085
|
-
* object and contains any of the standard property descriptor keys.
|
|
1086
|
-
*
|
|
1087
|
-
* @param value The value to check.
|
|
1088
|
-
* @returns True if the value is a property descriptor, false otherwise.
|
|
1089
|
-
*
|
|
1090
|
-
* @example
|
|
1091
|
-
* is.descriptor({ configurable: true, enumerable: false }); // true
|
|
1092
|
-
* is.descriptor({ get: () => {}, set: () => {} }); // true
|
|
1093
|
-
* is.descriptor({}); // false
|
|
1094
|
-
*/
|
|
1095
|
-
export function descriptor(value: any): boolean;
|
|
1096
|
-
/**
|
|
1097
|
-
* Checks if a value is strictly false.
|
|
1098
|
-
*
|
|
1099
|
-
* This method verifies if the provided value is strictly `false`.
|
|
1100
|
-
*
|
|
1101
|
-
* @param {*} value - The value to check.
|
|
1102
|
-
* @returns {boolean} True if the value is strictly false, false otherwise.
|
|
1103
|
-
*
|
|
1104
|
-
* @example
|
|
1105
|
-
* is.false(false); // true
|
|
1106
|
-
* is.false(true); // false
|
|
1107
|
-
* is.false(0); // false
|
|
1108
|
-
*/
|
|
1109
|
-
function _false(value: any): boolean;
|
|
1110
|
-
export { _false as false };
|
|
1111
|
-
/**
|
|
1112
|
-
* Checks if a value is falsy.
|
|
1113
|
-
*
|
|
1114
|
-
* This method converts the provided value to a boolean and returns
|
|
1115
|
-
* `true` if the value is falsy (i.e., false, 0, "", null, undefined,
|
|
1116
|
-
* or NaN).
|
|
1117
|
-
*
|
|
1118
|
-
* @param {*} value - The value to check.
|
|
1119
|
-
* @returns {boolean} True if the value is falsy, false otherwise.
|
|
1120
|
-
*
|
|
1121
|
-
* @example
|
|
1122
|
-
* is.falsy(0); // true
|
|
1123
|
-
* is.falsy(""); // true
|
|
1124
|
-
* is.falsy(1); // false
|
|
1125
|
-
* is.falsy("hello"); // false
|
|
1126
|
-
*/
|
|
1127
|
-
export function falsy(value: any): boolean;
|
|
1128
|
-
/**
|
|
1129
|
-
* Alias for the `falsy` method.
|
|
1130
|
-
*
|
|
1131
|
-
* This method is an alias for `is.falsy` and performs the same check.
|
|
1132
|
-
*
|
|
1133
|
-
* @param {*} value - The value to check.
|
|
1134
|
-
* @returns {boolean} True if the value is falsy, false otherwise.
|
|
1135
|
-
*
|
|
1136
|
-
* @example
|
|
1137
|
-
* is.falsey(0); // true
|
|
1138
|
-
* is.falsey(""); // true
|
|
1139
|
-
* is.falsey(1); // false
|
|
1140
|
-
* is.falsey("hello"); // false
|
|
1141
|
-
*/
|
|
1142
|
-
export function falsey(value: any): boolean;
|
|
1143
|
-
/**
|
|
1144
|
-
* Check if a value is a function.
|
|
1145
|
-
*
|
|
1146
|
-
* @param value The value to check.
|
|
1147
|
-
* @returns True if the value is a function, false otherwise.
|
|
1148
|
-
*
|
|
1149
|
-
* @example
|
|
1150
|
-
* is.function(function() {}); // true
|
|
1151
|
-
* is.function(123); // false
|
|
1152
|
-
*/
|
|
1153
|
-
function _function(value: any): boolean;
|
|
1154
|
-
export { _function as function };
|
|
1155
|
-
/**
|
|
1156
|
-
* Check if a value is iterable. Depending on the environment, JavaScript
|
|
1157
|
-
* will permit `'string'[Symbol.iterator]()` whereas in some places, you
|
|
1158
|
-
* will need to wrap string in an object first. Since other JSVM provided
|
|
1159
|
-
* environments may or may not be leniant with this, we play it safe by
|
|
1160
|
-
* implicitly object converting values before checking for the symbol. If
|
|
1161
|
-
* a value is already an object, it will simply be passed through.
|
|
1162
|
-
*
|
|
1163
|
-
* @param value The value to check.
|
|
1164
|
-
* @returns True if the value is iterable, false otherwise.
|
|
1165
|
-
*
|
|
1166
|
-
* @example
|
|
1167
|
-
* is.iterable([1, 2, 3]); // true
|
|
1168
|
-
* is.iterable('string'); // true
|
|
1169
|
-
* is.iterable(123); // false
|
|
1170
|
-
*/
|
|
1171
|
-
export function iterable(value: any): any;
|
|
1172
|
-
/**
|
|
1173
|
-
* Check if a value is null or undefined.
|
|
1174
|
-
*
|
|
1175
|
-
* @param value The value to check.
|
|
1176
|
-
* @returns True if the value is null or undefined, false otherwise.
|
|
1177
|
-
*
|
|
1178
|
-
* @example
|
|
1179
|
-
* is.nullish(null); // true
|
|
1180
|
-
* is.nullish(undefined); // true
|
|
1181
|
-
* is.nullish('value'); // false
|
|
1182
|
-
*/
|
|
1183
|
-
export function nullish(value: any): boolean;
|
|
1184
|
-
/**
|
|
1185
|
-
* Check if a value is a number.
|
|
1186
|
-
*
|
|
1187
|
-
* @param value The value to check.
|
|
1188
|
-
* @returns True if the value is a number, false otherwise.
|
|
1189
|
-
*
|
|
1190
|
-
* @example
|
|
1191
|
-
* is.number(123); // true
|
|
1192
|
-
* is.number('123'); // false
|
|
1193
|
-
*/
|
|
1194
|
-
export function number(value: any): value is number | Number;
|
|
1195
|
-
/**
|
|
1196
|
-
* Check if a value is an object.
|
|
1197
|
-
*
|
|
1198
|
-
* @param value The value to check.
|
|
1199
|
-
* @returns True if the value is an object, false otherwise.
|
|
1200
|
-
*
|
|
1201
|
-
* @example
|
|
1202
|
-
* is.object({}); // true
|
|
1203
|
-
* is.object(null); // false
|
|
1204
|
-
*/
|
|
1205
|
-
export function object(value: any): boolean;
|
|
1206
|
-
/**
|
|
1207
|
-
* Check if a value is a primitive type.
|
|
1208
|
-
*
|
|
1209
|
-
* This function determines if the provided value is one of the JavaScript
|
|
1210
|
-
* primitive types: string, number, boolean, bigint, or symbol.
|
|
1211
|
-
*
|
|
1212
|
-
* @param value The value to check.
|
|
1213
|
-
* @returns True if the value is a primitive type, false otherwise.
|
|
1214
|
-
*
|
|
1215
|
-
* @example
|
|
1216
|
-
* // Returns true
|
|
1217
|
-
* is.primitive('hello');
|
|
1218
|
-
*
|
|
1219
|
-
* // Returns true
|
|
1220
|
-
* is.primitive(123);
|
|
1221
|
-
*
|
|
1222
|
-
* // Returns true
|
|
1223
|
-
* is.primitive(true);
|
|
1224
|
-
*
|
|
1225
|
-
* // Returns true
|
|
1226
|
-
* is.primitive(123n);
|
|
1227
|
-
*
|
|
1228
|
-
* // Returns true
|
|
1229
|
-
* is.primitive(Symbol('symbol'));
|
|
1230
|
-
*
|
|
1231
|
-
* // Returns false
|
|
1232
|
-
* is.primitive({});
|
|
1233
|
-
*
|
|
1234
|
-
* // Returns false
|
|
1235
|
-
* is.primitive([]);
|
|
1236
|
-
*/
|
|
1237
|
-
export function primitive(value: any): boolean;
|
|
1238
|
-
/**
|
|
1239
|
-
* The use of `typeof` is not a safe guarantor when it comes to Reflect
|
|
1240
|
-
* supported values. Any non-null value that returns a `typeof` either
|
|
1241
|
-
* `object` or `function` should suffice. Note that arrays return 'object'
|
|
1242
|
-
* when run through `typeof`. Shiny is clearly a reference to something
|
|
1243
|
-
* reflective and is much shorter to type. Also, Mal says shiny. :)
|
|
1244
|
-
*
|
|
1245
|
-
* @param value The value to check.
|
|
1246
|
-
* @returns True if the value is an object or a function, false otherwise.
|
|
1247
|
-
*
|
|
1248
|
-
* @example
|
|
1249
|
-
* is.shiny({}); // true
|
|
1250
|
-
* is.shiny(function() {}); // true
|
|
1251
|
-
* is.shiny(123); // false
|
|
1252
|
-
*/
|
|
1253
|
-
export function shiny(value: any): boolean;
|
|
1254
|
-
/**
|
|
1255
|
-
* Check if a value is a string.
|
|
1256
|
-
*
|
|
1257
|
-
* @param value The value to check.
|
|
1258
|
-
* @returns True if the value is a string, false otherwise.
|
|
1259
|
-
*
|
|
1260
|
-
* @example
|
|
1261
|
-
* is.string('hello'); // true
|
|
1262
|
-
* is.string(123); // false
|
|
1263
|
-
*/
|
|
1264
|
-
export function string(value: any): value is string | String;
|
|
1265
|
-
/**
|
|
1266
|
-
* Checks if a value is a symbol.
|
|
1267
|
-
*
|
|
1268
|
-
* This function determines whether the provided value is of type
|
|
1269
|
-
* 'symbol' or an instance of the Symbol object.
|
|
1270
|
-
*
|
|
1271
|
-
* @param value - The value to check.
|
|
1272
|
-
* @returns True if the value is a symbol, false otherwise.
|
|
1273
|
-
*
|
|
1274
|
-
* @example
|
|
1275
|
-
* is.symbol(Symbol('foo')); // Returns true
|
|
1276
|
-
* is.symbol('foo'); // Returns false
|
|
1277
|
-
*/
|
|
1278
|
-
export function symbol(value: any): value is symbol | Symbol;
|
|
1279
|
-
/**
|
|
1280
|
-
* Checks if a value is strictly true.
|
|
1281
|
-
*
|
|
1282
|
-
* This method verifies if the provided value is strictly `true`.
|
|
1283
|
-
*
|
|
1284
|
-
* @param {*} value - The value to check.
|
|
1285
|
-
* @returns {boolean} True if the value is strictly true, false otherwise.
|
|
1286
|
-
*
|
|
1287
|
-
* @example
|
|
1288
|
-
* is.true(true); // true
|
|
1289
|
-
* is.true(false); // false
|
|
1290
|
-
* is.true(1); // false
|
|
1291
|
-
*/
|
|
1292
|
-
function _true(value: any): boolean;
|
|
1293
|
-
export { _true as true };
|
|
1294
|
-
/**
|
|
1295
|
-
* Checks if a value is truthy.
|
|
1296
|
-
*
|
|
1297
|
-
* This method converts the provided value to a boolean and returns
|
|
1298
|
-
* `true` if the value is truthy (i.e., not false, 0, "", null, undefined,
|
|
1299
|
-
* or NaN).
|
|
1300
|
-
*
|
|
1301
|
-
* @param {*} value - The value to check.
|
|
1302
|
-
* @returns {boolean} True if the value is truthy, false otherwise.
|
|
1303
|
-
*
|
|
1304
|
-
* @example
|
|
1305
|
-
* is.truthy(1); // true
|
|
1306
|
-
* is.truthy("hello"); // true
|
|
1307
|
-
* is.truthy(0); // false
|
|
1308
|
-
* is.truthy(""); // false
|
|
1309
|
-
*/
|
|
1310
|
-
export function truthy(value: any): boolean;
|
|
1311
|
-
}
|
|
1312
|
-
export namespace si {
|
|
1313
|
-
/**
|
|
1314
|
-
* Checks if a value matches a specified type or class.
|
|
1315
|
-
*
|
|
1316
|
-
* This function determines if the provided value matches the specified
|
|
1317
|
-
* type or class. It supports both primitive types and class constructors.
|
|
1318
|
-
*
|
|
1319
|
-
* @param {*} value - The value to check.
|
|
1320
|
-
* @param {*} typeOrClass - The type or class to compare against.
|
|
1321
|
-
* @param {boolean} [alreadyReversed=false] - Internal flag to prevent
|
|
1322
|
-
* infinite recursion. Not intended for external use.
|
|
1323
|
-
* @returns {boolean} True if the value matches the type or class,
|
|
1324
|
-
* false otherwise.
|
|
1325
|
-
*
|
|
1326
|
-
* @example
|
|
1327
|
-
* // Returns true
|
|
1328
|
-
* is.a(42, 'number')
|
|
1329
|
-
*
|
|
1330
|
-
* @example
|
|
1331
|
-
* // Returns true
|
|
1332
|
-
* is.a(new Date(), Date)
|
|
1333
|
-
*
|
|
1334
|
-
* @example
|
|
1335
|
-
* // Returns false
|
|
1336
|
-
* is.a('string', Number)
|
|
1337
|
-
*/
|
|
1338
|
-
export function a(value: any, typeOrClass: any, thenValue: any, elseValue: any): boolean;
|
|
1339
|
-
/**
|
|
1340
|
-
* Check if a value is an accessor descriptor.
|
|
1341
|
-
*
|
|
1342
|
-
* An accessor descriptor is an object that describes the configuration of a
|
|
1343
|
-
* property on an object, specifically focusing on the 'get' and 'set'
|
|
1344
|
-
* attributes. Computed accessor descriptors are invalid if they also have
|
|
1345
|
-
* a `value` and/or `writable` property.
|
|
1346
|
-
*
|
|
1347
|
-
* @param value The value to check.
|
|
1348
|
-
* @returns True if the value is an accessor descriptor, false otherwise.
|
|
1349
|
-
*
|
|
1350
|
-
* @example
|
|
1351
|
-
* // Returns true
|
|
1352
|
-
* is.accessorDescriptor({ get: () => 42, set: () => {} });
|
|
1353
|
-
*
|
|
1354
|
-
* // Returns false
|
|
1355
|
-
* is.accessorDescriptor({ value: 42, writable: true });
|
|
1356
|
-
*/
|
|
1357
|
-
export function accessorDescriptor(value: any, thenValue: any, elseValue: any): any;
|
|
1358
|
-
/**
|
|
1359
|
-
* Check if a value is an array.
|
|
1360
|
-
*
|
|
1361
|
-
* @param value The value to check.
|
|
1362
|
-
* @returns True if the value is an array, false otherwise.
|
|
1363
|
-
*
|
|
1364
|
-
* @example
|
|
1365
|
-
* is.array([1, 2, 3]); // true
|
|
1366
|
-
* is.array('string'); // false
|
|
1367
|
-
*/
|
|
1368
|
-
export function array(value: any, thenValue: any, elseValue: any): any;
|
|
1369
|
-
/**
|
|
1370
|
-
* Check if a value is a bigint.
|
|
1371
|
-
*
|
|
1372
|
-
* @param value The value to check.
|
|
1373
|
-
* @returns True if the value is a bigint, false otherwise.
|
|
1374
|
-
*
|
|
1375
|
-
* @example
|
|
1376
|
-
* is.bigint(123n); // true
|
|
1377
|
-
* is.bigint(123); // false
|
|
1378
|
-
*/
|
|
1379
|
-
export function bigint(value: any, thenValue: any, elseValue: any): any;
|
|
1380
|
-
/**
|
|
1381
|
-
* Checks if a value is strictly a boolean (true or false).
|
|
1382
|
-
*
|
|
1383
|
-
* This method verifies if the provided value is either `true` or `false`.
|
|
1384
|
-
*
|
|
1385
|
-
* @param {*} value - The value to check.
|
|
1386
|
-
* @returns {boolean} True if the value is a boolean, false otherwise.
|
|
1387
|
-
*
|
|
1388
|
-
* @example
|
|
1389
|
-
* is.boolean(true); // true
|
|
1390
|
-
* is.boolean(false); // true
|
|
1391
|
-
* is.boolean(1); // false
|
|
1392
|
-
* is.boolean("true"); // false
|
|
1393
|
-
*/
|
|
1394
|
-
export function boolean(value: any, thenValue: any, elseValue: any): boolean;
|
|
1395
|
-
/**
|
|
1396
|
-
* Check if an object is callable. This function is more or less a
|
|
1397
|
-
* synonym or alias for `is.function()`.
|
|
1398
|
-
*
|
|
1399
|
-
* @param object The object to check.
|
|
1400
|
-
* @returns True if the object is callable, false otherwise.
|
|
1401
|
-
*
|
|
1402
|
-
* @note if you wish to know if a descriptor has a callable `value`,
|
|
1403
|
-
* `get`, or `set` function, use `is.callableDescriptor` instead.
|
|
1404
|
-
*
|
|
1405
|
-
* @example
|
|
1406
|
-
* is.callable(function() {}); // true
|
|
1407
|
-
*/
|
|
1408
|
-
export function callable(object: any, thenValue: any, elseValue: any): any;
|
|
1409
|
-
/**
|
|
1410
|
-
* Check if an object is callable. It looks to see if the object
|
|
1411
|
-
* represents a descriptor that is callable by checking object
|
|
1412
|
-
* properties named `value`, `get`, and `set`. If any three variations
|
|
1413
|
-
* yields a function type, true is returned.
|
|
1414
|
-
*
|
|
1415
|
-
* @param object The object to check.
|
|
1416
|
-
* @returns True if the object is callable, false otherwise.
|
|
1417
|
-
*
|
|
1418
|
-
* @example
|
|
1419
|
-
* is.callable({ get: function() {} }); // true
|
|
1420
|
-
* is.callable(123); // false
|
|
1421
|
-
*
|
|
1422
|
-
* // Note the differences between these
|
|
1423
|
-
* const object = { get name() { return "Brie"; } };
|
|
1424
|
-
* const descriptor = Object.getOwnPropertyDescriptor(object, 'name');
|
|
1425
|
-
* is.callable(object); // false
|
|
1426
|
-
* is.callable(descriptor); // true
|
|
1427
|
-
*/
|
|
1428
|
-
export function callableDescriptor(object: any, thenValue: any, elseValue: any): any;
|
|
1429
|
-
/**
|
|
1430
|
-
* Check if a value is a data property descriptor.
|
|
1431
|
-
*
|
|
1432
|
-
* A data descriptor is an object that describes the configuration of a
|
|
1433
|
-
* property on an object, specifically focusing on the 'value' and
|
|
1434
|
-
* 'writable' attributes. The descriptor is invalid if it contains
|
|
1435
|
-
* thew accessor descriptors `get` or `set`.
|
|
1436
|
-
*
|
|
1437
|
-
* @param value The value to check.
|
|
1438
|
-
* @returns True if the value is a data descriptor, false otherwise.
|
|
1439
|
-
*
|
|
1440
|
-
* @example
|
|
1441
|
-
* // Returns true
|
|
1442
|
-
* is.dataDescriptor({ value: 42, writable: true });
|
|
1443
|
-
*
|
|
1444
|
-
* // Returns false
|
|
1445
|
-
* is.dataDescriptor({ get: () => 42, set: () => {} });
|
|
1446
|
-
*/
|
|
1447
|
-
export function dataDescriptor(value: any, thenValue: any, elseValue: any): any;
|
|
1448
|
-
/**
|
|
1449
|
-
* Check if a value is a property descriptor.
|
|
1450
|
-
*
|
|
1451
|
-
* A property descriptor is an object that describes the configuration of a
|
|
1452
|
-
* property on an object. This function checks if the provided value is an
|
|
1453
|
-
* object and contains any of the standard property descriptor keys.
|
|
1454
|
-
*
|
|
1455
|
-
* @param value The value to check.
|
|
1456
|
-
* @returns True if the value is a property descriptor, false otherwise.
|
|
1457
|
-
*
|
|
1458
|
-
* @example
|
|
1459
|
-
* is.descriptor({ configurable: true, enumerable: false }); // true
|
|
1460
|
-
* is.descriptor({ get: () => {}, set: () => {} }); // true
|
|
1461
|
-
* is.descriptor({}); // false
|
|
1462
|
-
*/
|
|
1463
|
-
export function descriptor(value: any, thenValue: any, elseValue: any): any;
|
|
1464
|
-
/**
|
|
1465
|
-
* Checks if a value is strictly false.
|
|
1466
|
-
*
|
|
1467
|
-
* This method verifies if the provided value is strictly `false`.
|
|
1468
|
-
*
|
|
1469
|
-
* @param {*} value - The value to check.
|
|
1470
|
-
* @returns {boolean} True if the value is strictly false, false otherwise.
|
|
1471
|
-
*
|
|
1472
|
-
* @example
|
|
1473
|
-
* is.false(false); // true
|
|
1474
|
-
* is.false(true); // false
|
|
1475
|
-
* is.false(0); // false
|
|
1476
|
-
*/
|
|
1477
|
-
function _false(value: any, thenValue: any, elseValue: any): boolean;
|
|
1478
|
-
export { _false as false };
|
|
1479
|
-
/**
|
|
1480
|
-
* Checks if a value is falsy.
|
|
1481
|
-
*
|
|
1482
|
-
* This method converts the provided value to a boolean and returns
|
|
1483
|
-
* `true` if the value is falsy (i.e., false, 0, "", null, undefined,
|
|
1484
|
-
* or NaN).
|
|
1485
|
-
*
|
|
1486
|
-
* @param {*} value - The value to check.
|
|
1487
|
-
* @returns {boolean} True if the value is falsy, false otherwise.
|
|
1488
|
-
*
|
|
1489
|
-
* @example
|
|
1490
|
-
* is.falsy(0); // true
|
|
1491
|
-
* is.falsy(""); // true
|
|
1492
|
-
* is.falsy(1); // false
|
|
1493
|
-
* is.falsy("hello"); // false
|
|
1494
|
-
*/
|
|
1495
|
-
export function falsy(value: any, thenValue: any, elseValue: any): boolean;
|
|
1496
|
-
/**
|
|
1497
|
-
* Alias for the `falsy` method.
|
|
1498
|
-
*
|
|
1499
|
-
* This method is an alias for `is.falsy` and performs the same check.
|
|
1500
|
-
*
|
|
1501
|
-
* @param {*} value - The value to check.
|
|
1502
|
-
* @returns {boolean} True if the value is falsy, false otherwise.
|
|
1503
|
-
*
|
|
1504
|
-
* @example
|
|
1505
|
-
* is.falsey(0); // true
|
|
1506
|
-
* is.falsey(""); // true
|
|
1507
|
-
* is.falsey(1); // false
|
|
1508
|
-
* is.falsey("hello"); // false
|
|
1509
|
-
*/
|
|
1510
|
-
export function falsey(value: any, thenValue: any, elseValue: any): boolean;
|
|
1511
|
-
/**
|
|
1512
|
-
* Check if a value is a function.
|
|
1513
|
-
*
|
|
1514
|
-
* @param value The value to check.
|
|
1515
|
-
* @returns True if the value is a function, false otherwise.
|
|
1516
|
-
*
|
|
1517
|
-
* @example
|
|
1518
|
-
* is.function(function() {}); // true
|
|
1519
|
-
* is.function(123); // false
|
|
1520
|
-
*/
|
|
1521
|
-
function _function(value: any, thenValue: any, elseValue: any): any;
|
|
1522
|
-
export { _function as function };
|
|
1523
|
-
/**
|
|
1524
|
-
* Check if a value is iterable. Depending on the environment, JavaScript
|
|
1525
|
-
* will permit `'string'[Symbol.iterator]()` whereas in some places, you
|
|
1526
|
-
* will need to wrap string in an object first. Since other JSVM provided
|
|
1527
|
-
* environments may or may not be leniant with this, we play it safe by
|
|
1528
|
-
* implicitly object converting values before checking for the symbol. If
|
|
1529
|
-
* a value is already an object, it will simply be passed through.
|
|
1530
|
-
*
|
|
1531
|
-
* @param value The value to check.
|
|
1532
|
-
* @returns True if the value is iterable, false otherwise.
|
|
1533
|
-
*
|
|
1534
|
-
* @example
|
|
1535
|
-
* is.iterable([1, 2, 3]); // true
|
|
1536
|
-
* is.iterable('string'); // true
|
|
1537
|
-
* is.iterable(123); // false
|
|
1538
|
-
*/
|
|
1539
|
-
export function iterable(value: any, thenValue: any, elseValue: any): any;
|
|
1540
|
-
/**
|
|
1541
|
-
* Check if a value is null or undefined.
|
|
1542
|
-
*
|
|
1543
|
-
* @param value The value to check.
|
|
1544
|
-
* @returns True if the value is null or undefined, false otherwise.
|
|
1545
|
-
*
|
|
1546
|
-
* @example
|
|
1547
|
-
* is.nullish(null); // true
|
|
1548
|
-
* is.nullish(undefined); // true
|
|
1549
|
-
* is.nullish('value'); // false
|
|
1550
|
-
*/
|
|
1551
|
-
export function nullish(value: any, thenValue: any, elseValue: any): any;
|
|
1552
|
-
/**
|
|
1553
|
-
* Check if a value is a number.
|
|
1554
|
-
*
|
|
1555
|
-
* @param value The value to check.
|
|
1556
|
-
* @returns True if the value is a number, false otherwise.
|
|
1557
|
-
*
|
|
1558
|
-
* @example
|
|
1559
|
-
* is.number(123); // true
|
|
1560
|
-
* is.number('123'); // false
|
|
1561
|
-
*/
|
|
1562
|
-
export function number(value: any, thenValue: any, elseValue: any): any;
|
|
1563
|
-
/**
|
|
1564
|
-
* Check if a value is an object.
|
|
1565
|
-
*
|
|
1566
|
-
* @param value The value to check.
|
|
1567
|
-
* @returns True if the value is an object, false otherwise.
|
|
1568
|
-
*
|
|
1569
|
-
* @example
|
|
1570
|
-
* is.object({}); // true
|
|
1571
|
-
* is.object(null); // false
|
|
1572
|
-
*/
|
|
1573
|
-
export function object(value: any, thenValue: any, elseValue: any): any;
|
|
1574
|
-
/**
|
|
1575
|
-
* Check if a value is a primitive type.
|
|
1576
|
-
*
|
|
1577
|
-
* This function determines if the provided value is one of the JavaScript
|
|
1578
|
-
* primitive types: string, number, boolean, bigint, or symbol.
|
|
1579
|
-
*
|
|
1580
|
-
* @param value The value to check.
|
|
1581
|
-
* @returns True if the value is a primitive type, false otherwise.
|
|
1582
|
-
*
|
|
1583
|
-
* @example
|
|
1584
|
-
* // Returns true
|
|
1585
|
-
* is.primitive('hello');
|
|
1586
|
-
*
|
|
1587
|
-
* // Returns true
|
|
1588
|
-
* is.primitive(123);
|
|
1589
|
-
*
|
|
1590
|
-
* // Returns true
|
|
1591
|
-
* is.primitive(true);
|
|
1592
|
-
*
|
|
1593
|
-
* // Returns true
|
|
1594
|
-
* is.primitive(123n);
|
|
1595
|
-
*
|
|
1596
|
-
* // Returns true
|
|
1597
|
-
* is.primitive(Symbol('symbol'));
|
|
1598
|
-
*
|
|
1599
|
-
* // Returns false
|
|
1600
|
-
* is.primitive({});
|
|
1601
|
-
*
|
|
1602
|
-
* // Returns false
|
|
1603
|
-
* is.primitive([]);
|
|
1604
|
-
*/
|
|
1605
|
-
export function primitive(value: any, thenValue: any, elseValue: any): any;
|
|
1606
|
-
/**
|
|
1607
|
-
* The use of `typeof` is not a safe guarantor when it comes to Reflect
|
|
1608
|
-
* supported values. Any non-null value that returns a `typeof` either
|
|
1609
|
-
* `object` or `function` should suffice. Note that arrays return 'object'
|
|
1610
|
-
* when run through `typeof`. Shiny is clearly a reference to something
|
|
1611
|
-
* reflective and is much shorter to type. Also, Mal says shiny. :)
|
|
1612
|
-
*
|
|
1613
|
-
* @param value The value to check.
|
|
1614
|
-
* @returns True if the value is an object or a function, false otherwise.
|
|
1615
|
-
*
|
|
1616
|
-
* @example
|
|
1617
|
-
* is.shiny({}); // true
|
|
1618
|
-
* is.shiny(function() {}); // true
|
|
1619
|
-
* is.shiny(123); // false
|
|
1620
|
-
*/
|
|
1621
|
-
export function shiny(value: any, thenValue: any, elseValue: any): any;
|
|
1622
|
-
/**
|
|
1623
|
-
* Check if a value is a string.
|
|
1624
|
-
*
|
|
1625
|
-
* @param value The value to check.
|
|
1626
|
-
* @returns True if the value is a string, false otherwise.
|
|
1627
|
-
*
|
|
1628
|
-
* @example
|
|
1629
|
-
* is.string('hello'); // true
|
|
1630
|
-
* is.string(123); // false
|
|
1631
|
-
*/
|
|
1632
|
-
export function string(value: any, thenValue: any, elseValue: any): any;
|
|
1633
|
-
/**
|
|
1634
|
-
* Checks if a value is a symbol.
|
|
1635
|
-
*
|
|
1636
|
-
* This function determines whether the provided value is of type
|
|
1637
|
-
* 'symbol' or an instance of the Symbol object.
|
|
1638
|
-
*
|
|
1639
|
-
* @param value - The value to check.
|
|
1640
|
-
* @returns True if the value is a symbol, false otherwise.
|
|
1641
|
-
*
|
|
1642
|
-
* @example
|
|
1643
|
-
* is.symbol(Symbol('foo')); // Returns true
|
|
1644
|
-
* is.symbol('foo'); // Returns false
|
|
1645
|
-
*/
|
|
1646
|
-
export function symbol(value: any, thenValue: any, elseValue: any): any;
|
|
1647
|
-
export function then(condition: any, thenValue: any, elseValue: any): any;
|
|
1648
|
-
/**
|
|
1649
|
-
* Checks if a value is strictly true.
|
|
1650
|
-
*
|
|
1651
|
-
* This method verifies if the provided value is strictly `true`.
|
|
1652
|
-
*
|
|
1653
|
-
* @param {*} value - The value to check.
|
|
1654
|
-
* @returns {boolean} True if the value is strictly true, false otherwise.
|
|
1655
|
-
*
|
|
1656
|
-
* @example
|
|
1657
|
-
* is.true(true); // true
|
|
1658
|
-
* is.true(false); // false
|
|
1659
|
-
* is.true(1); // false
|
|
1660
|
-
*/
|
|
1661
|
-
function _true(value: any, thenValue: any, elseValue: any): boolean;
|
|
1662
|
-
export { _true as true };
|
|
1663
|
-
/**
|
|
1664
|
-
* Checks if a value is truthy.
|
|
1665
|
-
*
|
|
1666
|
-
* This method converts the provided value to a boolean and returns
|
|
1667
|
-
* `true` if the value is truthy (i.e., not false, 0, "", null, undefined,
|
|
1668
|
-
* or NaN).
|
|
1669
|
-
*
|
|
1670
|
-
* @param {*} value - The value to check.
|
|
1671
|
-
* @returns {boolean} True if the value is truthy, false otherwise.
|
|
1672
|
-
*
|
|
1673
|
-
* @example
|
|
1674
|
-
* is.truthy(1); // true
|
|
1675
|
-
* is.truthy("hello"); // true
|
|
1676
|
-
* is.truthy(0); // false
|
|
1677
|
-
* is.truthy(""); // false
|
|
1678
|
-
*/
|
|
1679
|
-
export function truthy(value: any, thenValue: any, elseValue: any): boolean;
|
|
1680
|
-
}
|
|
1681
|
-
export function has(object: any, key: any): any;
|
|
1682
|
-
export namespace as {
|
|
1683
|
-
/**
|
|
1684
|
-
* Converts a value to an array if it is iterable.
|
|
1685
|
-
*
|
|
1686
|
-
* @param value The value to convert.
|
|
1687
|
-
* @returns The converted array if the value is iterable, otherwise undefined.
|
|
1688
|
-
*
|
|
1689
|
-
* @example
|
|
1690
|
-
* // Returns [1, 2, 3]
|
|
1691
|
-
* as.array([1, 2, 3]);
|
|
1692
|
-
*
|
|
1693
|
-
* @example
|
|
1694
|
-
* // Returns ['s', 't', 'r', 'i', 'n', 'g']
|
|
1695
|
-
* as.array('string');
|
|
1696
|
-
*
|
|
1697
|
-
* @example
|
|
1698
|
-
* // Returns undefined
|
|
1699
|
-
* as.array(123);
|
|
1700
|
-
*/
|
|
1701
|
-
function array(value: any): any;
|
|
1702
|
-
/**
|
|
1703
|
-
* Converts a value to an object. If the supplied value is a primitive
|
|
1704
|
-
* value, in many cases, this will convert it to an object instance of
|
|
1705
|
-
* that type. Numbers, strings, symbols, and big integers, all have
|
|
1706
|
-
* object instance variants. Wrapping them in a call to `Object()` will
|
|
1707
|
-
* convert the primitive into this instance variant.
|
|
1708
|
-
*
|
|
1709
|
-
* @param value The value to convert.
|
|
1710
|
-
* @returns The converted object.
|
|
1711
|
-
*
|
|
1712
|
-
* @example
|
|
1713
|
-
* // Returns { key: 'value' }
|
|
1714
|
-
* as.object({ key: 'value' });
|
|
1715
|
-
*
|
|
1716
|
-
* @example
|
|
1717
|
-
* // String instance as oppposed to primitive string
|
|
1718
|
-
* typeof as.object('string') // 'object'
|
|
1719
|
-
* as.object('string') instanceof String // true
|
|
1720
|
-
* 'string' instanceof String // false
|
|
1721
|
-
*
|
|
1722
|
-
* @example
|
|
1723
|
-
* // Returns {}
|
|
1724
|
-
* as.object(null);
|
|
1725
|
-
*/
|
|
1726
|
-
function object(value: any): any;
|
|
1727
|
-
/**
|
|
1728
|
-
* Converts a given value to a string. This function handles various types
|
|
1729
|
-
* of values, including null, undefined, objects with custom
|
|
1730
|
-
* [Symbol.toPrimitive] methods, and objects with toString or valueOf
|
|
1731
|
-
* methods.
|
|
1732
|
-
*
|
|
1733
|
-
* @param value The value to convert to a string.
|
|
1734
|
-
* @param use Optional configuration object:
|
|
1735
|
-
* - description: If true, returns the description of a Symbol.
|
|
1736
|
-
* - stringTag: If true, returns the [Symbol.toStringTag] value if present.
|
|
1737
|
-
* @returns The string representation of the value.
|
|
1738
|
-
*
|
|
1739
|
-
* @example
|
|
1740
|
-
* // Returns 'null'
|
|
1741
|
-
* as.string(null);
|
|
1742
|
-
*
|
|
1743
|
-
* @example
|
|
1744
|
-
* // Returns '123'
|
|
1745
|
-
* as.string(123);
|
|
1746
|
-
*
|
|
1747
|
-
* @example
|
|
1748
|
-
* // Returns 'custom'
|
|
1749
|
-
* const obj = {
|
|
1750
|
-
* [Symbol.toPrimitive](hint) {
|
|
1751
|
-
* if (hint === 'string') return 'custom';
|
|
1752
|
-
* return null;
|
|
1753
|
-
* }
|
|
1754
|
-
* };
|
|
1755
|
-
* as.string(obj);
|
|
1756
|
-
*
|
|
1757
|
-
* @example
|
|
1758
|
-
* // Returns 'mySymbol'
|
|
1759
|
-
* as.string(Symbol('mySymbol'), { description: true });
|
|
1760
|
-
*
|
|
1761
|
-
* @example
|
|
1762
|
-
* // Returns 'Array'
|
|
1763
|
-
* as.string([], { stringTag: true });
|
|
1764
|
-
*/
|
|
1765
|
-
function string(value: any, use?: {
|
|
1766
|
-
description: boolean;
|
|
1767
|
-
stringTag: boolean;
|
|
1768
|
-
}): any;
|
|
1769
|
-
/**
|
|
1770
|
-
* Converts a given value to a string representing an integer.
|
|
1771
|
-
*
|
|
1772
|
-
* This method first converts the value to a number string and then extracts
|
|
1773
|
-
* the integer part by splitting the string at the decimal point.
|
|
1774
|
-
*
|
|
1775
|
-
* @param value The value to convert to an integer string.
|
|
1776
|
-
* @returns The integer part of the value as a string.
|
|
1777
|
-
*
|
|
1778
|
-
* @example
|
|
1779
|
-
* // Returns '123'
|
|
1780
|
-
* as.integerString(123.456);
|
|
1781
|
-
*
|
|
1782
|
-
* @example
|
|
1783
|
-
* // Returns '0'
|
|
1784
|
-
* as.integerString('0.789');
|
|
1785
|
-
*/
|
|
1786
|
-
function integerString(value: any): any;
|
|
1787
|
-
/**
|
|
1788
|
-
* Converts a given value to a string representing a number.
|
|
1789
|
-
*
|
|
1790
|
-
* This method first converts the value to a string, trims any whitespace,
|
|
1791
|
-
* and removes any non-numeric characters except for '.', 'e', 'E', '+',
|
|
1792
|
-
* and '-'. It then uses a regular expression to match a floating-point
|
|
1793
|
-
* number, allowing an optional leading '+' or '-' sign, digits before
|
|
1794
|
-
* and after a single decimal point.
|
|
1795
|
-
*
|
|
1796
|
-
* @param value The value to convert to a number string.
|
|
1797
|
-
* @returns The sanitized number string or an empty string if no valid
|
|
1798
|
-
* float was found.
|
|
1799
|
-
*
|
|
1800
|
-
* @example
|
|
1801
|
-
* // Returns '123.456'
|
|
1802
|
-
* numberString(' 123.456abc ');
|
|
1803
|
-
*
|
|
1804
|
-
* @example
|
|
1805
|
-
* // Returns '-0.789'
|
|
1806
|
-
* numberString('-0.789xyz');
|
|
1807
|
-
*/
|
|
1808
|
-
function numberString(value: any): any;
|
|
1809
|
-
/**
|
|
1810
|
-
* Converts a given value to a number.
|
|
1811
|
-
*
|
|
1812
|
-
* This method uses the `numberString` method to sanitize the input value
|
|
1813
|
-
* and then converts it to a number.
|
|
1814
|
-
*
|
|
1815
|
-
* @param value The value to convert to a number.
|
|
1816
|
-
* @returns The numeric representation of the value.
|
|
1817
|
-
*
|
|
1818
|
-
* @example
|
|
1819
|
-
* // Returns 123.456
|
|
1820
|
-
* number('123.456abc');
|
|
1821
|
-
*
|
|
1822
|
-
* @example
|
|
1823
|
-
* // Returns -0.789
|
|
1824
|
-
* number('-0.789xyz');
|
|
1825
|
-
*/
|
|
1826
|
-
function number(value: any): number;
|
|
1827
|
-
/**
|
|
1828
|
-
* Converts a given value to a bigint.
|
|
1829
|
-
*
|
|
1830
|
-
* This method uses the `integerString` method to sanitize the input value
|
|
1831
|
-
* and then converts it to a bigint.
|
|
1832
|
-
*
|
|
1833
|
-
* @param value The value to convert to a bigint.
|
|
1834
|
-
* @returns The bigint representation of the value.
|
|
1835
|
-
*
|
|
1836
|
-
* @example
|
|
1837
|
-
* // Returns 123n
|
|
1838
|
-
* bigint('123.456abc');
|
|
1839
|
-
*
|
|
1840
|
-
* @example
|
|
1841
|
-
* // Returns 0n
|
|
1842
|
-
* bigint('0.789xyz');
|
|
1843
|
-
*/
|
|
1844
|
-
function bigint(value: any): bigint;
|
|
1845
|
-
/**
|
|
1846
|
-
* Converts a given value to a boolean.
|
|
1847
|
-
*
|
|
1848
|
-
* This method takes a value, converts it to a string, and then checks
|
|
1849
|
-
* if it matches common representations of boolean values. It returns
|
|
1850
|
-
* `true` for "1", "yes", and "true" (case insensitive), and `false`
|
|
1851
|
-
* for "0", "no", and "false" (case insensitive). For any other values,
|
|
1852
|
-
* it returns the boolean representation of the value.
|
|
1853
|
-
*
|
|
1854
|
-
* @param {*} value - The value to convert to a boolean.
|
|
1855
|
-
* @returns {boolean} The boolean representation of the value.
|
|
1856
|
-
*
|
|
1857
|
-
* @example
|
|
1858
|
-
* // Returns true
|
|
1859
|
-
* is.boolean("yes")
|
|
1860
|
-
*
|
|
1861
|
-
* @example
|
|
1862
|
-
* // Returns false
|
|
1863
|
-
* is.boolean("no")
|
|
1864
|
-
*
|
|
1865
|
-
* @example
|
|
1866
|
-
* // Returns true
|
|
1867
|
-
* is.boolean(1)
|
|
1868
|
-
*
|
|
1869
|
-
* @example
|
|
1870
|
-
* // Returns false
|
|
1871
|
-
* is.boolean(0)
|
|
1872
|
-
*
|
|
1873
|
-
* @example
|
|
1874
|
-
* // Returns true
|
|
1875
|
-
* is.boolean("true")
|
|
1876
|
-
*
|
|
1877
|
-
* @example
|
|
1878
|
-
* // Returns false
|
|
1879
|
-
* is.boolean("false")
|
|
1880
|
-
*
|
|
1881
|
-
* @example
|
|
1882
|
-
* // Returns true
|
|
1883
|
-
* is.boolean({})
|
|
1884
|
-
*
|
|
1885
|
-
* @example
|
|
1886
|
-
* // Returns false
|
|
1887
|
-
* is.boolean(null)
|
|
1888
|
-
*/
|
|
1889
|
-
function boolean(value: any): boolean;
|
|
1890
|
-
}
|
|
1891
|
-
declare namespace _default {
|
|
1892
|
-
export { as };
|
|
1893
|
-
export { has };
|
|
1894
|
-
export { is };
|
|
1895
|
-
export { si };
|
|
1896
|
-
export { createToolkit };
|
|
1897
|
-
}
|
|
1898
|
-
export default _default;
|