@nejs/basic-extensions 1.7.0 → 1.9.0
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/README.md +518 -103
- package/dist/@nejs/basic-extensions.bundle.1.8.0.js +4 -0
- package/dist/@nejs/basic-extensions.bundle.1.8.0.js.map +7 -0
- package/dist/cjs/functionextensions.d.ts +1 -0
- package/dist/cjs/functionextensions.js +128 -18
- package/dist/cjs/functionextensions.js.map +1 -1
- package/dist/cjs/index.d.ts +5 -2
- package/dist/cjs/index.js +28 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/newClasses/deferred.d.ts +126 -0
- package/dist/cjs/newClasses/deferred.js +306 -0
- package/dist/cjs/newClasses/deferred.js.map +1 -0
- package/dist/cjs/setextensions.d.ts +2 -0
- package/dist/cjs/setextensions.js +204 -0
- package/dist/cjs/setextensions.js.map +1 -0
- package/dist/mjs/functionextensions.d.ts +1 -0
- package/dist/mjs/functionextensions.js +127 -17
- package/dist/mjs/functionextensions.js.map +1 -1
- package/dist/mjs/index.d.ts +5 -2
- package/dist/mjs/index.js +29 -6
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/newClasses/deferred.d.ts +126 -0
- package/dist/mjs/newClasses/deferred.js +230 -0
- package/dist/mjs/newClasses/deferred.js.map +1 -0
- package/dist/mjs/setextensions.d.ts +2 -0
- package/dist/mjs/setextensions.js +201 -0
- package/dist/mjs/setextensions.js.map +1 -0
- package/docs/index.html +6119 -3461
- package/package.json +7 -4
- package/src/functionextensions.js +150 -24
- package/src/index.js +35 -6
- package/src/newClasses/deferred.js +253 -0
- package/src/setextensions.js +242 -0
- package/tests/newClasses/deferred.test.js +86 -0
- package/tests/setextensions.test.js +89 -0
- package/dist/@nejs/basic-extensions.bundle.1.6.1.js +0 -4
- package/dist/@nejs/basic-extensions.bundle.1.6.1.js.map +0 -7
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FunctionExtensions = void 0;
|
|
3
|
+
exports.FunctionPrototypeExtensions = exports.FunctionExtensions = void 0;
|
|
4
4
|
const extension_1 = require("@nejs/extension");
|
|
5
|
+
const objectextensions_js_1 = require("./objectextensions.js");
|
|
6
|
+
const { getStringTag } = objectextensions_js_1.ObjectExtensions.patches;
|
|
5
7
|
/**
|
|
6
8
|
* The `FunctionExtensions` class is a patch applied to the built-in JavaScript
|
|
7
9
|
* `Function` constructor. It extends `Function` with additional utility methods
|
|
@@ -12,6 +14,68 @@ const extension_1 = require("@nejs/extension");
|
|
|
12
14
|
* capabilities of function handling and introspection in JavaScript.
|
|
13
15
|
*/
|
|
14
16
|
exports.FunctionExtensions = new extension_1.Patch(Function, {
|
|
17
|
+
/**
|
|
18
|
+
* Determines if a given value is an asynchronous function. It checks if the
|
|
19
|
+
* value is an instance of `Function` and if its string representation
|
|
20
|
+
* includes the keyword 'Async'. This method is particularly useful for
|
|
21
|
+
* identifying async functions.
|
|
22
|
+
*
|
|
23
|
+
* @param {*} value - The value to be checked.
|
|
24
|
+
* @returns {boolean} Returns `true` if the value is an async function,
|
|
25
|
+
* otherwise `false`.
|
|
26
|
+
*/
|
|
27
|
+
isAsync(value) {
|
|
28
|
+
const stringTag = /(\w+)]/g.exec(Object.prototype.toString.call(value))[1];
|
|
29
|
+
return (value instanceof Function &&
|
|
30
|
+
stringTag.includes('Async'));
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* The function checks if a given value is an async generator function
|
|
34
|
+
*
|
|
35
|
+
* @param {any} value - The `value` parameter is the value that we want to
|
|
36
|
+
* check if it is a generator function.
|
|
37
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
38
|
+
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
|
|
39
|
+
*/
|
|
40
|
+
isAsyncGenerator(value) {
|
|
41
|
+
const stringTag = getStringTag(value);
|
|
42
|
+
return (value instanceof Function &&
|
|
43
|
+
stringTag == 'AsyncGeneratorFunction');
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Checks if a given value is an arrow function. It verifies if the value is
|
|
47
|
+
* an instance of `Function`, if its string representation includes the '=>'
|
|
48
|
+
* symbol, and if it lacks a prototype, which is a characteristic of arrow
|
|
49
|
+
* functions in JavaScript.
|
|
50
|
+
*
|
|
51
|
+
* @param {*} value - The value to be checked.
|
|
52
|
+
* @returns {boolean} Returns `true` if the value is an arrow function,
|
|
53
|
+
* otherwise `false`.
|
|
54
|
+
*/
|
|
55
|
+
isBigArrow(value) {
|
|
56
|
+
return (value instanceof Function &&
|
|
57
|
+
String(value).includes('=>') &&
|
|
58
|
+
!String(value).startsWith('bound') &&
|
|
59
|
+
!Reflect.has(value, 'prototype'));
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Determines if a given value is a bound function. Bound functions are
|
|
63
|
+
* created using the `Function.prototype.bind` method, which allows setting
|
|
64
|
+
* the `this` value at the time of binding. This method checks if the value
|
|
65
|
+
* is an instance of `Function`, if its string representation starts with
|
|
66
|
+
* 'bound', and if it lacks a `prototype` property. These characteristics
|
|
67
|
+
* are indicative of bound functions in JavaScript.
|
|
68
|
+
*
|
|
69
|
+
* @param {*} value - The value to be checked, typically a function.
|
|
70
|
+
* @returns {boolean} Returns `true` if the value is a bound function,
|
|
71
|
+
* otherwise `false`. Bound functions have a specific format in their
|
|
72
|
+
* string representation and do not have their own `prototype` property.
|
|
73
|
+
*/
|
|
74
|
+
isBound(value) {
|
|
75
|
+
return (value instanceof Function &&
|
|
76
|
+
String(value).startsWith('bound') &&
|
|
77
|
+
!Reflect.has(value, 'prototype'));
|
|
78
|
+
},
|
|
15
79
|
/**
|
|
16
80
|
* Determines if a given value is a class. It checks if the value is an
|
|
17
81
|
* instance of `Function` and if its string representation includes the
|
|
@@ -35,22 +99,43 @@ exports.FunctionExtensions = new extension_1.Patch(Function, {
|
|
|
35
99
|
* otherwise `false`.
|
|
36
100
|
*/
|
|
37
101
|
isFunction(value) {
|
|
38
|
-
return value instanceof Function;
|
|
102
|
+
return value instanceof Function && !Function.isClass(value);
|
|
39
103
|
},
|
|
104
|
+
/**
|
|
105
|
+
* The function checks if a given value is a generator function
|
|
106
|
+
*
|
|
107
|
+
* @param {any} value - The `value` parameter is the value that we want to
|
|
108
|
+
* check if it is a generator function.
|
|
109
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
110
|
+
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
|
|
111
|
+
*/
|
|
112
|
+
isGenerator(value) {
|
|
113
|
+
const stringTag = getStringTag(value);
|
|
114
|
+
return (value instanceof Function &&
|
|
115
|
+
stringTag == 'GeneratorFunction');
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
exports.FunctionPrototypeExtensions = new extension_1.Patch(Function.prototype, {
|
|
40
119
|
/**
|
|
41
120
|
* Determines if a given value is an asynchronous function. It checks if the
|
|
42
121
|
* value is an instance of `Function` and if its string representation
|
|
43
122
|
* includes the keyword 'Async'. This method is particularly useful for
|
|
44
123
|
* identifying async functions.
|
|
45
124
|
*
|
|
46
|
-
* @param {*} value - The value to be checked.
|
|
47
125
|
* @returns {boolean} Returns `true` if the value is an async function,
|
|
48
126
|
* otherwise `false`.
|
|
49
127
|
*/
|
|
50
|
-
isAsync(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
128
|
+
get isAsync() {
|
|
129
|
+
return Function.isAsync(this);
|
|
130
|
+
},
|
|
131
|
+
/**
|
|
132
|
+
* The function checks if a given value is an async generator function
|
|
133
|
+
*
|
|
134
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
135
|
+
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
|
|
136
|
+
*/
|
|
137
|
+
get isAsyncGenerator() {
|
|
138
|
+
return Function.isAsyncGenerator(this);
|
|
54
139
|
},
|
|
55
140
|
/**
|
|
56
141
|
* Checks if a given value is an arrow function. It verifies if the value is
|
|
@@ -58,15 +143,11 @@ exports.FunctionExtensions = new extension_1.Patch(Function, {
|
|
|
58
143
|
* symbol, and if it lacks a prototype, which is a characteristic of arrow
|
|
59
144
|
* functions in JavaScript.
|
|
60
145
|
*
|
|
61
|
-
* @param {*} value - The value to be checked.
|
|
62
146
|
* @returns {boolean} Returns `true` if the value is an arrow function,
|
|
63
147
|
* otherwise `false`.
|
|
64
148
|
*/
|
|
65
|
-
isBigArrow(
|
|
66
|
-
return (
|
|
67
|
-
String(value).includes('=>') &&
|
|
68
|
-
!String(value).startsWith('bound') &&
|
|
69
|
-
!Reflect.has(value, 'prototype'));
|
|
149
|
+
get isBigArrow() {
|
|
150
|
+
return Function.isBigArrow(this);
|
|
70
151
|
},
|
|
71
152
|
/**
|
|
72
153
|
* Determines if a given value is a bound function. Bound functions are
|
|
@@ -76,15 +157,44 @@ exports.FunctionExtensions = new extension_1.Patch(Function, {
|
|
|
76
157
|
* 'bound', and if it lacks a `prototype` property. These characteristics
|
|
77
158
|
* are indicative of bound functions in JavaScript.
|
|
78
159
|
*
|
|
79
|
-
* @param {*} value - The value to be checked, typically a function.
|
|
80
160
|
* @returns {boolean} Returns `true` if the value is a bound function,
|
|
81
161
|
* otherwise `false`. Bound functions have a specific format in their
|
|
82
162
|
* string representation and do not have their own `prototype` property.
|
|
83
163
|
*/
|
|
84
|
-
isBound(
|
|
85
|
-
return (
|
|
86
|
-
|
|
87
|
-
|
|
164
|
+
get isBound() {
|
|
165
|
+
return Function.isBound(this);
|
|
166
|
+
},
|
|
167
|
+
/**
|
|
168
|
+
* Determines if a given value is a class. It checks if the value is an
|
|
169
|
+
* instance of `Function` and if its string representation includes the
|
|
170
|
+
* keyword 'class'. This method is useful for distinguishing classes from
|
|
171
|
+
* other function types in JavaScript.
|
|
172
|
+
*
|
|
173
|
+
* @returns {boolean} Returns `true` if the value is a class, otherwise
|
|
174
|
+
* `false`.
|
|
175
|
+
*/
|
|
176
|
+
get isClass() {
|
|
177
|
+
return Function.isClass(this);
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Checks if a given value is a regular function. This method verifies if
|
|
181
|
+
* the value is an instance of `Function`, which includes regular functions,
|
|
182
|
+
* classes, and async functions but excludes arrow functions.
|
|
183
|
+
*
|
|
184
|
+
* @returns {boolean} Returns `true` if the value is a regular function,
|
|
185
|
+
* otherwise `false`.
|
|
186
|
+
*/
|
|
187
|
+
get isFunction() {
|
|
188
|
+
return Function.isFunction(this);
|
|
189
|
+
},
|
|
190
|
+
/**
|
|
191
|
+
* The function checks if a given value is a generator function
|
|
192
|
+
*
|
|
193
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
194
|
+
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
|
|
195
|
+
*/
|
|
196
|
+
get isGenerator() {
|
|
197
|
+
return Function.isGenerator(this);
|
|
88
198
|
},
|
|
89
199
|
});
|
|
90
200
|
//# sourceMappingURL=functionextensions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functionextensions.js","sourceRoot":"","sources":["../../src/functionextensions.js"],"names":[],"mappings":";;;AAAA,+CAAuC;
|
|
1
|
+
{"version":3,"file":"functionextensions.js","sourceRoot":"","sources":["../../src/functionextensions.js"],"names":[],"mappings":";;;AAAA,+CAAuC;AACvC,+DAAwD;AAExD,MAAM,EAAE,YAAY,EAAE,GAAG,sCAAgB,CAAC,OAAO,CAAA;AAEjD;;;;;;;;GAQG;AACU,QAAA,kBAAkB,GAAG,IAAI,iBAAK,CAAC,QAAQ,EAAE;IACpD;;;;;;;;;OASG;IACH,OAAO,CAAC,KAAK;QACX,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC1E,OAAO,CACL,KAAK,YAAY,QAAQ;YACzB,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAC5B,CAAA;IACH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AAI,iBAAK,CAAC,QAAQ,CAAC,SAAS,EAAE;IACvE;;;;;;;;OAQG;IACH,IAAI,OAAO;QACT,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;IAED;;;;;OAKG;IACH,IAAI,gBAAgB;QAClB,OAAO,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC;IAED;;;;;;;;OAQG;IACH,IAAI,UAAU;QACZ,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,IAAI,OAAO;QACT,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;IAED;;;;;;;;OAQG;IACH,IAAI,OAAO;QACT,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,UAAU;QACZ,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IAED;;;;;OAKG;IACH,IAAI,WAAW;QACb,OAAO,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;CACF,CAAC,CAAA"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ declare namespace results {
|
|
|
5
5
|
export { Patches as patches };
|
|
6
6
|
export { all };
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
export
|
|
8
|
+
export namespace Extensions {
|
|
9
|
+
export { GlobalFunctionsAndProps as global };
|
|
10
|
+
}
|
|
11
|
+
export const Patches: Map<any, any>;
|
|
10
12
|
export const Controls: {};
|
|
13
|
+
import { GlobalFunctionsAndProps } from './globals.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Controls = exports.Patches = exports.Extensions = exports.all = void 0;
|
|
|
4
4
|
const functionextensions_js_1 = require("./functionextensions.js");
|
|
5
5
|
const objectextensions_js_1 = require("./objectextensions.js");
|
|
6
6
|
const mapextensions_js_1 = require("./mapextensions.js");
|
|
7
|
+
const setextensions_js_1 = require("./setextensions.js");
|
|
7
8
|
const reflectextensions_js_1 = require("./reflectextensions.js");
|
|
8
9
|
const stringextensions_js_1 = require("./stringextensions.js");
|
|
9
10
|
const symbolextensions_js_1 = require("./symbolextensions.js");
|
|
@@ -12,28 +13,38 @@ const descriptor_js_1 = require("./newClasses/descriptor.js");
|
|
|
12
13
|
const globals_js_1 = require("./globals.js");
|
|
13
14
|
const refset_js_1 = require("./newClasses/refset.js");
|
|
14
15
|
const refmap_js_1 = require("./newClasses/refmap.js");
|
|
16
|
+
const deferred_js_1 = require("./newClasses/deferred.js");
|
|
15
17
|
const asyncIterable_js_1 = require("./newClasses/asyncIterable.js");
|
|
16
18
|
const iterable_js_1 = require("./newClasses/iterable.js");
|
|
17
|
-
const
|
|
19
|
+
const StaticPatches = [
|
|
18
20
|
[Object, objectextensions_js_1.ObjectExtensions],
|
|
19
21
|
[Function, functionextensions_js_1.FunctionExtensions],
|
|
20
22
|
[Reflect, reflectextensions_js_1.ReflectExtensions],
|
|
21
23
|
[String, stringextensions_js_1.StringExtensions],
|
|
22
24
|
[Symbol, symbolextensions_js_1.SymbolExtensions],
|
|
25
|
+
];
|
|
26
|
+
const InstancePatches = [
|
|
23
27
|
[Object.prototype, objectextensions_js_1.ObjectPrototypeExtensions],
|
|
28
|
+
[Function.prototype, functionextensions_js_1.FunctionPrototypeExtensions],
|
|
24
29
|
[Array.prototype, arrayextensions_js_1.ArrayPrototypeExtensions],
|
|
25
30
|
[Map.prototype, mapextensions_js_1.MapPrototypeExtensions],
|
|
26
|
-
[
|
|
31
|
+
[Set.prototype, setextensions_js_1.SetPrototypeExtensions],
|
|
32
|
+
];
|
|
33
|
+
const Patches = new Map([
|
|
34
|
+
...StaticPatches,
|
|
35
|
+
...InstancePatches,
|
|
27
36
|
]);
|
|
28
37
|
exports.Patches = Patches;
|
|
29
38
|
const Extensions = {
|
|
30
|
-
|
|
39
|
+
global: globals_js_1.GlobalFunctionsAndProps,
|
|
31
40
|
[asyncIterable_js_1.AsyncIterableExtensions.key]: asyncIterable_js_1.AsyncIterableExtensions,
|
|
32
41
|
[asyncIterable_js_1.AsyncIteratorExtensions.key]: asyncIterable_js_1.AsyncIteratorExtensions,
|
|
42
|
+
[deferred_js_1.DeferredExtension.key]: deferred_js_1.DeferredExtension,
|
|
43
|
+
[descriptor_js_1.DescriptorExtensions.key]: descriptor_js_1.DescriptorExtensions,
|
|
33
44
|
[iterable_js_1.IterableExtensions.key]: iterable_js_1.IterableExtensions,
|
|
34
45
|
[iterable_js_1.IteratorExtensions.key]: iterable_js_1.IteratorExtensions,
|
|
35
|
-
[refset_js_1.RefSetExtensions.key]: refset_js_1.RefSetExtensions,
|
|
36
46
|
[refmap_js_1.RefMapExtensions.key]: refmap_js_1.RefMapExtensions,
|
|
47
|
+
[refset_js_1.RefSetExtensions.key]: refset_js_1.RefSetExtensions,
|
|
37
48
|
};
|
|
38
49
|
exports.Extensions = Extensions;
|
|
39
50
|
const Controls = {};
|
|
@@ -46,16 +57,28 @@ Object.assign(Controls, {
|
|
|
46
57
|
enablePatches() {
|
|
47
58
|
Patches.forEach((extension) => { extension.apply(); });
|
|
48
59
|
},
|
|
60
|
+
enableStaticPatches(filter = (extension) => true) {
|
|
61
|
+
StaticPatches.filter(filter).forEach(extension => extension.apply());
|
|
62
|
+
},
|
|
63
|
+
enableInstancePatches(filter = (extension) => true) {
|
|
64
|
+
InstancePatches.filter(filter).forEach(extension => extension.apply());
|
|
65
|
+
},
|
|
49
66
|
enableExtensions() {
|
|
50
67
|
Object.values(Extensions).forEach((extension) => { extension.apply(); });
|
|
51
68
|
},
|
|
52
|
-
disableAll(
|
|
69
|
+
disableAll() {
|
|
53
70
|
Controls.disablePatches();
|
|
54
71
|
Controls.disableExtensions();
|
|
55
72
|
},
|
|
56
73
|
disablePatches() {
|
|
57
74
|
Patches.forEach((extension) => { extension.revert(); });
|
|
58
75
|
},
|
|
76
|
+
disableStaticPatches(filter = (extension) => true) {
|
|
77
|
+
StaticPatches.filter(filter).forEach(extension => extension.revert());
|
|
78
|
+
},
|
|
79
|
+
disableInstancePatches(filter = (extension) => true) {
|
|
80
|
+
InstancePatches.filter(filter).forEach(extension => extension.revert());
|
|
81
|
+
},
|
|
59
82
|
disableExtensions() {
|
|
60
83
|
Object.values(Extensions).forEach((extension) => { extension.revert(); });
|
|
61
84
|
},
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;AAAA,mEAAyF;AACzF,+DAAmF;AACnF,yDAA2D;AAC3D,yDAA2D;AAC3D,iEAA0D;AAC1D,+DAAwD;AACxD,+DAAwD;AACxD,6DAA+D;AAC/D,8DAA6E;AAC7E,6CAAsD;AACtD,sDAAyD;AACzD,sDAAyD;AACzD,0DAA4D;AAE5D,oEAGsC;AAEtC,0DAGiC;AAEjC,MAAM,aAAa,GAAG;IACpB,CAAC,MAAM,EAAE,sCAAgB,CAAC;IAC1B,CAAC,QAAQ,EAAE,0CAAkB,CAAC;IAC9B,CAAC,OAAO,EAAE,wCAAiB,CAAC;IAC5B,CAAC,MAAM,EAAE,sCAAgB,CAAC;IAC1B,CAAC,MAAM,EAAE,sCAAgB,CAAC;CAC3B,CAAA;AAED,MAAM,eAAe,GAAG;IACtB,CAAC,MAAM,CAAC,SAAS,EAAE,+CAAyB,CAAC;IAC7C,CAAC,QAAQ,CAAC,SAAS,EAAE,mDAA2B,CAAC;IACjD,CAAC,KAAK,CAAC,SAAS,EAAE,6CAAwB,CAAC;IAC3C,CAAC,GAAG,CAAC,SAAS,EAAE,yCAAsB,CAAC;IACvC,CAAC,GAAG,CAAC,SAAS,E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AAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/B,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KACzC,CAAA;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE;QACxD,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;YACxD,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;YAEzC,IAAI,KAAK,CAAC,UAAU;gBAClB,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,0BAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;;gBAEnD,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAA;YAEnC,OAAO,WAAW,CAAA;QACpB,CAAC,EAAE,WAAW,CAAC,CAAA;QAEf,OAAO,WAAW,CAAA;IACpB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,IAAI,CAAA;AACb,CAAC,CAAC,EAAE,CAAA;AAEJ,MAAM,OAAO,GAAG;IACd,GAAG,QAAQ;IACX,UAAU,EAAE,UAAU;IACtB,OAAO,EAAE,OAAO;IAChB,GAAG,EAAH,WAAG;CACJ,CAAA;AAED,kBAAe,OAAO,CAAA"}
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
* Accessor for the promise managed by this Deferred instance.
|
|
95
|
+
*
|
|
96
|
+
* This getter provides access to the internal promise which is controlled
|
|
97
|
+
* by the Deferred's resolve and reject methods. It allows external code to
|
|
98
|
+
* attach callbacks for the resolution or rejection of the Deferred without
|
|
99
|
+
* the ability to directly resolve or reject it.
|
|
100
|
+
*
|
|
101
|
+
* @returns {Promise} The promise controlled by this Deferred instance.
|
|
102
|
+
*/
|
|
103
|
+
get promise(): Promise<any>;
|
|
104
|
+
/**
|
|
105
|
+
* Resolves the Deferred with the given value. If the value is a thenable
|
|
106
|
+
* (i.e., has a "then" method), the Deferred will "follow" that thenable,
|
|
107
|
+
* adopting its eventual state; otherwise, the Deferred will be fulfilled
|
|
108
|
+
* with the value. This function behaves the same as Promise.resolve.
|
|
109
|
+
*
|
|
110
|
+
* @param {*} value - The value to resolve the Deferred with.
|
|
111
|
+
* @returns {Promise} A Promise that is resolved with the given value.
|
|
112
|
+
*/
|
|
113
|
+
resolve(value: any): Promise<any>;
|
|
114
|
+
/**
|
|
115
|
+
* Rejects the Deferred with the given reason. This function behaves the
|
|
116
|
+
* same as Promise.reject. The Deferred will be rejected with the provided
|
|
117
|
+
* reason.
|
|
118
|
+
*
|
|
119
|
+
* @param {*} reason - The reason to reject the Deferred with.
|
|
120
|
+
* @returns {Promise} A Promise that is rejected with the given reason.
|
|
121
|
+
*/
|
|
122
|
+
reject(reason: any): Promise<any>;
|
|
123
|
+
#private;
|
|
124
|
+
}
|
|
125
|
+
export const DeferredExtension: Extension;
|
|
126
|
+
import { Extension } from '@nejs/extension';
|