@nejs/basic-extensions 1.6.1 → 1.7.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/.esdoc.json +9 -0
- package/README.md +2025 -11
- package/bin/clean +6 -0
- package/dist/@nejs/basic-extensions.bundle.1.6.1.js +4 -0
- package/dist/@nejs/basic-extensions.bundle.1.6.1.js.map +7 -0
- package/dist/cjs/arrayextensions.js +1 -0
- package/dist/cjs/arrayextensions.js.map +1 -0
- package/dist/cjs/functionextensions.js +1 -0
- package/dist/cjs/functionextensions.js.map +1 -0
- package/dist/cjs/globals.js +2 -1
- package/dist/cjs/globals.js.map +1 -0
- package/dist/cjs/index.d.ts +10 -19
- package/dist/cjs/index.js +69 -76
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/mapextensions.d.ts +2 -0
- package/dist/cjs/mapextensions.js +30 -0
- package/dist/cjs/mapextensions.js.map +1 -0
- package/dist/cjs/newClasses/asyncIterable.d.ts +123 -0
- package/dist/cjs/{asyncIterable.js → newClasses/asyncIterable.js} +7 -4
- package/dist/cjs/newClasses/asyncIterable.js.map +1 -0
- package/dist/cjs/newClasses/descriptor.d.ts +401 -0
- package/dist/cjs/{descriptor.js → newClasses/descriptor.js} +150 -80
- package/dist/cjs/newClasses/descriptor.js.map +1 -0
- package/dist/cjs/newClasses/iterable.d.ts +125 -0
- package/dist/cjs/{iterable.js → newClasses/iterable.js} +36 -10
- package/dist/cjs/newClasses/iterable.js.map +1 -0
- package/dist/cjs/newClasses/refmap.d.ts +238 -0
- package/dist/cjs/newClasses/refmap.js +433 -0
- package/dist/cjs/newClasses/refmap.js.map +1 -0
- package/dist/cjs/newClasses/refset.d.ts +186 -0
- package/dist/cjs/{refset.js → newClasses/refset.js} +4 -2
- package/dist/cjs/newClasses/refset.js.map +1 -0
- package/dist/cjs/objectextensions.d.ts +7 -6
- package/dist/cjs/objectextensions.js +85 -43
- package/dist/cjs/objectextensions.js.map +1 -0
- package/dist/cjs/reflectextensions.js +16 -12
- package/dist/cjs/reflectextensions.js.map +1 -0
- package/dist/cjs/stringextensions.js +1 -0
- package/dist/cjs/stringextensions.js.map +1 -0
- package/dist/cjs/symbolextensions.js +3 -1
- package/dist/cjs/symbolextensions.js.map +1 -0
- package/dist/cjs/weakrefextensions.js +1 -0
- package/dist/cjs/weakrefextensions.js.map +1 -0
- package/dist/mjs/arrayextensions.js +1 -0
- package/dist/mjs/arrayextensions.js.map +1 -0
- package/dist/mjs/functionextensions.js +1 -0
- package/dist/mjs/functionextensions.js.map +1 -0
- package/dist/mjs/globals.js +2 -1
- package/dist/mjs/globals.js.map +1 -0
- package/dist/mjs/index.d.ts +10 -19
- package/dist/mjs/index.js +67 -60
- package/dist/mjs/index.js.map +1 -0
- package/dist/mjs/mapextensions.d.ts +2 -0
- package/dist/mjs/mapextensions.js +27 -0
- package/dist/mjs/mapextensions.js.map +1 -0
- package/dist/mjs/newClasses/asyncIterable.d.ts +123 -0
- package/dist/mjs/{asyncIterable.js → newClasses/asyncIterable.js} +106 -105
- package/dist/mjs/newClasses/asyncIterable.js.map +1 -0
- package/dist/mjs/newClasses/descriptor.d.ts +401 -0
- package/dist/mjs/{descriptor.js → newClasses/descriptor.js} +129 -67
- package/dist/mjs/newClasses/descriptor.js.map +1 -0
- package/dist/mjs/newClasses/iterable.d.ts +125 -0
- package/dist/mjs/newClasses/iterable.js +199 -0
- package/dist/mjs/newClasses/iterable.js.map +1 -0
- package/dist/mjs/newClasses/refmap.d.ts +238 -0
- package/dist/mjs/newClasses/refmap.js +417 -0
- package/dist/mjs/newClasses/refmap.js.map +1 -0
- package/dist/mjs/newClasses/refset.d.ts +186 -0
- package/dist/mjs/{refset.js → newClasses/refset.js} +3 -2
- package/dist/mjs/newClasses/refset.js.map +1 -0
- package/dist/mjs/objectextensions.d.ts +7 -6
- package/dist/mjs/objectextensions.js +84 -42
- package/dist/mjs/objectextensions.js.map +1 -0
- package/dist/mjs/reflectextensions.js +16 -12
- package/dist/mjs/reflectextensions.js.map +1 -0
- package/dist/mjs/stringextensions.js +1 -0
- package/dist/mjs/stringextensions.js.map +1 -0
- package/dist/mjs/symbolextensions.js +3 -1
- package/dist/mjs/symbolextensions.js.map +1 -0
- package/dist/mjs/weakrefextensions.js +1 -0
- package/dist/mjs/weakrefextensions.js.map +1 -0
- package/docs/assets/anchor.js +350 -0
- package/docs/assets/bass-addons.css +12 -0
- package/docs/assets/bass.css +544 -0
- package/docs/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
- package/docs/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
- package/docs/assets/fonts/LICENSE.txt +93 -0
- package/docs/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
- package/docs/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
- package/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
- package/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
- package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
- package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
- package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
- package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
- package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
- package/docs/assets/fonts/source-code-pro.css +23 -0
- package/docs/assets/github.css +123 -0
- package/docs/assets/site.js +168 -0
- package/docs/assets/split.css +15 -0
- package/docs/assets/split.js +782 -0
- package/docs/assets/style.css +147 -0
- package/docs/index.html +13060 -0
- package/jsdoc-config.json +31 -0
- package/package.json +12 -3
- package/src/globals.js +1 -1
- package/src/index.js +75 -82
- package/src/mapextensions.js +30 -0
- package/src/{asyncIterable.js → newClasses/asyncIterable.js} +117 -117
- package/src/{descriptor.js → newClasses/descriptor.js} +137 -74
- package/src/newClasses/iterable.js +221 -0
- package/src/newClasses/refmap.js +483 -0
- package/src/{refset.js → newClasses/refset.js} +2 -2
- package/src/objectextensions.js +97 -46
- package/src/reflectextensions.js +16 -14
- package/src/symbolextensions.js +2 -1
- package/tests/index.test.js +1 -1
- package/tests/{asyncIterable.test.js → newClasses/asyncIterable.test.js} +3 -4
- package/tests/newClasses/descriptor.test.js +252 -0
- package/tests/{iterable.test.js → newClasses/iterable.test.js} +2 -4
- package/tests/newClasses/refmap.test.js +69 -0
- package/tests/{refset.test.js → newClasses/refset.test.js} +2 -4
- package/tests/objectextensions.test.js +128 -0
- package/tsconfig.base.json +2 -1
- package/dist/@nejs/basic-extensions.bundle.1.6.0.js +0 -2
- package/dist/@nejs/basic-extensions.bundle.1.6.0.js.map +0 -7
- package/dist/cjs/asyncIterable.d.ts +0 -3
- package/dist/cjs/descriptor.d.ts +0 -2
- package/dist/cjs/iterable.d.ts +0 -3
- package/dist/cjs/refset.d.ts +0 -2
- package/dist/mjs/asyncIterable.d.ts +0 -3
- package/dist/mjs/descriptor.d.ts +0 -2
- package/dist/mjs/iterable.d.ts +0 -3
- package/dist/mjs/iterable.js +0 -184
- package/dist/mjs/refset.d.ts +0 -2
- package/src/iterable.js +0 -203
|
@@ -10,17 +10,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var
|
|
13
|
+
var _Descriptor_desc, _Descriptor_object;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.DescriptorExtensions = void 0;
|
|
15
|
+
exports.DescriptorExtensions = exports.Descriptor = void 0;
|
|
16
16
|
const extension_1 = require("@nejs/extension");
|
|
17
|
-
const objectextensions_js_1 = require("
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const isValidKey = objectextensions_js_1.ObjectExtensions.patchEntries?.isValidKey?.computed;
|
|
22
|
-
const isString = stringextensions_js_1.StringExtensions.patchEntries?.isString?.computed;
|
|
23
|
-
const hasSome = reflectextensions_js_1.ReflectExtensions.patchEntries?.hasSome?.computed;
|
|
17
|
+
const objectextensions_js_1 = require("../objectextensions.js");
|
|
18
|
+
const reflectextensions_js_1 = require("../reflectextensions.js");
|
|
19
|
+
const { isObject, isValidKey } = objectextensions_js_1.ObjectExtensions.patches;
|
|
20
|
+
const { hasSome } = reflectextensions_js_1.ReflectExtensions.patches;
|
|
24
21
|
class Descriptor {
|
|
25
22
|
/**
|
|
26
23
|
* Creates a new instance of Descriptor either from another object or
|
|
@@ -32,7 +29,29 @@ class Descriptor {
|
|
|
32
29
|
* on the aforesupplied object.
|
|
33
30
|
*/
|
|
34
31
|
constructor(object, key) {
|
|
35
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The default private descriptor value is that of `enigmatic`
|
|
34
|
+
*
|
|
35
|
+
* @private
|
|
36
|
+
* @type {object}
|
|
37
|
+
*/
|
|
38
|
+
_Descriptor_desc.set(this, undefined
|
|
39
|
+
/**
|
|
40
|
+
* An optionally associated object, usually the parent from which
|
|
41
|
+
* the descriptor was taken, or undefined if none was able to be
|
|
42
|
+
* derived.
|
|
43
|
+
*
|
|
44
|
+
* @type {object}
|
|
45
|
+
*/
|
|
46
|
+
);
|
|
47
|
+
/**
|
|
48
|
+
* An optionally associated object, usually the parent from which
|
|
49
|
+
* the descriptor was taken, or undefined if none was able to be
|
|
50
|
+
* derived.
|
|
51
|
+
*
|
|
52
|
+
* @type {object}
|
|
53
|
+
*/
|
|
54
|
+
_Descriptor_object.set(this, undefined
|
|
36
55
|
/**
|
|
37
56
|
* Creates a new instance of Descriptor either from another object or
|
|
38
57
|
* around the supplied object descriptor value.
|
|
@@ -43,11 +62,19 @@ class Descriptor {
|
|
|
43
62
|
* on the aforesupplied object.
|
|
44
63
|
*/
|
|
45
64
|
);
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
if ((object ?? key) === undefined) {
|
|
66
|
+
__classPrivateFieldSet(this, _Descriptor_desc, Descriptor.enigmatic, "f");
|
|
67
|
+
}
|
|
68
|
+
if (Descriptor.isDescriptor(object)) {
|
|
69
|
+
__classPrivateFieldSet(this, _Descriptor_desc, object, "f");
|
|
70
|
+
__classPrivateFieldSet(this, _Descriptor_object, undefined, "f");
|
|
71
|
+
}
|
|
72
|
+
else if (isObject(object) && isValidKey(key)) {
|
|
48
73
|
__classPrivateFieldSet(this, _Descriptor_desc, Object.getOwnPropertyDescriptor(object, key), "f");
|
|
74
|
+
__classPrivateFieldSet(this, _Descriptor_object, object, "f");
|
|
49
75
|
}
|
|
50
76
|
if (!this.isDescriptor) {
|
|
77
|
+
console.error('Current descriptor:', __classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
51
78
|
throw new Error(`Not a valid descriptor:`, __classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
52
79
|
}
|
|
53
80
|
}
|
|
@@ -58,7 +85,7 @@ class Descriptor {
|
|
|
58
85
|
* a data descriptor
|
|
59
86
|
*/
|
|
60
87
|
get isAccessor() {
|
|
61
|
-
return
|
|
88
|
+
return Descriptor.isAccessor(__classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
62
89
|
}
|
|
63
90
|
/**
|
|
64
91
|
* Detects whether or not this instance is an data object descriptor
|
|
@@ -67,7 +94,7 @@ class Descriptor {
|
|
|
67
94
|
* an accessor descriptor
|
|
68
95
|
*/
|
|
69
96
|
get isData() {
|
|
70
|
-
return
|
|
97
|
+
return Descriptor.isData(__classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
71
98
|
}
|
|
72
99
|
/**
|
|
73
100
|
* Detects whether or not this instance is a valid object descriptor
|
|
@@ -75,7 +102,7 @@ class Descriptor {
|
|
|
75
102
|
* @returns {boolean} true if this descriptor store is a valid descriptor
|
|
76
103
|
*/
|
|
77
104
|
get isDescriptor() {
|
|
78
|
-
return
|
|
105
|
+
return Descriptor.isDescriptor(__classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
79
106
|
}
|
|
80
107
|
/**
|
|
81
108
|
* Getter around the `configurable` object descriptor property of
|
|
@@ -167,6 +194,17 @@ class Descriptor {
|
|
|
167
194
|
get get() {
|
|
168
195
|
return __classPrivateFieldGet(this, _Descriptor_desc, "f")?.get;
|
|
169
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Retrieves the {@link get} function for this accessor and binds it to
|
|
199
|
+
* the object from which the descriptor was derived, if that value is set.
|
|
200
|
+
* Otherwise this method is identical to the {@link get} accessor.
|
|
201
|
+
*
|
|
202
|
+
* @returns {function} the getter if one is defined. If possible this
|
|
203
|
+
* getter will be bound the associated and previously set `object`.
|
|
204
|
+
*/
|
|
205
|
+
get boundGet() {
|
|
206
|
+
return (isObject(__classPrivateFieldGet(this, _Descriptor_object, "f")) ? this.get?.bind(__classPrivateFieldGet(this, _Descriptor_object, "f")) : this.get);
|
|
207
|
+
}
|
|
170
208
|
/**
|
|
171
209
|
* Sets the `get` value of this object. If the internal descriptor
|
|
172
210
|
* store is invalid, the value is thrown away
|
|
@@ -185,7 +223,18 @@ class Descriptor {
|
|
|
185
223
|
* is undefined.
|
|
186
224
|
*/
|
|
187
225
|
get set() {
|
|
188
|
-
return __classPrivateFieldGet(this, _Descriptor_desc, "f")
|
|
226
|
+
return (__classPrivateFieldGet(this, _Descriptor_desc, "f") || {}).set;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Retrieves the {@link set} function for this accessor and binds it to
|
|
230
|
+
* the object from which the descriptor was derived, if that value is set.
|
|
231
|
+
* Otherwise this method is identical to the {@link set} accessor.
|
|
232
|
+
*
|
|
233
|
+
* @returns {function} the setter if one is defined. If possible this
|
|
234
|
+
* setter will be bound the associated and previously set `object`.
|
|
235
|
+
*/
|
|
236
|
+
get boundSet() {
|
|
237
|
+
return (isObject(__classPrivateFieldGet(this, _Descriptor_object, "f")) ? this.set?.bind(__classPrivateFieldGet(this, _Descriptor_object, "f")) : this.set);
|
|
189
238
|
}
|
|
190
239
|
/**
|
|
191
240
|
* Sets the `set` value of this object. If the internal descriptor
|
|
@@ -196,7 +245,50 @@ class Descriptor {
|
|
|
196
245
|
set set(value) {
|
|
197
246
|
(__classPrivateFieldGet(this, _Descriptor_desc, "f") || {}).set = value;
|
|
198
247
|
}
|
|
199
|
-
|
|
248
|
+
/**
|
|
249
|
+
* The function checks the descriptor's associated object has been set on this
|
|
250
|
+
* instance of `Descriptor`.
|
|
251
|
+
*
|
|
252
|
+
* @returns {boolean} `true` if the `object` property has been set,
|
|
253
|
+
* `false` otherwise
|
|
254
|
+
*/
|
|
255
|
+
get hasObject() { return isObject(__classPrivateFieldGet(this, _Descriptor_object, "f")); }
|
|
256
|
+
/**
|
|
257
|
+
* Returns the descriptor's associated `object` value. This is usually the
|
|
258
|
+
* parent object from which the descriptor was derived. If the value is preset
|
|
259
|
+
* it will be returned. Undefined will be returned otherwise
|
|
260
|
+
*
|
|
261
|
+
* @returns {object} the associated object for this descriptor or undefined
|
|
262
|
+
* if it has not yet been set.
|
|
263
|
+
*/
|
|
264
|
+
get object() { return __classPrivateFieldGet(this, _Descriptor_object, "f"); }
|
|
265
|
+
/**
|
|
266
|
+
* Sets the descriptor's associated `object` value. This is usually the
|
|
267
|
+
* parent object from which the descriptor was derived.
|
|
268
|
+
*
|
|
269
|
+
* @param {object} value sets the object for which this descriptor is to
|
|
270
|
+
* be associated with.
|
|
271
|
+
*/
|
|
272
|
+
set object(value) { __classPrivateFieldSet(this, _Descriptor_object, Object(value), "f"); }
|
|
273
|
+
/**
|
|
274
|
+
* The function returns a string representation of a descriptor object with
|
|
275
|
+
* additional information about its type when used in the NodeJS repl.
|
|
276
|
+
*
|
|
277
|
+
* @param {number} depth - The `depth` parameter is used to specify the
|
|
278
|
+
* maximum depth to which nested objects and arrays will be formatted. If
|
|
279
|
+
* the depth is exceeded, the output will be truncated with ellipses.
|
|
280
|
+
* @param {object} options - The `options` parameter is an object that
|
|
281
|
+
* contains various configuration options for the `inspect` function.
|
|
282
|
+
* These options can be used to customize the output of the inspection.
|
|
283
|
+
* @param {function} inspect - The `inspect` parameter is a function that
|
|
284
|
+
* is used to convert an object into a string representation. It is
|
|
285
|
+
* typically used for debugging purposes or when displaying an object's
|
|
286
|
+
* properties.
|
|
287
|
+
* @returns a string that represents a descriptor. The string includes the
|
|
288
|
+
* type of the descriptor (either "Accessor" or "Data") and the result of
|
|
289
|
+
* inspecting the descriptor object using the provided options and depth.
|
|
290
|
+
*/
|
|
291
|
+
[(_Descriptor_desc = new WeakMap(), _Descriptor_object = new WeakMap(), Symbol.for('nodejs.util.inspect.custom'))](depth, options, inspect) {
|
|
200
292
|
const type = this.isAccessor ? ' (Accessor)' : this.isData ? ' (Data)' : '';
|
|
201
293
|
return `Descriptor${type} ${inspect(__classPrivateFieldGet(this, _Descriptor_desc, "f"), { ...options, depth })}`;
|
|
202
294
|
}
|
|
@@ -208,11 +300,13 @@ class Descriptor {
|
|
|
208
300
|
* object to return a descriptor for.
|
|
209
301
|
* @returns an object descriptor for the requested field or null
|
|
210
302
|
*/
|
|
211
|
-
static for(object, key) {
|
|
212
|
-
if (!isObject(object)
|
|
303
|
+
static for(object, key, wrap = false) {
|
|
304
|
+
if (!isObject(object) || !isValidKey(key) || !Reflect.has(object, key)) {
|
|
213
305
|
return null;
|
|
214
306
|
}
|
|
215
|
-
return
|
|
307
|
+
return (wrap
|
|
308
|
+
? new Descriptor(Object.getOwnPropertyDescriptor(object, key))
|
|
309
|
+
: Object.getOwnPropertyDescriptor(object, key));
|
|
216
310
|
}
|
|
217
311
|
/**
|
|
218
312
|
* Take the descriptor defined by this objects values and apply them to
|
|
@@ -270,26 +364,23 @@ class Descriptor {
|
|
|
270
364
|
* The function `getData` retrieves the value of a property from an object
|
|
271
365
|
* if it exists and is a data property.
|
|
272
366
|
*
|
|
273
|
-
* @param object - The "object" parameter is the object from which
|
|
274
|
-
* retrieve data.
|
|
275
|
-
* @param property - The `property` parameter is the name of
|
|
276
|
-
* you want to retrieve the data from.
|
|
367
|
+
* @param {object} object - The "object" parameter is the object from which
|
|
368
|
+
* we want to retrieve data.
|
|
369
|
+
* @param {string|symbol} property - The `property` parameter is the name of
|
|
370
|
+
* the property that you want to retrieve the data from.
|
|
277
371
|
* @returns either the value of the specified property if it exists and is
|
|
278
372
|
* a data property, or undefined if the property does not exist or is not
|
|
279
373
|
* a data property.
|
|
280
374
|
*/
|
|
281
375
|
static getData(object, property) {
|
|
282
|
-
if (!isObject(object) || !
|
|
283
|
-
return
|
|
376
|
+
if (!isObject(object) || !Reflect.has(object, property)) {
|
|
377
|
+
return undefined;
|
|
284
378
|
}
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
if (_a.isData(descriptor)) {
|
|
289
|
-
return descriptor.value;
|
|
290
|
-
}
|
|
379
|
+
const descriptor = Descriptor.for(object, property, true);
|
|
380
|
+
if (!descriptor.isData) {
|
|
381
|
+
return null;
|
|
291
382
|
}
|
|
292
|
-
return
|
|
383
|
+
return descriptor.value;
|
|
293
384
|
}
|
|
294
385
|
/**
|
|
295
386
|
* The function `getAccessor` checks if an object has a getter/setter accessor
|
|
@@ -307,35 +398,14 @@ class Descriptor {
|
|
|
307
398
|
* returns undefined.
|
|
308
399
|
*/
|
|
309
400
|
static getAccessor(object, property) {
|
|
310
|
-
if (!isObject(object))
|
|
401
|
+
if (!isObject(object) || !Reflect.has(object, property)) {
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
const descriptor = Descriptor.for(object, property, true);
|
|
405
|
+
if (!descriptor.isAccessor) {
|
|
311
406
|
return null;
|
|
312
|
-
const [GETTER, SETTER, OBJECT] = [0, 1, 2];
|
|
313
|
-
const results = [undefined, undefined, undefined];
|
|
314
|
-
const descriptors = this.all(object);
|
|
315
|
-
const isDescriptor = _a.isDescriptor(object);
|
|
316
|
-
if (descriptors.has(property) || isDescriptor) {
|
|
317
|
-
const descriptor = isDescriptor ? object : descriptors.get(property);
|
|
318
|
-
if (_a.isAccessor(descriptor)) {
|
|
319
|
-
results[OBJECT] = descriptors.object(property);
|
|
320
|
-
results[GETTER] = descriptor?.get;
|
|
321
|
-
results[SETTER] = descriptor?.set;
|
|
322
|
-
Object.assign(results, {
|
|
323
|
-
get() { this[GETTER].bind(this[OBJECT])(); },
|
|
324
|
-
set(value) { this[SETTER].bind(this[OBJECT])(value); },
|
|
325
|
-
get accessor() { return true; },
|
|
326
|
-
get descriptor() { return descriptor; },
|
|
327
|
-
get boundDescriptor() {
|
|
328
|
-
return {
|
|
329
|
-
...descriptor,
|
|
330
|
-
get: descriptor.get?.bind(object),
|
|
331
|
-
set: descriptor.set?.bind(object),
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
return results;
|
|
336
|
-
}
|
|
337
407
|
}
|
|
338
|
-
return
|
|
408
|
+
return descriptor.get.bind(object)();
|
|
339
409
|
}
|
|
340
410
|
/**
|
|
341
411
|
* The function returns an object with enumerable and configurable properties
|
|
@@ -373,7 +443,7 @@ class Descriptor {
|
|
|
373
443
|
* @returns an object with properties "get", "set", "enumerable", and
|
|
374
444
|
* "configurable".
|
|
375
445
|
*/
|
|
376
|
-
static accessor(getter, setter, { enumerable, configurable } =
|
|
446
|
+
static accessor(getter, setter, { enumerable, configurable } = Descriptor.base()) {
|
|
377
447
|
return {
|
|
378
448
|
get: getter,
|
|
379
449
|
set: setter,
|
|
@@ -395,7 +465,7 @@ class Descriptor {
|
|
|
395
465
|
* @returns an object with properties `value`, `enumerable`, `writable`, and
|
|
396
466
|
* `configurable`.
|
|
397
467
|
*/
|
|
398
|
-
static data(value, writable = true, { enumerable, configurable } =
|
|
468
|
+
static data(value, writable = true, { enumerable, configurable } = Descriptor.base()) {
|
|
399
469
|
return {
|
|
400
470
|
value,
|
|
401
471
|
enumerable,
|
|
@@ -404,8 +474,11 @@ class Descriptor {
|
|
|
404
474
|
};
|
|
405
475
|
}
|
|
406
476
|
/**
|
|
407
|
-
* The function checks if an object is a
|
|
408
|
-
* JavaScript.
|
|
477
|
+
* The function checks if an object is a likely an object descriptor in
|
|
478
|
+
* JavaScript. This is determined as an object with some of the known
|
|
479
|
+
* descriptor keys (e.g. enumerable, configurable, value, writable, get,
|
|
480
|
+
* or set). Technically, any object could serve as a descriptor but this
|
|
481
|
+
* function only returns true if known descriptor keys are found.
|
|
409
482
|
*
|
|
410
483
|
* @param object - The `object` parameter is the object that we want to
|
|
411
484
|
* check if it is a descriptor.
|
|
@@ -413,15 +486,17 @@ class Descriptor {
|
|
|
413
486
|
*/
|
|
414
487
|
static isDescriptor(object) {
|
|
415
488
|
const knownKeys = [
|
|
416
|
-
...
|
|
417
|
-
...
|
|
418
|
-
...
|
|
489
|
+
...Descriptor.SHARED_KEYS,
|
|
490
|
+
...Descriptor.ACCESSOR_KEYS,
|
|
491
|
+
...Descriptor.DATA_KEYS,
|
|
419
492
|
];
|
|
420
493
|
return hasSome(object, knownKeys);
|
|
421
494
|
}
|
|
422
495
|
/**
|
|
423
496
|
* The function checks if a given property or descriptor is a data property.
|
|
424
497
|
*
|
|
498
|
+
* brie
|
|
499
|
+
*
|
|
425
500
|
* @param descriptor_orProp - The `descriptor_orProp` parameter can be
|
|
426
501
|
* either a descriptor or a property name.
|
|
427
502
|
* @param object - The `object` parameter is the object that you want to
|
|
@@ -434,14 +509,11 @@ class Descriptor {
|
|
|
434
509
|
const needsDescriptor = (((typeof object_orProp === 'object') || object_orProp instanceof Object) &&
|
|
435
510
|
property instanceof String);
|
|
436
511
|
const descriptor = (needsDescriptor
|
|
437
|
-
?
|
|
512
|
+
? Descriptor.for(object_orProp, property)
|
|
438
513
|
: object_orProp);
|
|
439
|
-
const {
|
|
514
|
+
const { DATA_KEYS } = this;
|
|
440
515
|
let validData = false;
|
|
441
|
-
if (hasSome(descriptor,
|
|
442
|
-
validData = false;
|
|
443
|
-
}
|
|
444
|
-
else if (hasSome(descriptor, DATA_KEYS)) {
|
|
516
|
+
if (hasSome(descriptor, DATA_KEYS)) {
|
|
445
517
|
validData = true;
|
|
446
518
|
}
|
|
447
519
|
return validData;
|
|
@@ -462,14 +534,11 @@ class Descriptor {
|
|
|
462
534
|
((typeof object_orProp === 'object') || object_orProp instanceof Object) &&
|
|
463
535
|
(property instanceof String || (typeof property === 'symbol')));
|
|
464
536
|
const descriptor = (needsDescriptor
|
|
465
|
-
?
|
|
537
|
+
? Descriptor.for(object_orProp, property)
|
|
466
538
|
: object_orProp);
|
|
467
|
-
const { ACCESSOR_KEYS
|
|
539
|
+
const { ACCESSOR_KEYS } = this;
|
|
468
540
|
let validAccessor = false;
|
|
469
|
-
if (hasSome(descriptor,
|
|
470
|
-
validAccessor = false;
|
|
471
|
-
}
|
|
472
|
-
else if (hasSome(descriptor, ACCESSOR_KEYS)) {
|
|
541
|
+
if (hasSome(descriptor, ACCESSOR_KEYS)) {
|
|
473
542
|
validAccessor = true;
|
|
474
543
|
}
|
|
475
544
|
return validAccessor;
|
|
@@ -539,5 +608,6 @@ class Descriptor {
|
|
|
539
608
|
return ['value', 'writable'];
|
|
540
609
|
}
|
|
541
610
|
}
|
|
542
|
-
|
|
611
|
+
exports.Descriptor = Descriptor;
|
|
543
612
|
exports.DescriptorExtensions = new extension_1.Extension(Descriptor);
|
|
613
|
+
//# sourceMappingURL=descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor.js","sourceRoot":"","sources":["../../../src/newClasses/descriptor.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAA2C;AAC3C,gEAAyD;AACzD,kEAA2D;AA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;;;;OAIG;IACH,MAAM,KAAK,aAAa;QACtB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IACvB,CAAC;IAED;;;;;OAKG;IACH,MAAM,KAAK,SAAS;QAClB,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IAC9B,CAAC;CACF;AAxoBD,gCAwoBC;AAEY,QAAA,oBAAoB,GAAG,IAAI,qBAAS,CAAC,UAAU,CAAC,CAAA"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Iterable class is designed to provide a convenient way to create synchronous
|
|
3
|
+
* iterable objects. It can be initialized with either an array or individual elements.
|
|
4
|
+
* This class implements the iterable protocol, allowing instances to be used with
|
|
5
|
+
* `for...of` loops and other standard JavaScript iteration mechanisms.
|
|
6
|
+
*/
|
|
7
|
+
export class Iterable {
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a given value is an iterable. This method determines if the
|
|
10
|
+
* provided value has a `Symbol.iterator` property that is a generator
|
|
11
|
+
* function. It's a precise way to identify if the value conforms to the
|
|
12
|
+
* iterable protocol using a generator function.
|
|
13
|
+
*
|
|
14
|
+
* Note: This method specifically checks for generator functions. Some
|
|
15
|
+
* iterables might use regular functions that return an iterator, which
|
|
16
|
+
* this method won't identify.
|
|
17
|
+
*
|
|
18
|
+
* @param {*} value - The value to be checked for iterability.
|
|
19
|
+
* @returns {boolean} - Returns true if the value is an iterable implemented
|
|
20
|
+
* using a generator function, false otherwise.
|
|
21
|
+
*/
|
|
22
|
+
static isIterable(value: any): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Constructs an instance of Iterable. It can be initialized with either an
|
|
25
|
+
* iterable object (such as an array, Set, Map, string, or any object
|
|
26
|
+
* implementing the iterable protocol) or individual elements. If the first
|
|
27
|
+
* argument is an iterable, the class instance is initialized with the
|
|
28
|
+
* elements from the iterable, followed by any additional arguments. If the
|
|
29
|
+
* first argument is not an iterable, all arguments are treated as individual
|
|
30
|
+
* elements.
|
|
31
|
+
*
|
|
32
|
+
* @param {Iterable|*} elementsOrFirstElement - An iterable object or the
|
|
33
|
+
* first element.
|
|
34
|
+
* @param {...*} moreElements - Additional elements if the first argument is
|
|
35
|
+
* not an iterable.
|
|
36
|
+
*/
|
|
37
|
+
constructor(elementsOrFirstElement: Iterable | any, ...moreElements: any[]);
|
|
38
|
+
/**
|
|
39
|
+
* Provides access to the elements as a standard array. Useful for scenarios
|
|
40
|
+
* where array methods and behaviors are needed.
|
|
41
|
+
*
|
|
42
|
+
* @returns {Array} An array containing all the elements of the iterable.
|
|
43
|
+
*/
|
|
44
|
+
get asArray(): any[];
|
|
45
|
+
/**
|
|
46
|
+
* Implements the iterable protocol. When an instance of Iterable is used
|
|
47
|
+
* in a `for...of` loop or spread syntax, this generator function is invoked
|
|
48
|
+
* to yield the elements one by one in a synchronous manner.
|
|
49
|
+
*
|
|
50
|
+
* @returns {Generator} A generator that yields each element of the iterable.
|
|
51
|
+
*/
|
|
52
|
+
[Symbol.iterator](): Generator;
|
|
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 `Iterator` around any type of iterable
|
|
64
|
+
* object. This can be wrapped around any type of object that has a
|
|
65
|
+
* `[Symbol.iterator]` property assigned to a generator function.
|
|
66
|
+
*/
|
|
67
|
+
export class Iterator {
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new `Iterator` object instance.
|
|
70
|
+
*
|
|
71
|
+
* @param {object} iterable any object that has a `[Symbol.iterator]`
|
|
72
|
+
* property assigned to a generator function.
|
|
73
|
+
* @param {function} mapEach when provided `mapEach` is a callback that
|
|
74
|
+
* takes an entry as input and receives one as output.
|
|
75
|
+
*/
|
|
76
|
+
constructor(iterable: object, mapEach: Function);
|
|
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 `Array.from()`
|
|
83
|
+
*/
|
|
84
|
+
get asArray(): array;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the actual iterable object passed to the constructor that
|
|
87
|
+
* created this instance.
|
|
88
|
+
*
|
|
89
|
+
* @returns {object} the object containing the `[Symbol.iterator]`
|
|
90
|
+
*/
|
|
91
|
+
get iterable(): object;
|
|
92
|
+
/**
|
|
93
|
+
* The function retrieves the next value in the iterator. If the
|
|
94
|
+
* the iterator has run its course, `reset()` can be invoked to
|
|
95
|
+
* reset the pointer to the beginning of the iteration.
|
|
96
|
+
*
|
|
97
|
+
* @returns {any} the next value
|
|
98
|
+
*/
|
|
99
|
+
next(): any;
|
|
100
|
+
/**
|
|
101
|
+
* Resets the iterator to the beginning allowing it to be
|
|
102
|
+
* iterated over again.
|
|
103
|
+
*/
|
|
104
|
+
reset(): void;
|
|
105
|
+
/**
|
|
106
|
+
* The existence of this symbol on the object instances, indicates that
|
|
107
|
+
* it can be used in `for(.. of ..)` loops and its values can be
|
|
108
|
+
* extracted from calls to `Array.from()`
|
|
109
|
+
*
|
|
110
|
+
* @returns {Iterator} this is returned since this object is already
|
|
111
|
+
* conforming to the expected JavaScript Iterator interface
|
|
112
|
+
*/
|
|
113
|
+
[Symbol.iterator](): Iterator;
|
|
114
|
+
/**
|
|
115
|
+
* Ensures that the constructor of this object instance's name
|
|
116
|
+
* is returned if the string tag for this instance is queried
|
|
117
|
+
*
|
|
118
|
+
* @returns {string} the name of the class
|
|
119
|
+
*/
|
|
120
|
+
get [Symbol.toStringTag](): string;
|
|
121
|
+
#private;
|
|
122
|
+
}
|
|
123
|
+
export const IterableExtensions: Extension;
|
|
124
|
+
export const IteratorExtensions: Extension;
|
|
125
|
+
import { Extension } from '@nejs/extension';
|
|
@@ -10,9 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _Iterable_elements, _Iterator_iterable, _Iterator_iterator;
|
|
13
|
+
var _Iterable_elements, _Iterator_mapEach, _Iterator_iterable, _Iterator_iterator;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.IteratorExtensions = exports.IterableExtensions = void 0;
|
|
15
|
+
exports.IteratorExtensions = exports.IterableExtensions = exports.Iterator = exports.Iterable = void 0;
|
|
16
16
|
const extension_1 = require("@nejs/extension");
|
|
17
17
|
/**
|
|
18
18
|
* The Iterable class is designed to provide a convenient way to create synchronous
|
|
@@ -98,19 +98,38 @@ class Iterable {
|
|
|
98
98
|
return type === '[object GeneratorFunction]';
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
exports.Iterable = Iterable;
|
|
101
102
|
/**
|
|
102
103
|
* Being able to create a compliant `Iterator` around any type of iterable
|
|
103
104
|
* object. This can be wrapped around any type of object that has a
|
|
104
105
|
* `[Symbol.iterator]` property assigned to a generator function.
|
|
105
106
|
*/
|
|
106
|
-
|
|
107
|
+
class Iterator {
|
|
107
108
|
/**
|
|
108
109
|
* Creates a new `Iterator` object instance.
|
|
109
110
|
*
|
|
110
111
|
* @param {object} iterable any object that has a `[Symbol.iterator]`
|
|
111
112
|
* property assigned to a generator function.
|
|
113
|
+
* @param {function} mapEach when provided `mapEach` is a callback that
|
|
114
|
+
* takes an entry as input and receives one as output.
|
|
112
115
|
*/
|
|
113
|
-
constructor(iterable) {
|
|
116
|
+
constructor(iterable, mapEach) {
|
|
117
|
+
/**
|
|
118
|
+
* A private function that when provided has the following signature:
|
|
119
|
+
* `function mapEach(entry) -> entry`. This allows any changes to be made
|
|
120
|
+
* to each element, conditionally and programmatically, as needed before
|
|
121
|
+
* they are returned to the called code.
|
|
122
|
+
*/
|
|
123
|
+
_Iterator_mapEach.set(this, undefined
|
|
124
|
+
/**
|
|
125
|
+
* Creates a new `Iterator` object instance.
|
|
126
|
+
*
|
|
127
|
+
* @param {object} iterable any object that has a `[Symbol.iterator]`
|
|
128
|
+
* property assigned to a generator function.
|
|
129
|
+
* @param {function} mapEach when provided `mapEach` is a callback that
|
|
130
|
+
* takes an entry as input and receives one as output.
|
|
131
|
+
*/
|
|
132
|
+
);
|
|
114
133
|
/**
|
|
115
134
|
* The object from which its iterator functionality is derived.
|
|
116
135
|
*
|
|
@@ -131,6 +150,7 @@ Iterable.Iterator = class Iterator {
|
|
|
131
150
|
}
|
|
132
151
|
__classPrivateFieldSet(this, _Iterator_iterable, iterable, "f");
|
|
133
152
|
__classPrivateFieldSet(this, _Iterator_iterator, iterable[Symbol.iterator](), "f");
|
|
153
|
+
__classPrivateFieldSet(this, _Iterator_mapEach, typeof mapEach === 'function' ? mapEach : undefined, "f");
|
|
134
154
|
}
|
|
135
155
|
/**
|
|
136
156
|
* Returns a new `Array` derived from the iterable this object
|
|
@@ -159,12 +179,16 @@ Iterable.Iterator = class Iterator {
|
|
|
159
179
|
* @returns {any} the next value
|
|
160
180
|
*/
|
|
161
181
|
next() {
|
|
162
|
-
const
|
|
163
|
-
|
|
182
|
+
const input = __classPrivateFieldGet(this, _Iterator_iterator, "f").next();
|
|
183
|
+
let output = input;
|
|
184
|
+
if (output.done) {
|
|
164
185
|
return { value: undefined, done: true };
|
|
165
186
|
}
|
|
166
187
|
else {
|
|
167
|
-
|
|
188
|
+
if (__classPrivateFieldGet(this, _Iterator_mapEach, "f") && typeof __classPrivateFieldGet(this, _Iterator_mapEach, "f") === 'function') {
|
|
189
|
+
output.value = __classPrivateFieldGet(this, _Iterator_mapEach, "f").call(this, input.value);
|
|
190
|
+
}
|
|
191
|
+
return { value: output.value, done: false };
|
|
168
192
|
}
|
|
169
193
|
}
|
|
170
194
|
/**
|
|
@@ -182,7 +206,7 @@ Iterable.Iterator = class Iterator {
|
|
|
182
206
|
* @returns {Iterator} this is returned since this object is already
|
|
183
207
|
* conforming to the expected JavaScript Iterator interface
|
|
184
208
|
*/
|
|
185
|
-
[(_Iterator_iterable = new WeakMap(), _Iterator_iterator = new WeakMap(), Symbol.iterator)]() {
|
|
209
|
+
[(_Iterator_mapEach = new WeakMap(), _Iterator_iterable = new WeakMap(), _Iterator_iterator = new WeakMap(), Symbol.iterator)]() {
|
|
186
210
|
return this;
|
|
187
211
|
}
|
|
188
212
|
/**
|
|
@@ -194,6 +218,8 @@ Iterable.Iterator = class Iterator {
|
|
|
194
218
|
get [Symbol.toStringTag]() {
|
|
195
219
|
return this.constructor.name;
|
|
196
220
|
}
|
|
197
|
-
}
|
|
221
|
+
}
|
|
222
|
+
exports.Iterator = Iterator;
|
|
198
223
|
exports.IterableExtensions = new extension_1.Extension(Iterable);
|
|
199
|
-
exports.IteratorExtensions = new extension_1.Extension(
|
|
224
|
+
exports.IteratorExtensions = new extension_1.Extension(Iterator);
|
|
225
|
+
//# sourceMappingURL=iterable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterable.js","sourceRoot":"","sources":["../../../src/newClasses/iterable.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAA2C;AAE3C;;;;;GAKG;AACH,MAAa,QAAQ;IAOnB;;;;;;;;;;;;;OAaG;IACH,YAAY,sBAAsB,EAAE,GAAG,YAAY;QApBnD;;;WAGG;QACH,6BAAY,EAAE,EAAC;QAiBb,IACE,sBAAsB,IAAI,IAAI;YAC9B,OAAO,sBAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAU,EAC7D,CAAC;YACD,uBAAA,IAAI,sBAAa,CAAC,GAAG,sBAAsB,EAAE,GAAG,YAAY,CAAC,MA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