@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,165 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BigIntPrototypeExtensions = exports.BigIntExtensions = void 0;
|
|
4
|
-
const extension_1 = require("@nejs/extension");
|
|
5
|
-
/**
|
|
6
|
-
* `BigIntExtensions` is a patch for the JavaScript built-in `BigInt` class.
|
|
7
|
-
* It adds utility methods to the `BigInt` class without modifying the global
|
|
8
|
-
* namespace directly. This patch includes methods for checking if a value is
|
|
9
|
-
* a `BigInt` and conditionally returning a value based on whether the supplied
|
|
10
|
-
* value is a `BigInt` or not.
|
|
11
|
-
*
|
|
12
|
-
* @type {Patch}
|
|
13
|
-
* @example
|
|
14
|
-
* import { BigIntExtensions } from 'big.int.extension.js'
|
|
15
|
-
*
|
|
16
|
-
* BigIntExtensions.apply()
|
|
17
|
-
* // Now the `BigInt` class has additional methods available
|
|
18
|
-
*/
|
|
19
|
-
exports.BigIntExtensions = new extension_1.Patch(BigInt, {
|
|
20
|
-
/**
|
|
21
|
-
* Determines if the supplied `value` is a `BigInt`. This check is
|
|
22
|
-
* performed by first checking the `typeof` the `value` and then
|
|
23
|
-
* checking to see if the `value` is an `instanceof` `BigInt`
|
|
24
|
-
*
|
|
25
|
-
* @param {*} value The value that needs to be checked to determine
|
|
26
|
-
* if it is a `BigInt` or not
|
|
27
|
-
* @returns {boolean} `true` if the supplied `value` is a `BigInt`,
|
|
28
|
-
* `false` otherwise
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* const bigInt = 1234567890123456789012345678901234567890n
|
|
32
|
-
* isBigInt(bigInt) // true
|
|
33
|
-
* isBigInt(1234567890123456789012345678901234567890) // false
|
|
34
|
-
* isBigInt('1234567890123456789012345678901234567890') // false
|
|
35
|
-
* isBigInt(BigInt('1234567890123456789012345678901234567890')) // true
|
|
36
|
-
*/
|
|
37
|
-
isBigInt(value) {
|
|
38
|
-
return typeof value === 'bigint' || value instanceof BigInt;
|
|
39
|
-
},
|
|
40
|
-
/**
|
|
41
|
-
* Conditionally returns a value based on whether the supplied
|
|
42
|
-
* `value` is a `BigInt` or not. If the `value` is a `BigInt`,
|
|
43
|
-
* the `thenValue` will be returned. If it is not a `BigInt`,
|
|
44
|
-
* the `elseValue` will be returned instead.
|
|
45
|
-
*
|
|
46
|
-
* @param {any} value The value to check to determine if it is a
|
|
47
|
-
* `BigInt`
|
|
48
|
-
* @param {any} thenValue The value to return if the supplied
|
|
49
|
-
* `value` is a `BigInt`
|
|
50
|
-
* @param {any} elseValue The value to return if the supplied
|
|
51
|
-
* `value` is not a `BigInt`
|
|
52
|
-
* @returns {any} Either the `thenValue` or `elseValue` depending
|
|
53
|
-
* on if the supplied `value` is a `BigInt`
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* const bigInt = 1234567890123456789012345678901234567890n
|
|
57
|
-
* const num = 42
|
|
58
|
-
* ifBigInt(bigInt, 'is a BigInt', 'not a BigInt')
|
|
59
|
-
* // 'is a BigInt'
|
|
60
|
-
* ifBigInt(num, 'is a BigInt', 'not a BigInt')
|
|
61
|
-
* // 'not a BigInt'
|
|
62
|
-
*/
|
|
63
|
-
ifBigInt(value, thenValue, elseValue) {
|
|
64
|
-
return isThenElse(this.isBigInt(value), thenValue, elseValue);
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
const { isBigInt: pIsBigInt, ifBigInt: pIfBigInt } = exports.BigIntExtensions.patches;
|
|
68
|
-
/**
|
|
69
|
-
* `BigIntPrototypeExtensions` is a patch for the JavaScript built-in
|
|
70
|
-
* `BigInt.prototype`. It adds utility methods to the `BigInt` prototype
|
|
71
|
-
* without modifying the global namespace directly. This patch includes
|
|
72
|
-
* methods for checking if a value is a BigInt and conditionally returning
|
|
73
|
-
* a value based on whether the supplied value is a BigInt or not.
|
|
74
|
-
*
|
|
75
|
-
* @type {Patch}
|
|
76
|
-
* @example
|
|
77
|
-
* import { BigIntPrototypeExtensions } from 'big.int.extension.js'
|
|
78
|
-
*
|
|
79
|
-
* BigIntPrototypeExtensions.apply()
|
|
80
|
-
* // Now the `BigInt` prototype has additional methods available
|
|
81
|
-
*/
|
|
82
|
-
exports.BigIntPrototypeExtensions = new extension_1.Patch(BigInt.prototype, {
|
|
83
|
-
/**
|
|
84
|
-
* A getter method that returns an object representation of the BigInt
|
|
85
|
-
* instance.
|
|
86
|
-
*
|
|
87
|
-
* This method wraps the BigInt instance in an object, allowing it to be
|
|
88
|
-
* treated as an object. The returned object is created using the `Object()`
|
|
89
|
-
* constructor, which takes the BigInt instance as its argument.
|
|
90
|
-
*
|
|
91
|
-
* @type {Object}
|
|
92
|
-
* @readonly
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* const bigInt = 1234567890123456789012345678901234567890n
|
|
96
|
-
* console.log(typeof bigInt) // 'bigint'
|
|
97
|
-
* console.log(typeof bigInt.instance) // 'object'
|
|
98
|
-
*/
|
|
99
|
-
get instance() {
|
|
100
|
-
return Object(this);
|
|
101
|
-
},
|
|
102
|
-
/**
|
|
103
|
-
* A getter method that checks if the current instance is a BigInt.
|
|
104
|
-
*
|
|
105
|
-
* This method uses the `pIsBigInt` function from the `BigIntExtensions`
|
|
106
|
-
* patch to determine if the current instance (`this`) is a BigInt.
|
|
107
|
-
*
|
|
108
|
-
* @type {boolean}
|
|
109
|
-
* @readonly
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* const bigInt = 1234567890123456789012345678901234567890n
|
|
113
|
-
* console.log(bigInt.isBigInt) // Output: true
|
|
114
|
-
*
|
|
115
|
-
* const notBigInt = 42
|
|
116
|
-
* console.log(notBigInt.isBigInt) // Output: false
|
|
117
|
-
*/
|
|
118
|
-
get isBigInt() {
|
|
119
|
-
return pIsBigInt(this);
|
|
120
|
-
},
|
|
121
|
-
/**
|
|
122
|
-
* Checks if the current object is a BigInt and returns the corresponding
|
|
123
|
-
* value based on the result.
|
|
124
|
-
*
|
|
125
|
-
* This method uses the `pIfBigInt` function from the `BigIntExtensions`
|
|
126
|
-
* patch to determine if the current object (`this`) is a BigInt. If it is
|
|
127
|
-
* a BigInt, the `thenValue` is returned. Otherwise, the `elseValue` is
|
|
128
|
-
* returned.
|
|
129
|
-
*
|
|
130
|
-
* @param {any} thenValue - The value to return if the current object
|
|
131
|
-
* is a BigInt.
|
|
132
|
-
* @param {any} elseValue - The value to return if the current object
|
|
133
|
-
* is not a BigInt.
|
|
134
|
-
* @returns {any} The `thenValue` if the current object is a BigInt, or
|
|
135
|
-
* the `elseValue` if it is not a BigInt.
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* const bigInt = 1234567890123456789012345678901234567890n
|
|
139
|
-
* // 'Is a BigInt'
|
|
140
|
-
* console.log(bigInt.ifBigInt('Is a BigInt', 'Not a BigInt'))
|
|
141
|
-
*
|
|
142
|
-
* const notBigInt = 42
|
|
143
|
-
* // 'Not a BigInt'
|
|
144
|
-
* console.log(notBigInt.ifBigInt('Is a BigInt', 'Not a BigInt'))
|
|
145
|
-
*/
|
|
146
|
-
ifBigInt(thenValue, elseValue) {
|
|
147
|
-
return pIfBigInt(this, thenValue, elseValue);
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
// NOTE to self; this is repeated here otherwise a circular reference from
|
|
151
|
-
// Object<->Function<->Global occurs. See original source in global.this.js
|
|
152
|
-
// {@see globalThis.isThenElse}
|
|
153
|
-
function isThenElse(bv, tv, ev) {
|
|
154
|
-
function isFunction(value) { typeof value === 'function'; }
|
|
155
|
-
if (arguments.length > 1) {
|
|
156
|
-
var _then = isFunction(tv) ? tv(bv) : tv;
|
|
157
|
-
if (arguments.length > 2) {
|
|
158
|
-
var _else = isFunction(ev) ? tv(bv) : ev;
|
|
159
|
-
return bv ? _then : _else;
|
|
160
|
-
}
|
|
161
|
-
return bv || _then;
|
|
162
|
-
}
|
|
163
|
-
return bv;
|
|
164
|
-
}
|
|
165
|
-
//# sourceMappingURL=big.int.extension.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"big.int.extension.js","sourceRoot":"","sources":["../../src/big.int.extension.js"],"names":[],"mappings":";;;AAAA,+CAAuC;AAEvC;;;;;;;;;;;;;GAaG;AACU,QAAA,gBAAgB,GAAG,IAAI,iBAAK,CAAC,MAAM,EAAE;IAChD;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,KAAK;QACZ,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,CAAA;IAC7D,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS;QAClC,OAAO,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;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IAAI,KAAK,CAAC;IACvB,CAAC;IAAC,OAAO,EAAE,CAAA;AACb,CAAC"}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The AsyncIterable class extends the concept of Iterable to asynchronous
|
|
3
|
-
* operations. It allows creating iterable objects where each element can be
|
|
4
|
-
* an asynchronous entity, like a Promise. This class is particularly useful
|
|
5
|
-
* when dealing with asynchronous data sources, such as API responses, file
|
|
6
|
-
* reading in chunks, or any other data that is not immediately available but
|
|
7
|
-
* arrives over time.
|
|
8
|
-
*/
|
|
9
|
-
export class AsyncIterable {
|
|
10
|
-
/**
|
|
11
|
-
* Checks if a given value is an async iterable. This method determines if
|
|
12
|
-
* the provided value has a `Symbol.asyncIterator` property that is an async
|
|
13
|
-
* generator function. It's a precise way to identify if the value conforms
|
|
14
|
-
* to the async iterable protocol using an async generator function.
|
|
15
|
-
*
|
|
16
|
-
* Note: This method specifically checks for async generator functions. Some
|
|
17
|
-
* async iterables might use regular async functions that return an async
|
|
18
|
-
* iterator, which this method won't identify.
|
|
19
|
-
*
|
|
20
|
-
* @param {*} value - The value to be checked for async iterability.
|
|
21
|
-
* @returns {boolean} - Returns true if the value is an async iterable
|
|
22
|
-
* implemented using an async generator function, false otherwise.
|
|
23
|
-
*/
|
|
24
|
-
static isAsyncIterable(value: any): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Constructs an instance of AsyncIterable. Similar to Iterable, it can be
|
|
27
|
-
* initialized with either an iterable object, an async generator function,
|
|
28
|
-
* or individual elements. The elements can be promises, direct values, or a
|
|
29
|
-
* mix of both. If the first argument is an iterable or an async generator
|
|
30
|
-
* function, the instance is initialized with the elements from the iterable
|
|
31
|
-
* or the generated elements from the async generator function, followed by
|
|
32
|
-
* any additional arguments. If the first argument is not an iterable or an
|
|
33
|
-
* async generator function, all arguments are treated as individual elements.
|
|
34
|
-
*
|
|
35
|
-
* @param {Iterable|AsyncGeneratorFunction|Promise|*} elementsOrFirstElement -
|
|
36
|
-
* An iterable object, an async generator function, a Promise, or the first
|
|
37
|
-
* element.
|
|
38
|
-
* @param {...Promise|*} moreElements - Additional elements if the first
|
|
39
|
-
* argument is not an iterable or an async generator function.
|
|
40
|
-
*/
|
|
41
|
-
constructor(elementsOrFirstElement: Iterable<any> | AsyncGeneratorFunction | Promise<any> | any, ...moreElements: (Promise<any> | any)[]);
|
|
42
|
-
/**
|
|
43
|
-
* Implements the async iterable protocol. When an instance of AsyncIterable
|
|
44
|
-
* is used in a `for await...of` loop, this async generator function is
|
|
45
|
-
* invoked. It yields each element as a Promise, allowing asynchronous
|
|
46
|
-
* iteration. Elements that are not Promises are automatically wrapped in
|
|
47
|
-
* a resolved Promise to ensure consistency.
|
|
48
|
-
*
|
|
49
|
-
* @returns {AsyncGenerator} An async generator that yields each element as
|
|
50
|
-
* a Promise.
|
|
51
|
-
*/
|
|
52
|
-
[Symbol.asyncIterator](): AsyncGenerator;
|
|
53
|
-
/**
|
|
54
|
-
* Ensures that the constructor of this object instance's name
|
|
55
|
-
* is returned if the string tag for this instance is queried
|
|
56
|
-
*
|
|
57
|
-
* @returns {string} the name of the class
|
|
58
|
-
*/
|
|
59
|
-
get [Symbol.toStringTag](): string;
|
|
60
|
-
#private;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Being able to create a compliant `AsyncIterator` around any type of
|
|
64
|
-
* iterable object. This can be wrapped around any type of object that
|
|
65
|
-
* has a `[Symbol.asyncIterator]` property assigned to a generator
|
|
66
|
-
* function.
|
|
67
|
-
*/
|
|
68
|
-
export class AsyncIterator {
|
|
69
|
-
/**
|
|
70
|
-
* Creates a new `AsyncIterator` object instance.
|
|
71
|
-
*
|
|
72
|
-
* @param {object|AsyncGeneratorFunction} asyncIterable any object that has a
|
|
73
|
-
* `[Symbol.asyncIterable]` property assigned to a generator function or an
|
|
74
|
-
* async generator function itself.
|
|
75
|
-
*/
|
|
76
|
-
constructor(asyncIterable: object | AsyncGeneratorFunction);
|
|
77
|
-
/**
|
|
78
|
-
* Returns a new `Array` derived from the iterable this object
|
|
79
|
-
* wraps.
|
|
80
|
-
*
|
|
81
|
-
* @returns {array} a new `Array` generated from the wrapped
|
|
82
|
-
* iterable. The method is generated from using an async for of
|
|
83
|
-
* loop.
|
|
84
|
-
*/
|
|
85
|
-
asArray(): any[];
|
|
86
|
-
/**
|
|
87
|
-
* Returns the actual iterable object passed to the constructor that
|
|
88
|
-
* created this instance.
|
|
89
|
-
*
|
|
90
|
-
* @returns {object} the object containing the `[Symbol.iterator]`
|
|
91
|
-
*/
|
|
92
|
-
get asyncIterable(): object;
|
|
93
|
-
/**
|
|
94
|
-
* The function retrieves the next value in the iterator. If the
|
|
95
|
-
* the iterator has run its course, `reset()` can be invoked to
|
|
96
|
-
* reset the pointer to the beginning of the iteration.
|
|
97
|
-
*
|
|
98
|
-
* @returns {any} the next value
|
|
99
|
-
*/
|
|
100
|
-
next(): any;
|
|
101
|
-
/**
|
|
102
|
-
* Resets the async iterator to the beginning allowing it to be
|
|
103
|
-
* iterated over again.
|
|
104
|
-
*/
|
|
105
|
-
reset(): Promise<void>;
|
|
106
|
-
/**
|
|
107
|
-
* The existence of this symbol on the object instances, indicates that
|
|
108
|
-
* it can be used in `for(.. of ..)` loops and its values can be
|
|
109
|
-
* extracted from calls to `Array.from()`
|
|
110
|
-
*
|
|
111
|
-
* @returns {AsyncIterable} this is returned since this object is already
|
|
112
|
-
* conforming to the expected JavaScript AsyncIterator interface
|
|
113
|
-
*/
|
|
114
|
-
[Symbol.asyncIterator](): AsyncIterable;
|
|
115
|
-
/**
|
|
116
|
-
* Ensures that the constructor of this object instance's name
|
|
117
|
-
* is returned if the string tag for this instance is queried
|
|
118
|
-
*
|
|
119
|
-
* @returns {string} the name of the class
|
|
120
|
-
*/
|
|
121
|
-
get [Symbol.toStringTag](): string;
|
|
122
|
-
#private;
|
|
123
|
-
}
|
|
124
|
-
export const AsyncIterableExtensions: Extension;
|
|
125
|
-
export const AsyncIteratorExtensions: Extension;
|
|
126
|
-
import { Extension } from '@nejs/extension';
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AsyncIteratorExtensions = exports.AsyncIterableExtensions = exports.AsyncIterator = exports.AsyncIterable = void 0;
|
|
4
|
-
const extension_1 = require("@nejs/extension");
|
|
5
|
-
/**
|
|
6
|
-
* The AsyncIterable class extends the concept of Iterable to asynchronous
|
|
7
|
-
* operations. It allows creating iterable objects where each element can be
|
|
8
|
-
* an asynchronous entity, like a Promise. This class is particularly useful
|
|
9
|
-
* when dealing with asynchronous data sources, such as API responses, file
|
|
10
|
-
* reading in chunks, or any other data that is not immediately available but
|
|
11
|
-
* arrives over time.
|
|
12
|
-
*/
|
|
13
|
-
class AsyncIterable {
|
|
14
|
-
/**
|
|
15
|
-
* Private field to store the elements of the async iterable.
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
18
|
-
#elements = [];
|
|
19
|
-
/**
|
|
20
|
-
* Constructs an instance of AsyncIterable. Similar to Iterable, it can be
|
|
21
|
-
* initialized with either an iterable object, an async generator function,
|
|
22
|
-
* or individual elements. The elements can be promises, direct values, or a
|
|
23
|
-
* mix of both. If the first argument is an iterable or an async generator
|
|
24
|
-
* function, the instance is initialized with the elements from the iterable
|
|
25
|
-
* or the generated elements from the async generator function, followed by
|
|
26
|
-
* any additional arguments. If the first argument is not an iterable or an
|
|
27
|
-
* async generator function, all arguments are treated as individual elements.
|
|
28
|
-
*
|
|
29
|
-
* @param {Iterable|AsyncGeneratorFunction|Promise|*} elementsOrFirstElement -
|
|
30
|
-
* An iterable object, an async generator function, a Promise, or the first
|
|
31
|
-
* element.
|
|
32
|
-
* @param {...Promise|*} moreElements - Additional elements if the first
|
|
33
|
-
* argument is not an iterable or an async generator function.
|
|
34
|
-
*/
|
|
35
|
-
constructor(elementsOrFirstElement, ...moreElements) {
|
|
36
|
-
if (elementsOrFirstElement != null &&
|
|
37
|
-
(typeof elementsOrFirstElement[Symbol.iterator] === 'function' ||
|
|
38
|
-
typeof elementsOrFirstElement[Symbol.asyncIterator] === 'function')) {
|
|
39
|
-
this.#elements = [...elementsOrFirstElement, ...moreElements];
|
|
40
|
-
}
|
|
41
|
-
else if (typeof elementsOrFirstElement === 'function' &&
|
|
42
|
-
elementsOrFirstElement.constructor.name === 'AsyncGeneratorFunction') {
|
|
43
|
-
this.#elements = elementsOrFirstElement();
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
this.#elements = [elementsOrFirstElement, ...moreElements];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Implements the async iterable protocol. When an instance of AsyncIterable
|
|
51
|
-
* is used in a `for await...of` loop, this async generator function is
|
|
52
|
-
* invoked. It yields each element as a Promise, allowing asynchronous
|
|
53
|
-
* iteration. Elements that are not Promises are automatically wrapped in
|
|
54
|
-
* a resolved Promise to ensure consistency.
|
|
55
|
-
*
|
|
56
|
-
* @returns {AsyncGenerator} An async generator that yields each element as
|
|
57
|
-
* a Promise.
|
|
58
|
-
*/
|
|
59
|
-
async *[Symbol.asyncIterator]() {
|
|
60
|
-
for await (const element of this.#elements) {
|
|
61
|
-
// No need to wrap as a promise here since `for await...of` can handle
|
|
62
|
-
// both Promises and non-Promise values.
|
|
63
|
-
yield element;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Ensures that the constructor of this object instance's name
|
|
68
|
-
* is returned if the string tag for this instance is queried
|
|
69
|
-
*
|
|
70
|
-
* @returns {string} the name of the class
|
|
71
|
-
*/
|
|
72
|
-
get [Symbol.toStringTag]() {
|
|
73
|
-
return this.constructor.name;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Checks if a given value is an async iterable. This method determines if
|
|
77
|
-
* the provided value has a `Symbol.asyncIterator` property that is an async
|
|
78
|
-
* generator function. It's a precise way to identify if the value conforms
|
|
79
|
-
* to the async iterable protocol using an async generator function.
|
|
80
|
-
*
|
|
81
|
-
* Note: This method specifically checks for async generator functions. Some
|
|
82
|
-
* async iterables might use regular async functions that return an async
|
|
83
|
-
* iterator, which this method won't identify.
|
|
84
|
-
*
|
|
85
|
-
* @param {*} value - The value to be checked for async iterability.
|
|
86
|
-
* @returns {boolean} - Returns true if the value is an async iterable
|
|
87
|
-
* implemented using an async generator function, false otherwise.
|
|
88
|
-
*/
|
|
89
|
-
static isAsyncIterable(value) {
|
|
90
|
-
const type = Object.prototype.toString.call(value?.[Symbol.asyncIterator]);
|
|
91
|
-
return type === '[object AsyncGeneratorFunction]';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.AsyncIterable = AsyncIterable;
|
|
95
|
-
/**
|
|
96
|
-
* Being able to create a compliant `AsyncIterator` around any type of
|
|
97
|
-
* iterable object. This can be wrapped around any type of object that
|
|
98
|
-
* has a `[Symbol.asyncIterator]` property assigned to a generator
|
|
99
|
-
* function.
|
|
100
|
-
*/
|
|
101
|
-
class AsyncIterator {
|
|
102
|
-
/**
|
|
103
|
-
* Creates a new `AsyncIterator` object instance.
|
|
104
|
-
*
|
|
105
|
-
* @param {object|AsyncGeneratorFunction} asyncIterable any object that has a
|
|
106
|
-
* `[Symbol.asyncIterable]` property assigned to a generator function or an
|
|
107
|
-
* async generator function itself.
|
|
108
|
-
*/
|
|
109
|
-
constructor(asyncIterable) {
|
|
110
|
-
if (typeof asyncIterable === 'function' &&
|
|
111
|
-
asyncIterable.constructor.name === 'AsyncGeneratorFunction') {
|
|
112
|
-
this.#asyncIterable = asyncIterable();
|
|
113
|
-
}
|
|
114
|
-
else if (!asyncIterable ||
|
|
115
|
-
!Reflect.has(asyncIterable, Symbol.asyncIterator)) {
|
|
116
|
-
throw new TypeError('Value used to instantiate AsyncIterator is not an async iterable');
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
this.#asyncIterable = asyncIterable;
|
|
120
|
-
}
|
|
121
|
-
this.#asyncIterator = this.#asyncIterable[Symbol.asyncIterator]();
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Returns a new `Array` derived from the iterable this object
|
|
125
|
-
* wraps.
|
|
126
|
-
*
|
|
127
|
-
* @returns {array} a new `Array` generated from the wrapped
|
|
128
|
-
* iterable. The method is generated from using an async for of
|
|
129
|
-
* loop.
|
|
130
|
-
*/
|
|
131
|
-
async asArray() {
|
|
132
|
-
const array = [];
|
|
133
|
-
for await (const value of this) {
|
|
134
|
-
array.push(value);
|
|
135
|
-
}
|
|
136
|
-
return array;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Returns the actual iterable object passed to the constructor that
|
|
140
|
-
* created this instance.
|
|
141
|
-
*
|
|
142
|
-
* @returns {object} the object containing the `[Symbol.iterator]`
|
|
143
|
-
*/
|
|
144
|
-
get asyncIterable() {
|
|
145
|
-
return this.#asyncIterable;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* The function retrieves the next value in the iterator. If the
|
|
149
|
-
* the iterator has run its course, `reset()` can be invoked to
|
|
150
|
-
* reset the pointer to the beginning of the iteration.
|
|
151
|
-
*
|
|
152
|
-
* @returns {any} the next value
|
|
153
|
-
*/
|
|
154
|
-
async next() {
|
|
155
|
-
const result = await this.#asyncIterator.next();
|
|
156
|
-
if (result.done) {
|
|
157
|
-
return { value: undefined, done: true };
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
return { value: result.value, done: false };
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Resets the async iterator to the beginning allowing it to be
|
|
165
|
-
* iterated over again.
|
|
166
|
-
*/
|
|
167
|
-
async reset() {
|
|
168
|
-
this.#asyncIterator = this.#asyncIterable[Symbol.asyncIterator]();
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* The existence of this symbol on the object instances, indicates that
|
|
172
|
-
* it can be used in `for(.. of ..)` loops and its values can be
|
|
173
|
-
* extracted from calls to `Array.from()`
|
|
174
|
-
*
|
|
175
|
-
* @returns {AsyncIterable} this is returned since this object is already
|
|
176
|
-
* conforming to the expected JavaScript AsyncIterator interface
|
|
177
|
-
*/
|
|
178
|
-
[Symbol.asyncIterator]() {
|
|
179
|
-
return this;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Ensures that the constructor of this object instance's name
|
|
183
|
-
* is returned if the string tag for this instance is queried
|
|
184
|
-
*
|
|
185
|
-
* @returns {string} the name of the class
|
|
186
|
-
*/
|
|
187
|
-
get [Symbol.toStringTag]() {
|
|
188
|
-
return this.constructor.name;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* The object from which its iterator functionality is derived.
|
|
192
|
-
*
|
|
193
|
-
* @type {object}
|
|
194
|
-
* @private
|
|
195
|
-
*/
|
|
196
|
-
#asyncIterable = null;
|
|
197
|
-
/**
|
|
198
|
-
* The results of a call to the iterable's `[Symbol.asyncIterator]`
|
|
199
|
-
* generator function.
|
|
200
|
-
*
|
|
201
|
-
* @type {object}
|
|
202
|
-
* @private
|
|
203
|
-
*/
|
|
204
|
-
#asyncIterator = null;
|
|
205
|
-
}
|
|
206
|
-
exports.AsyncIterator = AsyncIterator;
|
|
207
|
-
exports.AsyncIterableExtensions = new extension_1.Extension(AsyncIterable);
|
|
208
|
-
exports.AsyncIteratorExtensions = new extension_1.Extension(AsyncIterator);
|
|
209
|
-
//# sourceMappingURL=asyncIterable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"asyncIterable.js","sourceRoot":"","sources":["../../../src/classes/asyncIterable.js"],"names":[],"mappings":";;;AAAA,+CAA2C;AAE3C;;;;;;;GAOG;AACH,MAAa,aAAa;IACxB;;;OAGG;IACH,SAAS,GAAG,EAAE,CAAC;IAEf;;;;;;;;;;;;;;;OAeG;IACH,YAAY,sBAAsB,EAAE,GAAG,YAAY;QACjD,IACE,sBAAsB,IAAI,IAAI;YAC9B,CAAC,OAAO,sBAAsB,CA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;;;;;;OAOG;IACH,CAAC,MAAM,CAAC,aAAa,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACH,cAAc,GAAG,IAAI,CAAC;IAEtB;;;;;;OAMG;IACH,cAAc,GAAG,IAAI,CAAC;CACvB;AAnHD,sCAmHC;AAEY,QAAA,uBAAuB,GAAG,IAAI,qBAAS,CAAC,aAAa,CAAC,CAAA;AACtD,QAAA,uBAAuB,GAAG,IAAI,qBAAS,CAAC,aAAa,CAAC,CAAA"}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deferreds, which were first introduced by jQuery for browsers in the early
|
|
3
|
-
* 2000s, are a way to manage asynchronous operations. They have been widely
|
|
4
|
-
* used and replicated by engineers since then. Although the Promise class in
|
|
5
|
-
* modern JavaScript provides a static method called `withResolvers` that
|
|
6
|
-
* returns an object with similar properties to a Deferred, it is not directly
|
|
7
|
-
* supported by Node.js.
|
|
8
|
-
*
|
|
9
|
-
* ```
|
|
10
|
-
* const withResolvers = Promise.withResolvers()
|
|
11
|
-
* Reflect.has(withResolvers, 'promise') // true
|
|
12
|
-
* Reflect.has(withResolvers, 'resolve') // true
|
|
13
|
-
* Reflect.has(withResolvers, 'reject') // true
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* This Deferred class extends the Promise class, allowing it to capture the
|
|
17
|
-
* value or reason for easy access after resolution, akin to
|
|
18
|
-
* {@link Promise.withResolvers}. As it extends {@link Promise}, it is
|
|
19
|
-
* 'thenable' and works with `await` as if it were a native Promise. This
|
|
20
|
-
* allows seamless integration with code expecting Promise-like objects.
|
|
21
|
-
*/
|
|
22
|
-
export class Deferred extends Promise<any> {
|
|
23
|
-
/**
|
|
24
|
-
* A getter for the species symbol which returns a custom DeferredPromise
|
|
25
|
-
* class. This class extends from Deferred and is used to ensure that the
|
|
26
|
-
* constructor signature matches that of a Promise. The executor function
|
|
27
|
-
* passed to the constructor of this class is used to initialize the Deferred
|
|
28
|
-
* object with resolve and reject functions, similar to how a Promise would
|
|
29
|
-
* be initialized.
|
|
30
|
-
*
|
|
31
|
-
* @returns {DeferredPromise} A DeferredPromise class that extends Deferred.
|
|
32
|
-
*/
|
|
33
|
-
static get [Symbol.species](): DeferredPromise;
|
|
34
|
-
/**
|
|
35
|
-
* The constructor for Deferred instances. By default, a new Deferred will
|
|
36
|
-
* have three important properties: `promise`, `resolve`, and `reject`.
|
|
37
|
-
*
|
|
38
|
-
* The constructor takes an object called `options`. It can have the
|
|
39
|
-
* following properties:
|
|
40
|
-
*
|
|
41
|
-
* ```
|
|
42
|
-
* interface BaseDeferredOptions {
|
|
43
|
-
* // Deferreds store the value or reason. To turn this off, pass true
|
|
44
|
-
* // to this option.
|
|
45
|
-
* doNotTrackAnswers?: boolean;
|
|
46
|
-
* }
|
|
47
|
-
*
|
|
48
|
-
* interface ResolveDeferredOptions {
|
|
49
|
-
* // Passing in an option object with a resolve value will auto resolve
|
|
50
|
-
* // the Deferred with your value. An error will be raised if both
|
|
51
|
-
* // resolve and reject are supplied at the same time.
|
|
52
|
-
* resolve?: (value: any) => void;
|
|
53
|
-
* }
|
|
54
|
-
*
|
|
55
|
-
* interface RejectDeferredOptions {
|
|
56
|
-
* // Passing in an option object with a reject reason will auto reject
|
|
57
|
-
* // the Deferred with your reason. An error will be raised if both
|
|
58
|
-
* // resolve and reject are supplied at the same time.
|
|
59
|
-
* reject?: (reason: any) => void;
|
|
60
|
-
* }
|
|
61
|
-
*
|
|
62
|
-
* type DeferredOptions = BaseDeferredOptions &
|
|
63
|
-
* (ResolveDeferredOptions | RejectDeferredOptions)
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @param {object} options see above for examples on supported options, but
|
|
67
|
-
* when supplied, the constructor can take instructions on how to auto
|
|
68
|
-
* resolve or reject the deferred created here.
|
|
69
|
-
*/
|
|
70
|
-
constructor(options: object);
|
|
71
|
-
/**
|
|
72
|
-
* When the Deferred is settled with {@link Deferred.resolve}, the `value`
|
|
73
|
-
* passed to that function will be set here as well.
|
|
74
|
-
*
|
|
75
|
-
* @type {*}
|
|
76
|
-
*/
|
|
77
|
-
value: any;
|
|
78
|
-
/**
|
|
79
|
-
* When the Deferred is settled with {@link Deferred.reject}, the `reason`
|
|
80
|
-
* passed to that rejection will also be stored here.
|
|
81
|
-
*
|
|
82
|
-
* @type {*}
|
|
83
|
-
*/
|
|
84
|
-
reason: any;
|
|
85
|
-
/**
|
|
86
|
-
* Returns a boolean value that indicates whether or not this Deferred
|
|
87
|
-
* has been settled (either resolve or reject have been invoked).
|
|
88
|
-
*
|
|
89
|
-
* @returns {boolean} `true` if either {@link Deferred.resolve} or
|
|
90
|
-
* {@link Deferred.reject} have been invoked; `false` otherwise
|
|
91
|
-
*/
|
|
92
|
-
get settled(): boolean;
|
|
93
|
-
/**
|
|
94
|
-
* A getter that returns a boolean indicating whether the Deferred instance
|
|
95
|
-
* was rejected. This property can be used to check if the Deferred has been
|
|
96
|
-
* settled with a rejection. It is particularly useful in scenarios where
|
|
97
|
-
* the resolution status of the Deferred needs to be checked without
|
|
98
|
-
* accessing the rejection reason or invoking any additional logic.
|
|
99
|
-
*
|
|
100
|
-
* @returns {boolean} `true` if the Deferred was rejected, otherwise `false`.
|
|
101
|
-
*/
|
|
102
|
-
get wasRejected(): boolean;
|
|
103
|
-
/**
|
|
104
|
-
* A getter that returns a boolean indicating whether the Deferred instance
|
|
105
|
-
* was resolved. This property is useful for checking if the Deferred has been
|
|
106
|
-
* settled with a resolution, allowing for checks on the Deferred's status
|
|
107
|
-
* without needing to access the resolved value or trigger any additional
|
|
108
|
-
* logic.
|
|
109
|
-
*
|
|
110
|
-
* @returns {boolean} `true` if the Deferred was resolved, otherwise `false`.
|
|
111
|
-
*/
|
|
112
|
-
get wasResolved(): boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Accessor for the promise managed by this Deferred instance.
|
|
115
|
-
*
|
|
116
|
-
* This getter provides access to the internal promise which is controlled
|
|
117
|
-
* by the Deferred's resolve and reject methods. It allows external code to
|
|
118
|
-
* attach callbacks for the resolution or rejection of the Deferred without
|
|
119
|
-
* the ability to directly resolve or reject it.
|
|
120
|
-
*
|
|
121
|
-
* @returns {Promise} The promise controlled by this Deferred instance.
|
|
122
|
-
*/
|
|
123
|
-
get promise(): Promise<any>;
|
|
124
|
-
/**
|
|
125
|
-
* Resolves the Deferred with the given value. If the value is a thenable
|
|
126
|
-
* (i.e., has a "then" method), the Deferred will "follow" that thenable,
|
|
127
|
-
* adopting its eventual state; otherwise, the Deferred will be fulfilled
|
|
128
|
-
* with the value. This function behaves the same as Promise.resolve.
|
|
129
|
-
*
|
|
130
|
-
* @param {*} value - The value to resolve the Deferred with.
|
|
131
|
-
* @returns {Promise} A Promise that is resolved with the given value.
|
|
132
|
-
*/
|
|
133
|
-
resolve(value: any): Promise<any>;
|
|
134
|
-
/**
|
|
135
|
-
* Rejects the Deferred with the given reason. This function behaves the
|
|
136
|
-
* same as Promise.reject. The Deferred will be rejected with the provided
|
|
137
|
-
* reason.
|
|
138
|
-
*
|
|
139
|
-
* @param {*} reason - The reason to reject the Deferred with.
|
|
140
|
-
* @returns {Promise} A Promise that is rejected with the given reason.
|
|
141
|
-
*/
|
|
142
|
-
reject(reason: any): Promise<any>;
|
|
143
|
-
#private;
|
|
144
|
-
}
|
|
145
|
-
export const DeferredExtension: Extension;
|
|
146
|
-
import { Extension } from '@nejs/extension';
|