@nejs/basic-extensions 2.21.5 → 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/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 +26 -26
- package/src/classes/enumeration.js +466 -0
- package/src/classes/index.js +5 -1
- package/src/index.js +3 -1
- 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.5.js +0 -25
- package/dist/@nejs/basic-extensions.bundle.2.21.5.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 -273
- 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 -228
- 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/math.extension.d.ts +0 -14
- package/dist/cjs/math.extension.js +0 -71
- package/dist/cjs/math.extension.js.map +0 -1
- package/dist/cjs/number.extension.d.ts +0 -44
- package/dist/cjs/number.extension.js +0 -278
- 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 -270
- 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 -206
- 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/math.extension.d.ts +0 -14
- package/dist/mjs/math.extension.js +0 -68
- package/dist/mjs/math.extension.js.map +0 -1
- package/dist/mjs/number.extension.d.ts +0 -44
- package/dist/mjs/number.extension.js +0 -275
- 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,421 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RefMapExtensions = exports.RefMap = void 0;
|
|
4
|
-
const extension_1 = require("@nejs/extension");
|
|
5
|
-
const object_extensions_js_1 = require("../object.extensions.js");
|
|
6
|
-
const symbol_extensions_js_1 = require("../symbol.extensions.js");
|
|
7
|
-
const weakref_extensions_js_1 = require("../weakref.extensions.js");
|
|
8
|
-
const iterable_js_1 = require("./iterable.js");
|
|
9
|
-
const { isObject, isNullDefined, isValidKey } = object_extensions_js_1.ObjectExtensions.patches;
|
|
10
|
-
const { isRegistered } = symbol_extensions_js_1.SymbolExtensions.patches;
|
|
11
|
-
const { isValidReference } = weakref_extensions_js_1.WeakRefExtensions.patches;
|
|
12
|
-
/**
|
|
13
|
-
* RefMap class extends the standard Map object to manage a collection of
|
|
14
|
-
* WeakRef values mapped to strong keys. It provides additional functionality
|
|
15
|
-
* such as objectification of values and various utility methods.
|
|
16
|
-
*
|
|
17
|
-
* Unlike standard Maps or Objects, RefMap stores weak references to objects,
|
|
18
|
-
* allowing them to be garbage-collected if there are no other references to
|
|
19
|
-
* them. This behavior is different from Maps and standard Objects, which
|
|
20
|
-
* maintain strong references to their elements.
|
|
21
|
-
*
|
|
22
|
-
* @extends Map
|
|
23
|
-
*/
|
|
24
|
-
class RefMap extends Map {
|
|
25
|
-
/**
|
|
26
|
-
* Private field to track whether the RefMap should objectify primitive
|
|
27
|
-
* values.
|
|
28
|
-
*
|
|
29
|
-
* @private
|
|
30
|
-
*/
|
|
31
|
-
#objectifyValues = false;
|
|
32
|
-
constructor(...args) {
|
|
33
|
-
super(...args);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Method to control whether the RefMap should objectify its values. When
|
|
37
|
-
* objectifying, primitive values (number, string, boolean, bigint) are
|
|
38
|
-
* converted to their respective object types, which allows them to be used as
|
|
39
|
-
* WeakRef targets.
|
|
40
|
-
*
|
|
41
|
-
* @param {boolean} setObjectification - Flag to enable or disable
|
|
42
|
-
* objectification.
|
|
43
|
-
* @returns {RefMap} - The current RefMap instance to allow method chaining.
|
|
44
|
-
*/
|
|
45
|
-
objectifying(setObjectification = true) {
|
|
46
|
-
this.objectifyValues = setObjectification;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* The function converts a JavaScript Map object into a regular JavaScript
|
|
51
|
-
* object, handling invalid keys by converting them to strings.
|
|
52
|
-
*
|
|
53
|
-
* @returns {object} an object; keys that are not either a `String` or a
|
|
54
|
-
* `Symbol` will be converted to a string.
|
|
55
|
-
*/
|
|
56
|
-
asObject() {
|
|
57
|
-
const object = {};
|
|
58
|
-
for (const [key, value] of this) {
|
|
59
|
-
const useKey = isValidKey(key) ? key : String(key);
|
|
60
|
-
const useValue = value?.valueOf() || value;
|
|
61
|
-
object[useKey] = useValue;
|
|
62
|
-
}
|
|
63
|
-
return object;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Returns the state indicating whether or not `RefMap` will attempt to
|
|
67
|
-
* convert non-valid primitives into targets that are valid input for
|
|
68
|
-
* new `WeakRef` object instances. If this value is `false` then no
|
|
69
|
-
* *objectification* will occur.
|
|
70
|
-
*
|
|
71
|
-
* @returns {boolean} The current state of objectifyValues.
|
|
72
|
-
*/
|
|
73
|
-
get objectifyValues() {
|
|
74
|
-
return this.#objectifyValues;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* The `get` function retrieves a value from a map and returns it, or returns a
|
|
78
|
-
* default value if the value is null or undefined. The actual retrieved value
|
|
79
|
-
* is a dereferenced `WeakRef`. If the result is `undefined` and this is not the
|
|
80
|
-
* expected response, it is likely the value has been garbage collected.
|
|
81
|
-
*
|
|
82
|
-
* @param {any} key - The key parameter is the key of the value you want to
|
|
83
|
-
* retrieve from the data structure.
|
|
84
|
-
* @param {any} defaultValue - The `defaultValue` parameter is the value that
|
|
85
|
-
* will be returned if the key does not exist in the map or if the value
|
|
86
|
-
* associated with the key has been garbage collected (i.e., it no longer
|
|
87
|
-
* exists).
|
|
88
|
-
* @returns The method is returning the value associated with the given key.
|
|
89
|
-
* If the value is not found or if it has been garbage collected (deref()
|
|
90
|
-
* returns null), then the defaultValue is returned.
|
|
91
|
-
*/
|
|
92
|
-
get(key, defaultValue) {
|
|
93
|
-
const value = super.get(key);
|
|
94
|
-
if (!value || !value?.deref()) {
|
|
95
|
-
return defaultValue;
|
|
96
|
-
}
|
|
97
|
-
return value?.deref();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Setting this value to true, will cause all set values to the Map to
|
|
101
|
-
* be analyzed for validity as a candidate to be wrapped in a `WeakRef`
|
|
102
|
-
* object. If true, and if possible, the object will be turned into an
|
|
103
|
-
* `Object` variant first.
|
|
104
|
-
*
|
|
105
|
-
* @param {boolean} value - The new state to set for objectifyValues.
|
|
106
|
-
*/
|
|
107
|
-
set objectifyValues(value) {
|
|
108
|
-
this.#objectifyValues = !!value;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Overrides the set method of `Map`. Adds a value to the `RefMap`,
|
|
112
|
-
* converting it to a `WeakRef`. Throws an error if the value is not a
|
|
113
|
-
* valid `WeakRef` target (e.g., `null`, `undefined`, or a registered
|
|
114
|
-
* `symbol`). If {@link objectifyValues} is enabled, an attempt to convert
|
|
115
|
-
* primitives to their object variants will be made. These are `numbers`,
|
|
116
|
-
* `strings`, `boolean` values and `bigint`s.
|
|
117
|
-
*
|
|
118
|
-
* @param {*} key - The `key` to be set on the `RefMap`
|
|
119
|
-
* @param {*} value - The value to be associated with the `key`
|
|
120
|
-
* @throws {TypeError} If the value is not a valid WeakRef target.
|
|
121
|
-
*/
|
|
122
|
-
set(key, value) {
|
|
123
|
-
let useValue = value;
|
|
124
|
-
// Objectify the value if needed
|
|
125
|
-
if (this.#objectifyValues && (typeof useValue === 'number' ||
|
|
126
|
-
typeof useValue === 'string' ||
|
|
127
|
-
typeof useValue === 'boolean' ||
|
|
128
|
-
typeof useValue === 'bigint')) {
|
|
129
|
-
useValue = Object(useValue);
|
|
130
|
-
}
|
|
131
|
-
// Check if the value is an object, and if it's a symbol, ensure it's not registered
|
|
132
|
-
if (typeof useValue === 'symbol' && Symbol.keyFor(useValue) !== undefined) {
|
|
133
|
-
throw new TypeError('RefMap cannot accept registered symbols as values');
|
|
134
|
-
}
|
|
135
|
-
if (typeof useValue !== 'object' && typeof useValue !== 'symbol') {
|
|
136
|
-
throw new TypeError('RefMap values must be objects, non-registered symbols, or objectified primitives');
|
|
137
|
-
}
|
|
138
|
-
// If the value is null or undefined, throw an error
|
|
139
|
-
if (useValue === null || useValue === undefined) {
|
|
140
|
-
throw new TypeError('RefMap values cannot be null or undefined');
|
|
141
|
-
}
|
|
142
|
-
const ref = new WeakRef(useValue);
|
|
143
|
-
super.set(key, ref);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Sets multiple values at a single time. The format is an array of array
|
|
147
|
-
* or rather an array of {@link Object.entries} (for example,
|
|
148
|
-
* `[[key1,value1], [key2,value2]]`). For each entry pair, if the length
|
|
149
|
-
* is not 2, either missing a key or value, it will be skipped.
|
|
150
|
-
*
|
|
151
|
-
* @param {Iterable} values - An iterable of values to add to the RefMap.
|
|
152
|
-
* @throws {TypeError} If the supplied values are falsey or non-iterable.
|
|
153
|
-
* @returns {RepMap} returns `this` to allow for chaining
|
|
154
|
-
*/
|
|
155
|
-
setAll(entries) {
|
|
156
|
-
if (!iterable_js_1.Iterable.isIterable(entries)) {
|
|
157
|
-
throw new TypeError('The supplied list of entries must be an array of arrays in the ' +
|
|
158
|
-
'format [[key1, value1], [key2, value2], ...].');
|
|
159
|
-
}
|
|
160
|
-
const forEach = entry => {
|
|
161
|
-
const [key, value] = entry;
|
|
162
|
-
if (!key || !isObject(value) || !isRegistered(value)) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
this.set(key, value);
|
|
166
|
-
};
|
|
167
|
-
for (const entry of entries) {
|
|
168
|
-
forEach(entry);
|
|
169
|
-
}
|
|
170
|
-
return this;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Removes all elements from the RefMap that have been garbage collected
|
|
174
|
-
* (i.e., their WeakRef no longer points to an object).
|
|
175
|
-
*
|
|
176
|
-
* @returns {RefMap} - The current RefMap instance to allow method chaining.
|
|
177
|
-
*/
|
|
178
|
-
clean() {
|
|
179
|
-
for (const [key, dereferenced] of this) {
|
|
180
|
-
if (!dereferenced) {
|
|
181
|
-
this.delete(key);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return this;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Executes a provided function once for each value in the RefMap. The callback
|
|
188
|
-
* function receives the dereferenced value, the value again (as RefMap doesn't
|
|
189
|
-
* use keys), and the RefMap itself. This method provides a way to iterate over
|
|
190
|
-
* and apply operations to the values stored in the RefMap, taking into account
|
|
191
|
-
* that they are weak references and may have been garbage-collected.
|
|
192
|
-
*
|
|
193
|
-
* @param {Function} forEachFn - Function to execute for each element. It
|
|
194
|
-
* takes three arguments: element, element (again, as RefMap has no key), and
|
|
195
|
-
* the RefMap itself.
|
|
196
|
-
* @param {*} thisArg - Value to use as `this` when executing `forEachFn`.
|
|
197
|
-
*/
|
|
198
|
-
entries() {
|
|
199
|
-
const entriesIterator = super.entries();
|
|
200
|
-
const refIterator = new iterable_js_1.Iterator(entriesIterator, (entry) => {
|
|
201
|
-
if (entry) {
|
|
202
|
-
const [key, ref] = entry;
|
|
203
|
-
const value = ref?.deref();
|
|
204
|
-
return [key, value];
|
|
205
|
-
}
|
|
206
|
-
return entry;
|
|
207
|
-
});
|
|
208
|
-
return refIterator;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Iterate over the items in the map and pass them to the supplied
|
|
212
|
-
* function ala `Map.prototype.forEach`. Note however, there are no
|
|
213
|
-
* indexes on Maps and as such, the index parameter of the callback
|
|
214
|
-
* will always be the value's key. Subsequently the `array` or third
|
|
215
|
-
* parameter will receive the map instance rather than an array.
|
|
216
|
-
*
|
|
217
|
-
* @param {function} forEachFn the function to use for each element in
|
|
218
|
-
* the set.
|
|
219
|
-
* @param {object} thisArg the `this` argument to be applied to each
|
|
220
|
-
* invocation of the `forEachFn` callback. Note, this value is unable
|
|
221
|
-
* to be applied if the `forEachFn` is a big arrow function
|
|
222
|
-
*/
|
|
223
|
-
forEach(forEachFn, thisArg) {
|
|
224
|
-
for (const [key, ref] of super.entries()) {
|
|
225
|
-
const value = ref?.deref();
|
|
226
|
-
if (!value) {
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
forEachFn.call(thisArg, value, key, this);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Returns an iterator for the values in the RefMap. Each value is
|
|
234
|
-
* dereferenced from its WeakRef before being returned. This method allows
|
|
235
|
-
* iterating over he set's values, similar to how one would iterate over
|
|
236
|
-
* values in a standard Map or Array, but with the understanding that the
|
|
237
|
-
* values are weakly referenced and may no longer exist (in which case
|
|
238
|
-
* they are skipped).
|
|
239
|
-
*
|
|
240
|
-
* @returns {Iterator} An iterator for the values.
|
|
241
|
-
*/
|
|
242
|
-
values() {
|
|
243
|
-
return new iterable_js_1.Iterator(super.values(), function perItem(value) {
|
|
244
|
-
const dereferenced = value?.deref();
|
|
245
|
-
return dereferenced || value;
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Determines whether an element with the specified value exists in the
|
|
250
|
-
* `RefMap`. For non-objectified sets, this method checks if the dereferenced
|
|
251
|
-
* values of the map include the specified value.
|
|
252
|
-
*
|
|
253
|
-
* For objectified sets, strict is set to false which uses loose
|
|
254
|
-
* equality to allow for things like `Object(5)` to equal `5`. This is important
|
|
255
|
-
* because otherwise primitives could not be weakly referenced. In the grand
|
|
256
|
-
* scheme of things, this is only useful if the objectified value is the
|
|
257
|
-
* one being referenced.
|
|
258
|
-
*
|
|
259
|
-
* @param {*} value - The value to check for presence in the RefMap.
|
|
260
|
-
* @param {boolean} strict - if `true`, the default, then the supplied value
|
|
261
|
-
* is hard compared to the dereferenced value (`===`). If `false`, then a
|
|
262
|
-
* loose comparison is used (`==`)
|
|
263
|
-
* @returns {boolean} - True if an element with the specified value exists
|
|
264
|
-
* in the RefMap, false otherwise.
|
|
265
|
-
*/
|
|
266
|
-
hasValue(value, strict = true) {
|
|
267
|
-
if (isNullDefined(value)) {
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
if (this.#objectifyValues) {
|
|
271
|
-
strict = false;
|
|
272
|
-
}
|
|
273
|
-
for (const [_, dereferenced] of this) {
|
|
274
|
-
if ((strict && value === dereferenced) ||
|
|
275
|
-
(!strict && value == dereferenced)) {
|
|
276
|
-
return true;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* The `filter` function filters the entries of a `RefMap` object based on
|
|
283
|
-
* a given filter function. The dereferenced entries of the values of the map
|
|
284
|
-
* will be passed to the function rather than a `WeakRef` itself.
|
|
285
|
-
*
|
|
286
|
-
* A new resulting entry set will be generated and a new `RefMap` will be made
|
|
287
|
-
* from these entries and returned. Note that this function never returns
|
|
288
|
-
* `null`
|
|
289
|
-
*
|
|
290
|
-
* @param {function} filterFn - The `filterFn` parameter is a function that
|
|
291
|
-
* will be used to filter the entries in the `RefMap`. It will be called with
|
|
292
|
-
* three arguments: the value of the current entry, the key of the current
|
|
293
|
-
* entry, and the `RefMap` itself. The function should return `true`
|
|
294
|
-
* @param {object} thisArg - The `thisArg` parameter is an optional argument
|
|
295
|
-
* that specifies the value to be used as `this` when executing the
|
|
296
|
-
* `filterFn` function. It allows you to explicitly set the context in which
|
|
297
|
-
* the `filterFn` function is called. If `thisArg` is not provided, `this
|
|
298
|
-
* @returns {array} The `filter` method is returning an array of filtered map
|
|
299
|
-
* entries
|
|
300
|
-
*/
|
|
301
|
-
filter(filterFn, thisArg) {
|
|
302
|
-
const resultingEntries = [];
|
|
303
|
-
for (const [key, dereferenced] of this) {
|
|
304
|
-
if (filterFn.call(thisArg, dereferenced, key, this)) {
|
|
305
|
-
resultingEntries.push([key, dereferenced]);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return resultingEntries;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* The `find` function iterates over a map and calls a given function on
|
|
312
|
-
* each value, returning the first value for which the function returns
|
|
313
|
-
* a truthy value.
|
|
314
|
-
*
|
|
315
|
-
* The function signature of `findFn` is
|
|
316
|
-
* ```
|
|
317
|
-
* function findFn(value, key, map)
|
|
318
|
-
* ```
|
|
319
|
-
* 'value' is passed to findFn up to two times; first with the `WeakRef`
|
|
320
|
-
* value, second with the result of {@link WeakRef.deref}. If `findFn`
|
|
321
|
-
* returns true for either of these the dereferenced value will be
|
|
322
|
-
* returned from the call to {@link RefMap.find}.
|
|
323
|
-
* `key` represents the key object that the value is mapped to.
|
|
324
|
-
* `map` is simply a reference to `this` map.
|
|
325
|
-
*
|
|
326
|
-
* @param findFn - `findFn` is a function that will be called for each
|
|
327
|
-
* element in the map. It takes three arguments: `ref`, `key`, and `map`;
|
|
328
|
-
* where `ref` is the value of the current element in the map, `key` is
|
|
329
|
-
* the key of the current element, and `map` is a reference to the instance
|
|
330
|
-
* being searched.
|
|
331
|
-
* @param thisArg - The `thisArg` parameter is the value to be used as
|
|
332
|
-
* the `this` value when executing the `findFn` function. It allows you
|
|
333
|
-
* to specify the context in which the `findFn` function should be called.
|
|
334
|
-
* @returns the first dereferenced value that satisfies the condition
|
|
335
|
-
* specified by the `findFn` function. If no value satisfies the condition,
|
|
336
|
-
* it returns `null`.
|
|
337
|
-
*/
|
|
338
|
-
find(findFn, thisArg) {
|
|
339
|
-
for (const [key, dereferenced] of this) {
|
|
340
|
-
const ref = super.get(key);
|
|
341
|
-
let result = findFn.call(thisArg, ref, key, map);
|
|
342
|
-
if (!result) {
|
|
343
|
-
result = findFn.call(thisArg, dereferenced, key, map);
|
|
344
|
-
}
|
|
345
|
-
if (result) {
|
|
346
|
-
return dereferenced;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Creates a new array or `RefMap` with the results of calling a provided
|
|
353
|
-
* function on every element in the calling `RefMap`. This method dereferences
|
|
354
|
-
* each value, applies the `mapFn`, and collects the results. If `toRefMap` is
|
|
355
|
-
* `true`, a new `RefMap` is returned; otherwise, an array. This method
|
|
356
|
-
* differs from `Array.map` in handling weak references and the potential to
|
|
357
|
-
* return a new `RefMap` instead of an array.
|
|
358
|
-
*
|
|
359
|
-
* @param {Function} mapFn - Function that produces an element of the new
|
|
360
|
-
* array or `RefMap`, taking three arguments.
|
|
361
|
-
* @param {*} thisArg - Value to use as this when executing mapFn.
|
|
362
|
-
* @param {boolean} toRefMap - Determines if the output should be a new
|
|
363
|
-
* `RefMap` (`true`) or an array (`false`).
|
|
364
|
-
* @param {boolean} mirrorObjectification - If `true` and `toRefMap` is
|
|
365
|
-
* `true`, the new `RefMap` mirrors the objectification setting of the
|
|
366
|
-
* original.
|
|
367
|
-
* @returns {Array|RefMap} - A new array or `RefMap` with each element being
|
|
368
|
-
* the result of the `mapFn`.
|
|
369
|
-
*/
|
|
370
|
-
map(mapFn, thisArg, toRefMap, mirrorObjectification) {
|
|
371
|
-
if (typeof mapFn !== 'function') {
|
|
372
|
-
throw new TypeError('mapFn must be a function! Received', mapFn);
|
|
373
|
-
}
|
|
374
|
-
const entries = [];
|
|
375
|
-
const errors = [];
|
|
376
|
-
let needsObjectification = mirrorObjectification && this.objectifyValues;
|
|
377
|
-
let detectNeed = mirrorObjectification === undefined;
|
|
378
|
-
let objectify = needsObjectification;
|
|
379
|
-
for (const [key, dereferenced] of this) {
|
|
380
|
-
const [, VALUE] = [0, 1];
|
|
381
|
-
const transformed = mapFn.call(thisArg, [key, dereferenced], key, this);
|
|
382
|
-
if (!isValidReference(transformed[VALUE])) {
|
|
383
|
-
if (isValidReference(Object(transformed[VALUE]))) {
|
|
384
|
-
needsObjectification = true;
|
|
385
|
-
if (detectNeed && !objectify) {
|
|
386
|
-
objectify = true;
|
|
387
|
-
transformed[VALUE] = Object(transformed[VALUE]);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
entries.push(transformed);
|
|
392
|
-
}
|
|
393
|
-
if (toRefMap) {
|
|
394
|
-
return new RefMap(entries).objectifying(objectify);
|
|
395
|
-
}
|
|
396
|
-
return entries;
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* The function returns an iterator that iterates over the entries of an object,
|
|
400
|
-
* dereferencing any weak references.
|
|
401
|
-
*
|
|
402
|
-
* @returns {Iterator} A new iterator object is being returned.
|
|
403
|
-
*/
|
|
404
|
-
*[Symbol.iterator]() {
|
|
405
|
-
for (const [key, ref] of this.entries()) {
|
|
406
|
-
yield [key, ref];
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* Ensures that the constructor of this object instance's name
|
|
411
|
-
* is returned if the string tag for this instance is queried
|
|
412
|
-
*
|
|
413
|
-
* @returns {string} the name of the class
|
|
414
|
-
*/
|
|
415
|
-
get [Symbol.toStringTag]() {
|
|
416
|
-
return this.constructor.name;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
exports.RefMap = RefMap;
|
|
420
|
-
exports.RefMapExtensions = new extension_1.Extension(RefMap);
|
|
421
|
-
//# sourceMappingURL=refmap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"refmap.js","sourceRoot":"","sources":["../../../src/classes/refmap.js"],"names":[],"mappings":";;;AAAA,+CAA2C;AAE3C,kEAA0D;AAC1D,kEAA0D;AAC1D,oEAA4D;AAE5D,+CAAkD;AAElD,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,uCAAgB,CAAC,OAAO,CAAA;AACxE,MAAM,EAAE,YAAY,EAAE,GAAG,uCAAgB,CAAC,OAAO,CAAA;AACjD,MAAM,EAAE,gBAAgB,EAAE,GAAG,yCAAiB,CAAC,OAAO,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,MAAa,MAAO,SAAQ,GAAG;IAC7B;;;;;OAKG;IACH,gBAAgB,GAAG,KAAK,CAAA;IAExB,YAAY,GAAG,IAAI;QACjB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;IAChB,CAAC;IAED;;;;;;;;;OASG;IACH,YAAY,CAAC,kBAAkB,GAAG,IAAI;QACpC,IAAI,CAAC,eAAe,GAAG,kBAAkB,CAAA;QACzC,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;;OAMG;IACH,QAAQ;QACN,MAAM,MAAM,GAAG,EAAE,CAAA;QAEjB,KAAK,MAAM,CAAC,GAAG,EAAE,KA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AA;oBAC3B,IAAI,UAAU,IAAI,CAAC,SAAS,EAAE,CAAC;wBAC7B,SAAS,GAAG,IAAI,CAAA;wBAChB,WAAW,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA;oBACjD,CAAC;gBACH,CAAC;YACH,CAAC;YAED,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QAC3B,CAAC;QAED,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;QACpD,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;;;;OAKG;IACH,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YACxC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAClB,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;CACF;AA1cD,wBA0cC;AAEY,QAAA,gBAAgB,GAAG,IAAI,qBAAS,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RefSet class extends the standard Set object to manage a collection of
|
|
3
|
-
* WeakRef objects. It provides additional functionality such as objectification
|
|
4
|
-
* of values and various utility methods.
|
|
5
|
-
*
|
|
6
|
-
* Unlike standard Sets or Arrays, RefSet stores weak references to objects,
|
|
7
|
-
* allowing them to be garbage-collected if there are no other references to
|
|
8
|
-
* them. This behavior is different from Arrays and standard Sets, which
|
|
9
|
-
* maintain strong references to their elements.
|
|
10
|
-
*
|
|
11
|
-
* @extends Set
|
|
12
|
-
*/
|
|
13
|
-
export class RefSet extends Set<any> {
|
|
14
|
-
constructor(values?: readonly any[] | null | undefined);
|
|
15
|
-
constructor(iterable?: Iterable<any> | null | undefined);
|
|
16
|
-
/**
|
|
17
|
-
* Method to control whether the RefSet should objectify its values. When
|
|
18
|
-
* objectifying, primitive values (number, string, boolean, bigint) are
|
|
19
|
-
* converted to their respective object types, which allows them to be used as
|
|
20
|
-
* WeakRef targets.
|
|
21
|
-
*
|
|
22
|
-
* @param {boolean} setObjectification - Flag to enable or disable
|
|
23
|
-
* objectification.
|
|
24
|
-
* @returns {RefSet} - The current RefSet instance to allow method chaining.
|
|
25
|
-
*/
|
|
26
|
-
objectifying(setObjectification?: boolean): RefSet;
|
|
27
|
-
/**
|
|
28
|
-
* Setting this value to true, will cause all added values to the Set to
|
|
29
|
-
* be analyzed for validity as a candidate to be wrapped in a `WeakRef`
|
|
30
|
-
* object. If true, and if possible, the object will be turned into an
|
|
31
|
-
* `Object` variant first. This will also enable less rigid variable
|
|
32
|
-
* comparison in the `.has()` method (i.e. `==` instead of `===`).
|
|
33
|
-
*
|
|
34
|
-
* @param {boolean} value - The new state to set for objectifyValues.
|
|
35
|
-
*/
|
|
36
|
-
set objectifyValues(value: boolean);
|
|
37
|
-
/**
|
|
38
|
-
* Returns the state indicating whether or not `RefSet` will attempt to
|
|
39
|
-
* convert non-valid primitives into targets that are valid input for
|
|
40
|
-
* new `WeakRef` object instances. If this value is `false` then no
|
|
41
|
-
* *objectification* will occur.
|
|
42
|
-
*
|
|
43
|
-
* @returns {boolean} The current state of objectifyValues.
|
|
44
|
-
*/
|
|
45
|
-
get objectifyValues(): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Overrides the add method of Set. Adds a value to the RefSet, converting it
|
|
48
|
-
* to a WeakRef. Throws an error if the value is not a valid WeakRef target
|
|
49
|
-
* (e.g., null, undefined, or a registered symbol). If `objectifyValues` is
|
|
50
|
-
* enabled, an attempt to convert primitives to their object variants will be
|
|
51
|
-
* made. These are numbers, strings, boolean values and big integers.
|
|
52
|
-
*
|
|
53
|
-
* @param {*} value - The value to be added to the RefSet.
|
|
54
|
-
* @throws {TypeError} If the value is not a valid WeakRef target.
|
|
55
|
-
*/
|
|
56
|
-
add(value: any): void;
|
|
57
|
-
/**
|
|
58
|
-
* Adds multiple values to the RefSet. The supplied `values` should be
|
|
59
|
-
* iterable and truthy. This function defers to `.add()` for its logic so
|
|
60
|
-
* each value from the supplied collection of values will also be subject
|
|
61
|
-
* to the criteria of that function.
|
|
62
|
-
*
|
|
63
|
-
* @param {Iterable} values - An iterable of values to add to the RefSet.
|
|
64
|
-
* @throws {TypeError} If the supplied values are falsey or non-iterable.
|
|
65
|
-
*/
|
|
66
|
-
addAll(values: Iterable<any>): void;
|
|
67
|
-
/**
|
|
68
|
-
* Removes all elements from the RefSet that have been garbage collected
|
|
69
|
-
* (i.e., their WeakRef no longer points to an object).
|
|
70
|
-
*
|
|
71
|
-
* @returns {RefSet} - The current RefSet instance to allow method chaining.
|
|
72
|
-
*/
|
|
73
|
-
clean(): RefSet;
|
|
74
|
-
/**
|
|
75
|
-
* Executes a provided function once for each value in the RefSet. The callback
|
|
76
|
-
* function receives the dereferenced value, the value again (as RefSet doesn't
|
|
77
|
-
* use keys), and the RefSet itself. This method provides a way to iterate over
|
|
78
|
-
* and apply operations to the values stored in the RefSet, taking into account
|
|
79
|
-
* that they are weak references and may have been garbage-collected.
|
|
80
|
-
*
|
|
81
|
-
* @param {Function} forEachFn - Function to execute for each element. It
|
|
82
|
-
* takes three arguments: element, element (again, as RefSet has no key), and
|
|
83
|
-
* the RefSet itself.
|
|
84
|
-
* @param {*} thisArg - Value to use as `this` when executing `forEachFn`.
|
|
85
|
-
*/
|
|
86
|
-
entries(): any[][];
|
|
87
|
-
/**
|
|
88
|
-
* Iterate over the items in the set and pass them to the supplied
|
|
89
|
-
* function ala `Array.prototype.forEach`. Note however, there are no
|
|
90
|
-
* indexes on Sets and as such, the index parameter of the callback
|
|
91
|
-
* will always be `NaN`. Subsequently the `array` or third parameter
|
|
92
|
-
* will receive the set instance rather than an array.
|
|
93
|
-
*
|
|
94
|
-
* @param {function} forEachFn the function to use for each element in
|
|
95
|
-
* the set.
|
|
96
|
-
* @param {object} thisArg the `this` argument to be applied to each
|
|
97
|
-
* invocation of the `forEachFn` callback. Note, this value is unable
|
|
98
|
-
* to be applied if the `forEachFn` is a big arrow function
|
|
99
|
-
*/
|
|
100
|
-
forEach(forEachFn: Function, thisArg: object): void;
|
|
101
|
-
/**
|
|
102
|
-
* Returns an iterator for the values in the RefSet. Each value is
|
|
103
|
-
* dereferenced from its WeakRef before being returned. This method allows
|
|
104
|
-
* iterating over he set's values, similar to how one would iterate over
|
|
105
|
-
* values in a standard Set or Array, but with the understanding that the
|
|
106
|
-
* values are weakly referenced and may no longer exist (in which case
|
|
107
|
-
* they are skipped).
|
|
108
|
-
*
|
|
109
|
-
* @returns {Iterator} An iterator for the values.
|
|
110
|
-
*/
|
|
111
|
-
values(): Iterator<any, any, any>;
|
|
112
|
-
/**
|
|
113
|
-
* Returns an iterator for the keys of the RefSet. In RefSet, keys and
|
|
114
|
-
* values are identical, so this method behaves the same as `values()`. It
|
|
115
|
-
* provides compatibility with the standard Set interface and allows use in
|
|
116
|
-
* contexts where keys are expected, despite RefSet not differentiating
|
|
117
|
-
* between keys and values.
|
|
118
|
-
*
|
|
119
|
-
* @returns {Iterator} An iterator for the keys.
|
|
120
|
-
*/
|
|
121
|
-
keys(): Iterator<any, any, any>;
|
|
122
|
-
/**
|
|
123
|
-
* Checks if the RefSet contains a value that is equal to the specified
|
|
124
|
-
* value. This method is used primarily in objectified RefSets to determine
|
|
125
|
-
* the presence of a value, taking into account objectification. It differs
|
|
126
|
-
* from the `has` method in that it's tailored for sets that have
|
|
127
|
-
* transformed their primitive values into objects, whereas `has` is more
|
|
128
|
-
* general-purpose.
|
|
129
|
-
*
|
|
130
|
-
* @param {*} value - The value to search for in the RefSet.
|
|
131
|
-
* @returns {boolean} - True if the RefSet contains the value, false otherwise.
|
|
132
|
-
*/
|
|
133
|
-
contains(value: any): boolean;
|
|
134
|
-
/**
|
|
135
|
-
* Creates a new array with all elements that pass the test implemented by
|
|
136
|
-
* the provided function. This method iterates over each element,
|
|
137
|
-
* dereferences it, and applies the filter function. Unlike Array `filter`,
|
|
138
|
-
* the callback receives the dereferenced value and not an index or array,
|
|
139
|
-
* reflecting the non-indexed nature of RefSet. Useful for selectively
|
|
140
|
-
* creating arrays from the set based on certain conditions, especially when
|
|
141
|
-
* dealing with weak references.
|
|
142
|
-
*
|
|
143
|
-
* @param {Function} filterFn - Function to test each element of the RefSet.
|
|
144
|
-
* The function receives the dereferenced value.
|
|
145
|
-
* @param {*} thisArg - Value to use as `this` when executing `filterFn`.
|
|
146
|
-
* @returns {Array} - A new array with the elements that pass the test.
|
|
147
|
-
*/
|
|
148
|
-
filter(filterFn: Function, thisArg: any): any[];
|
|
149
|
-
/**
|
|
150
|
-
* Returns the value of the first element in the RefSet that satisfies the
|
|
151
|
-
* provided testing function. Similar to Array `find`, this method iterates
|
|
152
|
-
* over the RefSet, dereferencing each value and applying the testing
|
|
153
|
-
* function. The non-indexed nature of RefSet is considered, as the
|
|
154
|
-
* callback does not receive an index. This method is useful for finding a
|
|
155
|
-
* specific element based on a condition.
|
|
156
|
-
*
|
|
157
|
-
* @param {*} thisArg - Value to use as this when executing findFn.
|
|
158
|
-
* @returns {*} - The value of the first element in the RefSet that satisfies
|
|
159
|
-
* the testing function, or undefined if none found.
|
|
160
|
-
* @returns {any} the dereferenced value if found, or undefined otherwise
|
|
161
|
-
*/
|
|
162
|
-
find(findFn: any, thisArg: any): any;
|
|
163
|
-
/**
|
|
164
|
-
* Creates a new array or `RefSet` with the results of calling a provided
|
|
165
|
-
* function on every element in the calling `RefSet`. This method dereferences
|
|
166
|
-
* each value, applies the `mapFn`, and collects the results. If `toRefSet` is
|
|
167
|
-
* `true`, a new `RefSet` is returned; otherwise, an array. This method
|
|
168
|
-
* differs from `Array.map` in handling weak references and the potential to
|
|
169
|
-
* return a new `RefSet` instead of an array.
|
|
170
|
-
*
|
|
171
|
-
* @param {Function} mapFn - Function that produces an element of the new
|
|
172
|
-
* array or `RefSet`, taking three arguments.
|
|
173
|
-
* @param {*} thisArg - Value to use as this when executing mapFn.
|
|
174
|
-
* @param {boolean} toRefSet - Determines if the output should be a new
|
|
175
|
-
* `RefSet` (`true`) or an array (`false`).
|
|
176
|
-
* @param {boolean} mirrorObjectification - If `true` and `toRefSet` is
|
|
177
|
-
* `true`, the new `RefSet` mirrors the objectification setting of the
|
|
178
|
-
* original.
|
|
179
|
-
* @returns {Array|RefSet} - A new array or `RefSet` with each element being
|
|
180
|
-
* the result of the `mapFn`.
|
|
181
|
-
*/
|
|
182
|
-
map(mapFn: Function, thisArg: any, toRefSet: boolean, mirrorObjectification: boolean): any[] | RefSet;
|
|
183
|
-
#private;
|
|
184
|
-
}
|
|
185
|
-
export const RefSetExtensions: Extension;
|
|
186
|
-
import { Extension } from '@nejs/extension';
|