@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,291 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DeferredExtension = exports.Deferred = void 0;
|
|
4
|
-
const extension_1 = require("@nejs/extension");
|
|
5
|
-
/**
|
|
6
|
-
* Deferreds, which were first introduced by jQuery for browsers in the early
|
|
7
|
-
* 2000s, are a way to manage asynchronous operations. They have been widely
|
|
8
|
-
* used and replicated by engineers since then. Although the Promise class in
|
|
9
|
-
* modern JavaScript provides a static method called `withResolvers` that
|
|
10
|
-
* returns an object with similar properties to a Deferred, it is not directly
|
|
11
|
-
* supported by Node.js.
|
|
12
|
-
*
|
|
13
|
-
* ```
|
|
14
|
-
* const withResolvers = Promise.withResolvers()
|
|
15
|
-
* Reflect.has(withResolvers, 'promise') // true
|
|
16
|
-
* Reflect.has(withResolvers, 'resolve') // true
|
|
17
|
-
* Reflect.has(withResolvers, 'reject') // true
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* This Deferred class extends the Promise class, allowing it to capture the
|
|
21
|
-
* value or reason for easy access after resolution, akin to
|
|
22
|
-
* {@link Promise.withResolvers}. As it extends {@link Promise}, it is
|
|
23
|
-
* 'thenable' and works with `await` as if it were a native Promise. This
|
|
24
|
-
* allows seamless integration with code expecting Promise-like objects.
|
|
25
|
-
*/
|
|
26
|
-
class Deferred extends Promise {
|
|
27
|
-
/**
|
|
28
|
-
* The promise backing this deferred object. Created when the constructor
|
|
29
|
-
* runs, this promise is what all `Promise.prototype` functions are routed
|
|
30
|
-
* to.
|
|
31
|
-
*
|
|
32
|
-
* @type {Promise}
|
|
33
|
-
*/
|
|
34
|
-
#promise = null;
|
|
35
|
-
/**
|
|
36
|
-
* The reject() resolver that will be assigned when a new instance is
|
|
37
|
-
* created. Invoking this function with or without a `reason` will cause
|
|
38
|
-
* the deferred's promise to be settled.
|
|
39
|
-
*
|
|
40
|
-
* @type {function}
|
|
41
|
-
*/
|
|
42
|
-
#reject = null;
|
|
43
|
-
/**
|
|
44
|
-
* The resolve() resolver that will be assigned when a new instance is
|
|
45
|
-
* created. Invoking this function with or without a `value` will cause
|
|
46
|
-
* the deferred's promise to be settled.
|
|
47
|
-
*
|
|
48
|
-
* @type {function}
|
|
49
|
-
*/
|
|
50
|
-
#resolve = null;
|
|
51
|
-
#rejected = false;
|
|
52
|
-
#resolved = false;
|
|
53
|
-
/**
|
|
54
|
-
* When the Deferred is settled with {@link Deferred.resolve}, the `value`
|
|
55
|
-
* passed to that function will be set here as well.
|
|
56
|
-
*
|
|
57
|
-
* @type {*}
|
|
58
|
-
*/
|
|
59
|
-
value = null;
|
|
60
|
-
/**
|
|
61
|
-
* When the Deferred is settled with {@link Deferred.reject}, the `reason`
|
|
62
|
-
* passed to that rejection will also be stored here.
|
|
63
|
-
*
|
|
64
|
-
* @type {*}
|
|
65
|
-
*/
|
|
66
|
-
reason = null;
|
|
67
|
-
/**
|
|
68
|
-
* When either {@link Deferred.resolve} or {@link Deferred.reject} are called,
|
|
69
|
-
* this property is set to `true`. Its current status at any time can be
|
|
70
|
-
* queried using the {@link Deferred.settled} getter.
|
|
71
|
-
*
|
|
72
|
-
* @type {boolean}
|
|
73
|
-
*/
|
|
74
|
-
#settled = false;
|
|
75
|
-
/**
|
|
76
|
-
* The constructor for Deferred instances. By default, a new Deferred will
|
|
77
|
-
* have three important properties: `promise`, `resolve`, and `reject`.
|
|
78
|
-
*
|
|
79
|
-
* The constructor takes an object called `options`. It can have the
|
|
80
|
-
* following properties:
|
|
81
|
-
*
|
|
82
|
-
* ```
|
|
83
|
-
* interface BaseDeferredOptions {
|
|
84
|
-
* // Deferreds store the value or reason. To turn this off, pass true
|
|
85
|
-
* // to this option.
|
|
86
|
-
* doNotTrackAnswers?: boolean;
|
|
87
|
-
* }
|
|
88
|
-
*
|
|
89
|
-
* interface ResolveDeferredOptions {
|
|
90
|
-
* // Passing in an option object with a resolve value will auto resolve
|
|
91
|
-
* // the Deferred with your value. An error will be raised if both
|
|
92
|
-
* // resolve and reject are supplied at the same time.
|
|
93
|
-
* resolve?: (value: any) => void;
|
|
94
|
-
* }
|
|
95
|
-
*
|
|
96
|
-
* interface RejectDeferredOptions {
|
|
97
|
-
* // Passing in an option object with a reject reason will auto reject
|
|
98
|
-
* // the Deferred with your reason. An error will be raised if both
|
|
99
|
-
* // resolve and reject are supplied at the same time.
|
|
100
|
-
* reject?: (reason: any) => void;
|
|
101
|
-
* }
|
|
102
|
-
*
|
|
103
|
-
* type DeferredOptions = BaseDeferredOptions &
|
|
104
|
-
* (ResolveDeferredOptions | RejectDeferredOptions)
|
|
105
|
-
* ```
|
|
106
|
-
*
|
|
107
|
-
* @param {object} options see above for examples on supported options, but
|
|
108
|
-
* when supplied, the constructor can take instructions on how to auto
|
|
109
|
-
* resolve or reject the deferred created here.
|
|
110
|
-
*/
|
|
111
|
-
constructor(options) {
|
|
112
|
-
// Check if options is an object, if not, assign an empty object to config
|
|
113
|
-
const config = (options && typeof (options) === 'object'
|
|
114
|
-
? options
|
|
115
|
-
: {});
|
|
116
|
-
// Throw an error if both resolve and reject options are provided
|
|
117
|
-
if (config?.resolve && config?.reject) {
|
|
118
|
-
throw new TypeError('resolve and reject options cannot be simultaneously provided');
|
|
119
|
-
}
|
|
120
|
-
// Create an empty object to store the resolve and reject functions
|
|
121
|
-
let _resolve, _reject;
|
|
122
|
-
// Create a new promise and assign its resolve and reject functions to resolvers
|
|
123
|
-
super((resolve, reject) => {
|
|
124
|
-
_resolve = resolve;
|
|
125
|
-
_reject = reject;
|
|
126
|
-
if (config?.executor && typeof (config?.executor) === 'function') {
|
|
127
|
-
config?.executor(resolve, reject);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
// Define the resolve function for the Deferred instance
|
|
131
|
-
this.#resolve = (value) => {
|
|
132
|
-
// If doNotTrackAnswers is not set to true, store the value
|
|
133
|
-
if (config?.doNotTrackAnswers !== true) {
|
|
134
|
-
this.value = value;
|
|
135
|
-
}
|
|
136
|
-
// Mark the Deferred instance as settled
|
|
137
|
-
this.#settled = true;
|
|
138
|
-
// Mark the Deferred instance as resolved
|
|
139
|
-
this.#resolved = true;
|
|
140
|
-
// Resolve the promise with the provided value
|
|
141
|
-
return _resolve(value);
|
|
142
|
-
};
|
|
143
|
-
// Define the reject function for the Deferred instance
|
|
144
|
-
this.#reject = async (reason) => {
|
|
145
|
-
// If doNotTrackAnswers is not set to true, store the reason
|
|
146
|
-
if (config?.doNotTrackAnswers !== true) {
|
|
147
|
-
this.reason = reason;
|
|
148
|
-
}
|
|
149
|
-
// Mark the Deferred instance as settled
|
|
150
|
-
this.#settled = true;
|
|
151
|
-
// Mark the Deferred as being rejected.
|
|
152
|
-
this.#rejected = true;
|
|
153
|
-
// Reject the promise with the provided reason
|
|
154
|
-
return _reject(reason);
|
|
155
|
-
};
|
|
156
|
-
this.#promise = this;
|
|
157
|
-
// If a resolve option is provided, resolve the Deferred instance with it
|
|
158
|
-
if (config?.resolve) {
|
|
159
|
-
this.#resolve(config?.resolve);
|
|
160
|
-
}
|
|
161
|
-
// If a reject option is provided, reject the Deferred instance with it
|
|
162
|
-
else if (config?.reject) {
|
|
163
|
-
this.#reject(config?.reject);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Returns a boolean value that indicates whether or not this Deferred
|
|
168
|
-
* has been settled (either resolve or reject have been invoked).
|
|
169
|
-
*
|
|
170
|
-
* @returns {boolean} `true` if either {@link Deferred.resolve} or
|
|
171
|
-
* {@link Deferred.reject} have been invoked; `false` otherwise
|
|
172
|
-
*/
|
|
173
|
-
get settled() {
|
|
174
|
-
return this.#settled;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* A getter that returns a boolean indicating whether the Deferred instance
|
|
178
|
-
* was rejected. This property can be used to check if the Deferred has been
|
|
179
|
-
* settled with a rejection. It is particularly useful in scenarios where
|
|
180
|
-
* the resolution status of the Deferred needs to be checked without
|
|
181
|
-
* accessing the rejection reason or invoking any additional logic.
|
|
182
|
-
*
|
|
183
|
-
* @returns {boolean} `true` if the Deferred was rejected, otherwise `false`.
|
|
184
|
-
*/
|
|
185
|
-
get wasRejected() {
|
|
186
|
-
return this.#rejected;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* A getter that returns a boolean indicating whether the Deferred instance
|
|
190
|
-
* was resolved. This property is useful for checking if the Deferred has been
|
|
191
|
-
* settled with a resolution, allowing for checks on the Deferred's status
|
|
192
|
-
* without needing to access the resolved value or trigger any additional
|
|
193
|
-
* logic.
|
|
194
|
-
*
|
|
195
|
-
* @returns {boolean} `true` if the Deferred was resolved, otherwise `false`.
|
|
196
|
-
*/
|
|
197
|
-
get wasResolved() {
|
|
198
|
-
return this.#resolved;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Accessor for the promise managed by this Deferred instance.
|
|
202
|
-
*
|
|
203
|
-
* This getter provides access to the internal promise which is controlled
|
|
204
|
-
* by the Deferred's resolve and reject methods. It allows external code to
|
|
205
|
-
* attach callbacks for the resolution or rejection of the Deferred without
|
|
206
|
-
* the ability to directly resolve or reject it.
|
|
207
|
-
*
|
|
208
|
-
* @returns {Promise} The promise controlled by this Deferred instance.
|
|
209
|
-
*/
|
|
210
|
-
get promise() {
|
|
211
|
-
return this.#promise;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Resolves the Deferred with the given value. If the value is a thenable
|
|
215
|
-
* (i.e., has a "then" method), the Deferred will "follow" that thenable,
|
|
216
|
-
* adopting its eventual state; otherwise, the Deferred will be fulfilled
|
|
217
|
-
* with the value. This function behaves the same as Promise.resolve.
|
|
218
|
-
*
|
|
219
|
-
* @param {*} value - The value to resolve the Deferred with.
|
|
220
|
-
* @returns {Promise} A Promise that is resolved with the given value.
|
|
221
|
-
*/
|
|
222
|
-
resolve(value) {
|
|
223
|
-
return this.#resolve(value);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Rejects the Deferred with the given reason. This function behaves the
|
|
227
|
-
* same as Promise.reject. The Deferred will be rejected with the provided
|
|
228
|
-
* reason.
|
|
229
|
-
*
|
|
230
|
-
* @param {*} reason - The reason to reject the Deferred with.
|
|
231
|
-
* @returns {Promise} A Promise that is rejected with the given reason.
|
|
232
|
-
*/
|
|
233
|
-
reject(reason) {
|
|
234
|
-
return this.#reject(reason);
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Customizes the output of `util.inspect` on instances of Deferred when
|
|
238
|
-
* used in Node.js. This method is invoked by Node.js's `util.inspect`
|
|
239
|
-
* utility to format the inspection output of a Deferred instance.
|
|
240
|
-
*
|
|
241
|
-
* The output includes the state of the Deferred (resolved, rejected, or
|
|
242
|
-
* unsettled) along with the resolved value or rejection reason, if
|
|
243
|
-
* applicable. This provides a quick, readable status of the Deferred
|
|
244
|
-
* instance directly in the console or debugging tools.
|
|
245
|
-
*
|
|
246
|
-
* @param {number} depth The depth to which `util.inspect` will recurse.
|
|
247
|
-
* @param {object} options Formatting options provided by `util.inspect`.
|
|
248
|
-
* @param {function} inspect Reference to the `util.inspect` function.
|
|
249
|
-
* @returns {string} A formatted string representing the Deferred instance.
|
|
250
|
-
*/
|
|
251
|
-
[Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {
|
|
252
|
-
return [
|
|
253
|
-
'\x1b[1mDeferred [\x1b[22;3mPromise\x1b[23;1m]\x1b[22m ',
|
|
254
|
-
'{ ',
|
|
255
|
-
(this.settled
|
|
256
|
-
? (this.wasResolved
|
|
257
|
-
? `resolved with \x1b[32m${this.value}\x1b[39m`
|
|
258
|
-
: `rejected with \x1b[31m${this.reason?.message ?? this.reason}\x1b[39m`)
|
|
259
|
-
: '\x1b[33munsettled valued or reason\x1b[39m'),
|
|
260
|
-
' }'
|
|
261
|
-
].join('');
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* A getter for the species symbol which returns a custom DeferredPromise
|
|
265
|
-
* class. This class extends from Deferred and is used to ensure that the
|
|
266
|
-
* constructor signature matches that of a Promise. The executor function
|
|
267
|
-
* passed to the constructor of this class is used to initialize the Deferred
|
|
268
|
-
* object with resolve and reject functions, similar to how a Promise would
|
|
269
|
-
* be initialized.
|
|
270
|
-
*
|
|
271
|
-
* @returns {DeferredPromise} A DeferredPromise class that extends Deferred.
|
|
272
|
-
*/
|
|
273
|
-
static get [Symbol.species]() {
|
|
274
|
-
return class DeferredPromise extends Deferred {
|
|
275
|
-
/**
|
|
276
|
-
* The constructor for the DeferredPromise class.
|
|
277
|
-
* It takes an executor function which is used to initialize the Deferred.
|
|
278
|
-
*
|
|
279
|
-
* @param {Function} executor - A function that is passed with the resolve
|
|
280
|
-
* and reject functions. The executor is expected to initialize the
|
|
281
|
-
* Deferred by calling resolve or reject at some point.
|
|
282
|
-
*/
|
|
283
|
-
constructor(executor) {
|
|
284
|
-
super({ executor });
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
exports.Deferred = Deferred;
|
|
290
|
-
exports.DeferredExtension = new extension_1.Extension(Deferred);
|
|
291
|
-
//# sourceMappingURL=deferred.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deferred.js","sourceRoot":"","sources":["../../../src/classes/deferred.js"],"names":[],"mappings":"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"}
|
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
export class Descriptor {
|
|
2
|
-
/**
|
|
3
|
-
* The function `getData` retrieves the value of a property from an object
|
|
4
|
-
* if it exists and is a data property.
|
|
5
|
-
*
|
|
6
|
-
* @param {object} object - The "object" parameter is the object from which
|
|
7
|
-
* we want to retrieve data.
|
|
8
|
-
* @param {string|symbol} property - The `property` parameter is the name of
|
|
9
|
-
* the property that you want to retrieve the data from.
|
|
10
|
-
* @returns either the value of the specified property if it exists and is
|
|
11
|
-
* a data property, or undefined if the property does not exist or is not
|
|
12
|
-
* a data property.
|
|
13
|
-
*/
|
|
14
|
-
static getData(object: object, property: string | symbol): any;
|
|
15
|
-
/**
|
|
16
|
-
* The function `getAccessor` checks if an object has a getter/setter accessor
|
|
17
|
-
* for a given property and returns the accessor functions if found.
|
|
18
|
-
*
|
|
19
|
-
* @param object - The `object` parameter is the object from which we want to
|
|
20
|
-
* retrieve the accessor for a specific property.
|
|
21
|
-
* @param property - The `property` parameter is the name of the property for
|
|
22
|
-
* which we want to get the accessor.
|
|
23
|
-
* @returns an object that contains the getter and setter functions for the
|
|
24
|
-
* specified property of the given object. If the property is an accessor
|
|
25
|
-
* property (defined with a getter and/or setter), the returned object will
|
|
26
|
-
* also have additional properties such as "accessor" and "descriptor". If
|
|
27
|
-
* the property is not found or is not an accessor property, the function
|
|
28
|
-
* returns undefined.
|
|
29
|
-
*/
|
|
30
|
-
static getAccessor(object: any, property: any): any;
|
|
31
|
-
/**
|
|
32
|
-
* The function returns an object with enumerable and configurable properties
|
|
33
|
-
* based on the input parameters.
|
|
34
|
-
*
|
|
35
|
-
* @param [enumerable=false] - A boolean value indicating whether the property
|
|
36
|
-
* can be enumerated (listed) when iterating over the object's properties.
|
|
37
|
-
* @param [configurable=false] - The `configurable` parameter determines
|
|
38
|
-
* whether the property can be deleted or its attributes can be modified.
|
|
39
|
-
* If `configurable` is set to `true`, the property can be deleted and its
|
|
40
|
-
* attributes can be changed. If `configurable` is set to `false`, the
|
|
41
|
-
* property cannot be deleted and
|
|
42
|
-
* @returns An object with the properties `enumerable` and `configurable` is
|
|
43
|
-
* being returned. The values of these properties are determined by the
|
|
44
|
-
* arguments passed to the `base` function.
|
|
45
|
-
*/
|
|
46
|
-
static base(enumerable?: boolean | undefined, configurable?: boolean | undefined): {
|
|
47
|
-
enumerable: boolean;
|
|
48
|
-
configurable: boolean;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* The function "newAccessor" creates a new property descriptor object with a
|
|
52
|
-
* getter and setter function, along with optional enumerable and configurable
|
|
53
|
-
* flags.
|
|
54
|
-
*
|
|
55
|
-
* @param getter - The getter parameter is a function that will be used as the
|
|
56
|
-
* getter for the property. It will be called when the property is accessed.
|
|
57
|
-
* @param setter - The `setter` parameter is a function that will be used as
|
|
58
|
-
* the setter for the property. It will be called whenever the property is
|
|
59
|
-
* assigned a new value.
|
|
60
|
-
* @param [] - - `getter`: A function that will be used as the getter for the
|
|
61
|
-
* property.
|
|
62
|
-
* @returns an object with properties "get", "set", "enumerable", and
|
|
63
|
-
* "configurable".
|
|
64
|
-
*/
|
|
65
|
-
static accessor(...args: any[]): any;
|
|
66
|
-
/**
|
|
67
|
-
* The function "newData" creates a new data object with customizable
|
|
68
|
-
* properties.
|
|
69
|
-
*
|
|
70
|
-
* @param value - The value parameter represents the value that will be
|
|
71
|
-
* assigned to the property.
|
|
72
|
-
* @param [writable=true] - The `writable` parameter determines whether the
|
|
73
|
-
* value of the property can be changed. If `writable` is set to `true`, the
|
|
74
|
-
* value can be changed. If `writable` is set to `false`, the value cannot be
|
|
75
|
-
* changed.
|
|
76
|
-
* @param [] - - `value`: The value to be assigned to the property.
|
|
77
|
-
* @returns an object with properties `value`, `enumerable`, `writable`, and
|
|
78
|
-
* `configurable`.
|
|
79
|
-
*/
|
|
80
|
-
static data(value: any, writable?: boolean | undefined, { enumerable, configurable }?: {
|
|
81
|
-
configurable: boolean;
|
|
82
|
-
enumerable: boolean;
|
|
83
|
-
} | undefined): any;
|
|
84
|
-
/**
|
|
85
|
-
* Shorthand for Object.getOwnPropertyDescriptor()
|
|
86
|
-
*
|
|
87
|
-
* @param {object} object a non-null object instance
|
|
88
|
-
* @param {string|symbol} key a symbol or string referencing which key on the
|
|
89
|
-
* object to return a descriptor for.
|
|
90
|
-
* @returns an object descriptor for the requested field or null
|
|
91
|
-
*/
|
|
92
|
-
static for(object: object, key: string | symbol, wrap?: boolean): PropertyDescriptor | Descriptor | null | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* The function checks if an object is a likely an object descriptor in
|
|
95
|
-
* JavaScript. This is determined as an object with some of the known
|
|
96
|
-
* descriptor keys (e.g. enumerable, configurable, value, writable, get,
|
|
97
|
-
* or set). Technically, any object could serve as a descriptor but this
|
|
98
|
-
* function only returns true if known descriptor keys are found.
|
|
99
|
-
*
|
|
100
|
-
* @param {any} object - Any value we want to check for being a descriptor.
|
|
101
|
-
* @param {boolean} returnStatsInstead defaults to false, but if the value
|
|
102
|
-
* is `true` then an object with reasoning behind the decision of whether
|
|
103
|
-
* or not the
|
|
104
|
-
* @returns {IsDescriptorResponse} either a {@link boolean} value or
|
|
105
|
-
* an object conforming to {@link IsDescriptorStats} if `returnStatsInstead`
|
|
106
|
-
* is `true`
|
|
107
|
-
*
|
|
108
|
-
* @see {@link DescriptorUtils.isDescriptor}
|
|
109
|
-
*/
|
|
110
|
-
static isDescriptor(object: any, returnStatsInstead?: boolean): IsDescriptorResponse;
|
|
111
|
-
/**
|
|
112
|
-
* The function checks if a given property descriptor or property of an
|
|
113
|
-
* object is an accessor.
|
|
114
|
-
*
|
|
115
|
-
* @param {object} objectOrDescriptor - The `objectOrDescriptor` parameter
|
|
116
|
-
* can be either a descriptor object or a property name.
|
|
117
|
-
* @param {(string|number|symbol)?} property the property name you wish to
|
|
118
|
-
* check the validity as an accessor descriptor. Only expected if the
|
|
119
|
-
* `objectOrDescriptor` parameter is the object that would contain this
|
|
120
|
-
* property.
|
|
121
|
-
* @returns {@link Boolean} returning `true` if the `descriptor` object
|
|
122
|
-
* has any keys that match the {@link Descriptor.ACCESSOR_KEYS} array,
|
|
123
|
-
* otherwise it returns `false`.
|
|
124
|
-
*/
|
|
125
|
-
static isAccessor(objectOrDescriptor: object, property: (string | number | symbol) | null): any;
|
|
126
|
-
/**
|
|
127
|
-
* The function checks if a given property or descriptor is a data property.
|
|
128
|
-
*
|
|
129
|
-
* @param {object} objectOrDescriptor - The `objectOrDescriptor` parameter
|
|
130
|
-
* can be either a descriptor object or a property name.
|
|
131
|
-
* @param {(string|number|symbol)?} property the property name you wish to
|
|
132
|
-
* check the validity as an accessor descriptor. Only expected if the
|
|
133
|
-
* `objectOrDescriptor` parameter is the object that would contain this
|
|
134
|
-
* property.
|
|
135
|
-
* @returns {@link Boolean} returning `true` if the `descriptor` object
|
|
136
|
-
* has any keys that match the {@link Descriptor.DATA_KEYS} array, otherwise
|
|
137
|
-
* it returns `false`.
|
|
138
|
-
*/
|
|
139
|
-
static isData(objectOrDescriptor: object, property: (string | number | symbol) | null): any;
|
|
140
|
-
/**
|
|
141
|
-
* A base descriptor (new for each read) that is both enumerable and
|
|
142
|
-
* configurable
|
|
143
|
-
*
|
|
144
|
-
* @returns `{ enumerable: true, configurable: true }`
|
|
145
|
-
*/
|
|
146
|
-
static get flexible(): {
|
|
147
|
-
enumerable: boolean;
|
|
148
|
-
configurable: boolean;
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* A base descriptor (new for each read) that is not enumerable but is
|
|
152
|
-
* configurable
|
|
153
|
-
*
|
|
154
|
-
* @returns `{ enumerable: false, configurable: true }`
|
|
155
|
-
*/
|
|
156
|
-
static get enigmatic(): {
|
|
157
|
-
enumerable: boolean;
|
|
158
|
-
configurable: boolean;
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* A base descriptor (new for each read) that is neither enumerable
|
|
162
|
-
* nor configurable.
|
|
163
|
-
*
|
|
164
|
-
* @returns `{ enumerable: false, configurable: false }`
|
|
165
|
-
*/
|
|
166
|
-
static get intrinsic(): {
|
|
167
|
-
enumerable: boolean;
|
|
168
|
-
configurable: boolean;
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* A base descriptor (new for each read) that is enumerable but
|
|
172
|
-
* not configurable
|
|
173
|
-
*
|
|
174
|
-
* @returns `{ enumerable: true, configurable: false }`
|
|
175
|
-
*/
|
|
176
|
-
static get transparent(): {
|
|
177
|
-
enumerable: boolean;
|
|
178
|
-
configurable: boolean;
|
|
179
|
-
};
|
|
180
|
-
/**
|
|
181
|
-
* The function returns an array of shared descriptor keys.
|
|
182
|
-
*
|
|
183
|
-
* @returns An array containing the strings 'configurable' and 'enumerable'.
|
|
184
|
-
*/
|
|
185
|
-
static get SHARED_KEYS(): string[];
|
|
186
|
-
/**
|
|
187
|
-
* The function returns an array of accessor descriptor keys.
|
|
188
|
-
*
|
|
189
|
-
* @returns An array containing the strings 'get' and 'set' is being returned.
|
|
190
|
-
*/
|
|
191
|
-
static get ACCESSOR_KEYS(): string[];
|
|
192
|
-
/**
|
|
193
|
-
* The function returns an array of data descriptor keys.
|
|
194
|
-
*
|
|
195
|
-
* @returns An array containing the strings 'value' and 'writable' is being
|
|
196
|
-
* returned.
|
|
197
|
-
*/
|
|
198
|
-
static get DATA_KEYS(): string[];
|
|
199
|
-
/**
|
|
200
|
-
* Constructs a Descriptor instance which wraps and manages an object
|
|
201
|
-
* property descriptor. The constructor can handle an existing descriptor
|
|
202
|
-
* object or create a new one based on an object and a property key.
|
|
203
|
-
*
|
|
204
|
-
* @param {object|Descriptor} object - The target object or an existing
|
|
205
|
-
* Descriptor instance. If it's an object, it is used in conjunction with
|
|
206
|
-
* `key` to create a descriptor. If it's a Descriptor instance, it is used
|
|
207
|
-
* directly as the descriptor.
|
|
208
|
-
* @param {string|symbol} [key] - The property key for which the descriptor
|
|
209
|
-
* is to be created. This parameter is ignored if `object` is a Descriptor
|
|
210
|
-
* instance. If `key` is an object and `object` is a valid descriptor, `key`
|
|
211
|
-
* is treated as the associated object.
|
|
212
|
-
* @throws {Error} Throws an error if the constructed descriptor is not
|
|
213
|
-
* valid.
|
|
214
|
-
*/
|
|
215
|
-
constructor(object: object | Descriptor, key?: string | symbol, ...args: any[]);
|
|
216
|
-
/**
|
|
217
|
-
* The default private descriptor value is that of `enigmatic`
|
|
218
|
-
*
|
|
219
|
-
* @private
|
|
220
|
-
* @type {object}
|
|
221
|
-
*/
|
|
222
|
-
private _desc;
|
|
223
|
-
/**
|
|
224
|
-
* An optionally associated object, usually the parent from which
|
|
225
|
-
* the descriptor was taken, or undefined if none was able to be
|
|
226
|
-
* derived.
|
|
227
|
-
*
|
|
228
|
-
* @type {object}
|
|
229
|
-
*/
|
|
230
|
-
_object: object;
|
|
231
|
-
/**
|
|
232
|
-
* Detects whether or not this instance is an accessor object descriptor
|
|
233
|
-
*
|
|
234
|
-
* @returns {boolean} true if this object has a getter or setter and is not
|
|
235
|
-
* a data descriptor
|
|
236
|
-
*/
|
|
237
|
-
get isAccessor(): boolean;
|
|
238
|
-
/**
|
|
239
|
-
* Detects whether or not this instance is an data object descriptor
|
|
240
|
-
*
|
|
241
|
-
* @returns {boolean} true if this object has a value property and is not
|
|
242
|
-
* an accessor descriptor
|
|
243
|
-
*/
|
|
244
|
-
get isData(): boolean;
|
|
245
|
-
/**
|
|
246
|
-
* Detects whether or not this instance is a valid object descriptor
|
|
247
|
-
*
|
|
248
|
-
* @returns {boolean} true if this descriptor store is a valid descriptor
|
|
249
|
-
*/
|
|
250
|
-
get isDescriptor(): boolean;
|
|
251
|
-
/**
|
|
252
|
-
* Retrieves the {@link get} function for this accessor and binds it to
|
|
253
|
-
* the object from which the descriptor was derived, if that value is set.
|
|
254
|
-
* Otherwise this method is identical to the {@link get} accessor.
|
|
255
|
-
*
|
|
256
|
-
* @returns {function} the getter if one is defined. If possible this
|
|
257
|
-
* getter will be bound the associated and previously set `object`.
|
|
258
|
-
*/
|
|
259
|
-
get boundGet(): Function;
|
|
260
|
-
/**
|
|
261
|
-
* Retrieves the {@link set} function for this accessor and binds it to
|
|
262
|
-
* the object from which the descriptor was derived, if that value is set.
|
|
263
|
-
* Otherwise this method is identical to the {@link set} accessor.
|
|
264
|
-
*
|
|
265
|
-
* @returns {function} the setter if one is defined. If possible this
|
|
266
|
-
* setter will be bound the associated and previously set `object`.
|
|
267
|
-
*/
|
|
268
|
-
get boundSet(): Function;
|
|
269
|
-
/**
|
|
270
|
-
* The function checks the descriptor's associated object has been set on this
|
|
271
|
-
* instance of `Descriptor`.
|
|
272
|
-
*
|
|
273
|
-
* @returns {boolean} `true` if the `object` property has been set,
|
|
274
|
-
* `false` otherwise
|
|
275
|
-
*/
|
|
276
|
-
get hasObject(): boolean;
|
|
277
|
-
/**
|
|
278
|
-
* Sets the descriptor's associated `object` value. This is usually the
|
|
279
|
-
* parent object from which the descriptor was derived.
|
|
280
|
-
*
|
|
281
|
-
* @param {object} value sets the object for which this descriptor is to
|
|
282
|
-
* be associated with.
|
|
283
|
-
*/
|
|
284
|
-
set object(value: object);
|
|
285
|
-
/**
|
|
286
|
-
* Returns the descriptor's associated `object` value. This is usually the
|
|
287
|
-
* parent object from which the descriptor was derived. If the value is preset
|
|
288
|
-
* it will be returned. Undefined will be returned otherwise
|
|
289
|
-
*
|
|
290
|
-
* @returns {object} the associated object for this descriptor or undefined
|
|
291
|
-
* if it has not yet been set.
|
|
292
|
-
*/
|
|
293
|
-
get object(): object;
|
|
294
|
-
/**
|
|
295
|
-
* Take the descriptor defined by this objects values and apply them to
|
|
296
|
-
* the specified object using the specified key.
|
|
297
|
-
*
|
|
298
|
-
* @param {object} object the object to apply this descriptor to
|
|
299
|
-
* @param {string|symbol} forKey the string or symbol for which this
|
|
300
|
-
* descriptor will abe applied
|
|
301
|
-
*/
|
|
302
|
-
applyTo(object: object, forKey: string | symbol, bindAccessors?: boolean): object;
|
|
303
|
-
/**
|
|
304
|
-
* Converts this Descriptor class instance into a basic object descriptor
|
|
305
|
-
* that is accepted by all the standard JavaScript runtime methods that
|
|
306
|
-
* deal with object descriptors.
|
|
307
|
-
*
|
|
308
|
-
* @param {boolean|object} bindAccessors if `true`, a non-fatal attempt to
|
|
309
|
-
* bind accessor getter and setter methods is made before returning the
|
|
310
|
-
* object. If `bindAccessors` is truthy and is also an object, this is the
|
|
311
|
-
* object the accessors will be bound to. If the value is falsy or if the
|
|
312
|
-
* descriptor instance represents a data descriptor, nothing happens.
|
|
313
|
-
* @returns {object} the object instance's basic object representation as
|
|
314
|
-
* a descriptor.
|
|
315
|
-
*/
|
|
316
|
-
toObject(bindAccessors?: boolean | object): object;
|
|
317
|
-
/**
|
|
318
|
-
* Converts this descriptor object into a base representation
|
|
319
|
-
*
|
|
320
|
-
* @param {string} hint one of `string`, `number` or default;
|
|
321
|
-
* @returns if the hint is 'string', then a string identifying the enum
|
|
322
|
-
* and its type is returned. `number` will always be NaN since it is incoret
|
|
323
|
-
*/
|
|
324
|
-
[Symbol.toPrimitive](hint: string): string | number | object | undefined;
|
|
325
|
-
/**
|
|
326
|
-
* Ensures that the constructor of this object instance's name
|
|
327
|
-
* is returned if the string tag for this instance is queried
|
|
328
|
-
*
|
|
329
|
-
* @returns {string} the name of the class
|
|
330
|
-
*/
|
|
331
|
-
get [Symbol.toStringTag](): string;
|
|
332
|
-
}
|
|
333
|
-
export const DescriptorExtensions: Extension;
|
|
334
|
-
import { Extension } from '@nejs/extension';
|