@nejs/basic-extensions 2.21.0 → 2.22.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/markdown.xml +8 -0
- package/.idea/modules.xml +8 -0
- package/.idea/ne-basic-extensions.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/CODE_STYLE.md +393 -0
- package/CODING_PHILOSOPHY.md +36 -0
- package/DOCUMENTATION_GUIDELINES.md +221 -0
- package/README.md +78 -4
- package/dist/@nejs/basic-extensions.bundle.2.22.6.js +25 -0
- package/dist/@nejs/basic-extensions.bundle.2.22.6.js.map +7 -0
- package/dist/cjs/classes/index.cjs +11129 -0
- package/dist/cjs/classes/index.cjs.map +7 -0
- package/dist/cjs/index.cjs +15191 -0
- package/dist/cjs/index.cjs.map +7 -0
- package/dist/cjs/utils/index.cjs +3954 -0
- package/dist/cjs/utils/index.cjs.map +7 -0
- package/dist/esm/basic-extensions.mjs +25 -0
- package/dist/esm/basic-extensions.mjs.map +7 -0
- package/package.json +16 -22
- package/repl.bootstrap.js +4 -7
- package/repl.history +30 -30
- package/src/big.int.extension.js +171 -45
- package/src/classes/enumeration.js +466 -0
- package/src/classes/index.js +5 -1
- package/src/index.js +5 -1
- package/src/math.extension.js +73 -0
- package/src/number.extension.js +18 -0
- package/src/regular.expression.extensions.js +0 -35
- package/src/utils/toolkit.js +699 -516
- package/tests/arrayextensions.test.js +3 -3
- package/tests/index.test.js +3 -1
- package/tests/newClasses/asyncIterable.test.js +3 -3
- package/tests/newClasses/deferred.test.js +3 -3
- package/tests/newClasses/descriptor.test.js +3 -3
- package/tests/newClasses/iterable.test.js +3 -3
- package/tests/newClasses/refmap.test.js +3 -3
- package/tests/newClasses/refset.test.js +3 -3
- package/tests/objectextensions.test.js +3 -3
- package/tests/setextensions.test.js +3 -3
- package/tests/stringextensions.test.js +3 -2
- package/tests/utils/descriptor.utils.test.js +1 -1
- package/tests/utils/toolkit.test.js +429 -163
- package/.esdoc.json +0 -9
- package/.vscode/settings.json +0 -5
- package/bin/build +0 -27
- package/bin/clean +0 -14
- package/bin/esbuild +0 -91
- package/bin/fixup +0 -13
- package/bin/repl.basics.js +0 -584
- package/bin/repl.signature.js +0 -63
- package/bin/version +0 -100
- package/dist/@nejs/basic-extensions.bundle.2.21.0.js +0 -25
- package/dist/@nejs/basic-extensions.bundle.2.21.0.js.map +0 -7
- package/dist/cjs/array.extensions.d.ts +0 -39
- package/dist/cjs/array.extensions.js +0 -477
- package/dist/cjs/array.extensions.js.map +0 -1
- package/dist/cjs/big.int.extension.d.ts +0 -31
- package/dist/cjs/big.int.extension.js +0 -165
- package/dist/cjs/big.int.extension.js.map +0 -1
- package/dist/cjs/classes/asyncIterable.d.ts +0 -126
- package/dist/cjs/classes/asyncIterable.js +0 -209
- package/dist/cjs/classes/asyncIterable.js.map +0 -1
- package/dist/cjs/classes/deferred.d.ts +0 -146
- package/dist/cjs/classes/deferred.js +0 -291
- package/dist/cjs/classes/deferred.js.map +0 -1
- package/dist/cjs/classes/descriptor.d.ts +0 -334
- package/dist/cjs/classes/descriptor.js +0 -537
- package/dist/cjs/classes/descriptor.js.map +0 -1
- package/dist/cjs/classes/enum.d.ts +0 -50
- package/dist/cjs/classes/enum.js +0 -405
- package/dist/cjs/classes/enum.js.map +0 -1
- package/dist/cjs/classes/index.d.ts +0 -15
- package/dist/cjs/classes/index.js +0 -63
- package/dist/cjs/classes/index.js.map +0 -1
- package/dist/cjs/classes/introspector.d.ts +0 -20
- package/dist/cjs/classes/introspector.js +0 -130
- package/dist/cjs/classes/introspector.js.map +0 -1
- package/dist/cjs/classes/iterable.d.ts +0 -169
- package/dist/cjs/classes/iterable.js +0 -268
- package/dist/cjs/classes/iterable.js.map +0 -1
- package/dist/cjs/classes/param.parser.d.ts +0 -221
- package/dist/cjs/classes/param.parser.js +0 -242
- package/dist/cjs/classes/param.parser.js.map +0 -1
- package/dist/cjs/classes/pluggable.proxy.d.ts +0 -153
- package/dist/cjs/classes/pluggable.proxy.js +0 -444
- package/dist/cjs/classes/pluggable.proxy.js.map +0 -1
- package/dist/cjs/classes/property.d.ts +0 -79
- package/dist/cjs/classes/property.js +0 -284
- package/dist/cjs/classes/property.js.map +0 -1
- package/dist/cjs/classes/refmap.d.ts +0 -238
- package/dist/cjs/classes/refmap.js +0 -421
- package/dist/cjs/classes/refmap.js.map +0 -1
- package/dist/cjs/classes/refset.d.ts +0 -186
- package/dist/cjs/classes/refset.js +0 -370
- package/dist/cjs/classes/refset.js.map +0 -1
- package/dist/cjs/classes/symkeys.d.ts +0 -349
- package/dist/cjs/classes/symkeys.js +0 -510
- package/dist/cjs/classes/symkeys.js.map +0 -1
- package/dist/cjs/classes/type.d.ts +0 -56
- package/dist/cjs/classes/type.js +0 -405
- package/dist/cjs/classes/type.js.map +0 -1
- package/dist/cjs/function.extensions.d.ts +0 -12
- package/dist/cjs/function.extensions.js +0 -758
- package/dist/cjs/function.extensions.js.map +0 -1
- package/dist/cjs/global.this.d.ts +0 -2
- package/dist/cjs/global.this.js +0 -300
- package/dist/cjs/global.this.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -31
- package/dist/cjs/index.js +0 -226
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json.extensions.d.ts +0 -2
- package/dist/cjs/json.extensions.js +0 -109
- package/dist/cjs/json.extensions.js.map +0 -1
- package/dist/cjs/map.extensions.d.ts +0 -3
- package/dist/cjs/map.extensions.js +0 -143
- package/dist/cjs/map.extensions.js.map +0 -1
- package/dist/cjs/number.extension.d.ts +0 -44
- package/dist/cjs/number.extension.js +0 -261
- package/dist/cjs/number.extension.js.map +0 -1
- package/dist/cjs/object.extensions.d.ts +0 -33
- package/dist/cjs/object.extensions.js +0 -1091
- package/dist/cjs/object.extensions.js.map +0 -1
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/proxy.extensions.d.ts +0 -2
- package/dist/cjs/proxy.extensions.js +0 -207
- package/dist/cjs/proxy.extensions.js.map +0 -1
- package/dist/cjs/reflect.extensions.d.ts +0 -14
- package/dist/cjs/reflect.extensions.js +0 -316
- package/dist/cjs/reflect.extensions.js.map +0 -1
- package/dist/cjs/regular.expression.extensions.d.ts +0 -2
- package/dist/cjs/regular.expression.extensions.js +0 -423
- package/dist/cjs/regular.expression.extensions.js.map +0 -1
- package/dist/cjs/set.extensions.d.ts +0 -40
- package/dist/cjs/set.extensions.js +0 -355
- package/dist/cjs/set.extensions.js.map +0 -1
- package/dist/cjs/string.extensions.d.ts +0 -23
- package/dist/cjs/string.extensions.js +0 -704
- package/dist/cjs/string.extensions.js.map +0 -1
- package/dist/cjs/symbol.extensions.d.ts +0 -11
- package/dist/cjs/symbol.extensions.js +0 -735
- package/dist/cjs/symbol.extensions.js.map +0 -1
- package/dist/cjs/utils/copy.object.d.ts +0 -408
- package/dist/cjs/utils/copy.object.js +0 -720
- package/dist/cjs/utils/copy.object.js.map +0 -1
- package/dist/cjs/utils/descriptor.utils.d.ts +0 -298
- package/dist/cjs/utils/descriptor.utils.js +0 -889
- package/dist/cjs/utils/descriptor.utils.js.map +0 -1
- package/dist/cjs/utils/index.d.ts +0 -75
- package/dist/cjs/utils/index.js +0 -61
- package/dist/cjs/utils/index.js.map +0 -1
- package/dist/cjs/utils/stdout.d.ts +0 -742
- package/dist/cjs/utils/stdout.js +0 -1042
- package/dist/cjs/utils/stdout.js.map +0 -1
- package/dist/cjs/utils/toolkit.d.ts +0 -1898
- package/dist/cjs/utils/toolkit.js +0 -1378
- package/dist/cjs/utils/toolkit.js.map +0 -1
- package/dist/cjs/weakref.extensions.d.ts +0 -2
- package/dist/cjs/weakref.extensions.js +0 -19
- package/dist/cjs/weakref.extensions.js.map +0 -1
- package/dist/mjs/array.extensions.d.ts +0 -39
- package/dist/mjs/array.extensions.js +0 -474
- package/dist/mjs/array.extensions.js.map +0 -1
- package/dist/mjs/big.int.extension.d.ts +0 -31
- package/dist/mjs/big.int.extension.js +0 -162
- package/dist/mjs/big.int.extension.js.map +0 -1
- package/dist/mjs/classes/asyncIterable.d.ts +0 -126
- package/dist/mjs/classes/asyncIterable.js +0 -204
- package/dist/mjs/classes/asyncIterable.js.map +0 -1
- package/dist/mjs/classes/deferred.d.ts +0 -146
- package/dist/mjs/classes/deferred.js +0 -287
- package/dist/mjs/classes/deferred.js.map +0 -1
- package/dist/mjs/classes/descriptor.d.ts +0 -334
- package/dist/mjs/classes/descriptor.js +0 -533
- package/dist/mjs/classes/descriptor.js.map +0 -1
- package/dist/mjs/classes/enum.d.ts +0 -50
- package/dist/mjs/classes/enum.js +0 -400
- package/dist/mjs/classes/enum.js.map +0 -1
- package/dist/mjs/classes/index.d.ts +0 -15
- package/dist/mjs/classes/index.js +0 -46
- package/dist/mjs/classes/index.js.map +0 -1
- package/dist/mjs/classes/introspector.d.ts +0 -20
- package/dist/mjs/classes/introspector.js +0 -126
- package/dist/mjs/classes/introspector.js.map +0 -1
- package/dist/mjs/classes/iterable.d.ts +0 -169
- package/dist/mjs/classes/iterable.js +0 -263
- package/dist/mjs/classes/iterable.js.map +0 -1
- package/dist/mjs/classes/param.parser.d.ts +0 -221
- package/dist/mjs/classes/param.parser.js +0 -238
- package/dist/mjs/classes/param.parser.js.map +0 -1
- package/dist/mjs/classes/pluggable.proxy.d.ts +0 -153
- package/dist/mjs/classes/pluggable.proxy.js +0 -438
- package/dist/mjs/classes/pluggable.proxy.js.map +0 -1
- package/dist/mjs/classes/property.d.ts +0 -79
- package/dist/mjs/classes/property.js +0 -280
- package/dist/mjs/classes/property.js.map +0 -1
- package/dist/mjs/classes/refmap.d.ts +0 -238
- package/dist/mjs/classes/refmap.js +0 -417
- package/dist/mjs/classes/refmap.js.map +0 -1
- package/dist/mjs/classes/refset.d.ts +0 -186
- package/dist/mjs/classes/refset.js +0 -366
- package/dist/mjs/classes/refset.js.map +0 -1
- package/dist/mjs/classes/symkeys.d.ts +0 -349
- package/dist/mjs/classes/symkeys.js +0 -506
- package/dist/mjs/classes/symkeys.js.map +0 -1
- package/dist/mjs/classes/type.d.ts +0 -56
- package/dist/mjs/classes/type.js +0 -401
- package/dist/mjs/classes/type.js.map +0 -1
- package/dist/mjs/function.extensions.d.ts +0 -12
- package/dist/mjs/function.extensions.js +0 -755
- package/dist/mjs/function.extensions.js.map +0 -1
- package/dist/mjs/global.this.d.ts +0 -2
- package/dist/mjs/global.this.js +0 -264
- package/dist/mjs/global.this.js.map +0 -1
- package/dist/mjs/index.d.ts +0 -31
- package/dist/mjs/index.js +0 -204
- package/dist/mjs/index.js.map +0 -1
- package/dist/mjs/json.extensions.d.ts +0 -2
- package/dist/mjs/json.extensions.js +0 -106
- package/dist/mjs/json.extensions.js.map +0 -1
- package/dist/mjs/map.extensions.d.ts +0 -3
- package/dist/mjs/map.extensions.js +0 -140
- package/dist/mjs/map.extensions.js.map +0 -1
- package/dist/mjs/number.extension.d.ts +0 -44
- package/dist/mjs/number.extension.js +0 -258
- package/dist/mjs/number.extension.js.map +0 -1
- package/dist/mjs/object.extensions.d.ts +0 -33
- package/dist/mjs/object.extensions.js +0 -1088
- package/dist/mjs/object.extensions.js.map +0 -1
- package/dist/mjs/package.json +0 -3
- package/dist/mjs/proxy.extensions.d.ts +0 -2
- package/dist/mjs/proxy.extensions.js +0 -204
- package/dist/mjs/proxy.extensions.js.map +0 -1
- package/dist/mjs/reflect.extensions.d.ts +0 -14
- package/dist/mjs/reflect.extensions.js +0 -313
- package/dist/mjs/reflect.extensions.js.map +0 -1
- package/dist/mjs/regular.expression.extensions.d.ts +0 -2
- package/dist/mjs/regular.expression.extensions.js +0 -420
- package/dist/mjs/regular.expression.extensions.js.map +0 -1
- package/dist/mjs/set.extensions.d.ts +0 -40
- package/dist/mjs/set.extensions.js +0 -352
- package/dist/mjs/set.extensions.js.map +0 -1
- package/dist/mjs/string.extensions.d.ts +0 -23
- package/dist/mjs/string.extensions.js +0 -701
- package/dist/mjs/string.extensions.js.map +0 -1
- package/dist/mjs/symbol.extensions.d.ts +0 -11
- package/dist/mjs/symbol.extensions.js +0 -732
- package/dist/mjs/symbol.extensions.js.map +0 -1
- package/dist/mjs/utils/copy.object.d.ts +0 -408
- package/dist/mjs/utils/copy.object.js +0 -702
- package/dist/mjs/utils/copy.object.js.map +0 -1
- package/dist/mjs/utils/descriptor.utils.d.ts +0 -298
- package/dist/mjs/utils/descriptor.utils.js +0 -875
- package/dist/mjs/utils/descriptor.utils.js.map +0 -1
- package/dist/mjs/utils/index.d.ts +0 -75
- package/dist/mjs/utils/index.js +0 -45
- package/dist/mjs/utils/index.js.map +0 -1
- package/dist/mjs/utils/stdout.d.ts +0 -742
- package/dist/mjs/utils/stdout.js +0 -1037
- package/dist/mjs/utils/stdout.js.map +0 -1
- package/dist/mjs/utils/toolkit.d.ts +0 -1898
- package/dist/mjs/utils/toolkit.js +0 -1373
- package/dist/mjs/utils/toolkit.js.map +0 -1
- package/dist/mjs/weakref.extensions.d.ts +0 -2
- package/dist/mjs/weakref.extensions.js +0 -16
- package/dist/mjs/weakref.extensions.js.map +0 -1
- package/jsdoc-config.json +0 -31
- package/tsconfig.base.json +0 -28
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.esm.json +0 -8
- package/vitest.config.js +0 -7
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
import { Patch } from '@nejs/extension';
|
|
2
|
-
/**
|
|
3
|
-
* `SetExtensions` is a constant that applies a patch to the global
|
|
4
|
-
* `Set` constructor. This patch extends the `Set` with additional
|
|
5
|
-
* methods and properties, enhancing its functionality.
|
|
6
|
-
*
|
|
7
|
-
* The `Patch` function takes two arguments: the target object to be patched
|
|
8
|
-
* (in this case, `Set`), and an object containing the methods and
|
|
9
|
-
* properties to be added to the target object.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* // Using a method added by SetExtensions
|
|
13
|
-
* const set = new Set();
|
|
14
|
-
* console.log(Set.isSet(set)); // Output: true
|
|
15
|
-
*
|
|
16
|
-
* @const
|
|
17
|
-
* @type {Patch}
|
|
18
|
-
* @memberof module:set.extensions
|
|
19
|
-
*/
|
|
20
|
-
export const SetExtensions = new Patch(Set, {
|
|
21
|
-
[Patch.kMutablyHidden]: {
|
|
22
|
-
/**
|
|
23
|
-
* Determines if the supplied `value` is a `Set` object. This check
|
|
24
|
-
* is performed by first looking for the `Symbol.toStringTag` on the
|
|
25
|
-
* `value` and checking to see if it is equal to the string "Set".
|
|
26
|
-
* If that check fails, `instanceof` is used as a fallback to check
|
|
27
|
-
* the prototype chain.
|
|
28
|
-
*
|
|
29
|
-
* @param {any} value the value that needs to be checked to determine
|
|
30
|
-
* if it is a `Set` object or not
|
|
31
|
-
* @returns {boolean} `true` if the supplied `value` is a `Set`
|
|
32
|
-
* object, `false` otherwise
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* const set = new Set()
|
|
36
|
-
* isSet(set) // true
|
|
37
|
-
* isSet(new Map()) // false
|
|
38
|
-
* isSet([]) // false
|
|
39
|
-
* isSet({}) // false
|
|
40
|
-
*/
|
|
41
|
-
isSet(value) {
|
|
42
|
-
return value?.[Symbol.toStringTag] === Set.name || value instanceof Set;
|
|
43
|
-
},
|
|
44
|
-
/**
|
|
45
|
-
* Conditionally returns a value based on whether the supplied
|
|
46
|
-
* `value` is a `Set` object or not. If the `value` is a `Set`
|
|
47
|
-
* object, the `thenValue` will be returned. If it is not a `Set`
|
|
48
|
-
* object, the `elseValue` will be returned instead.
|
|
49
|
-
*
|
|
50
|
-
* @param {any} value the value to check to determine if it is a
|
|
51
|
-
* `Set` object
|
|
52
|
-
* @param {any} thenValue the value to return if the supplied
|
|
53
|
-
* `value` is a `Set` object
|
|
54
|
-
* @param {any} elseValue the value to return if the supplied
|
|
55
|
-
* `value` is not a `Set` object
|
|
56
|
-
* @returns {any} either the `thenValue` or `elseValue` depending
|
|
57
|
-
* on if the supplied `value` is a `Set` object
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* const set = new Set()
|
|
61
|
-
* const map = new Map()
|
|
62
|
-
* ifSet(set, 'is a set', 'not a set') // 'is a set'
|
|
63
|
-
* ifSet(map, 'is a set', 'not a set') // 'not a set'
|
|
64
|
-
*/
|
|
65
|
-
ifSet(value, thenValue, elseValue) {
|
|
66
|
-
return isThenElse(this.isSet(value), thenValue, elseValue);
|
|
67
|
-
},
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
const { isSet: pIsSet } = SetExtensions.patches;
|
|
71
|
-
/**
|
|
72
|
-
* `SetPrototypeExtensions` is a constant that applies a patch to the
|
|
73
|
-
* prototype of the built-in JavaScript `Set` object. This patch extends the
|
|
74
|
-
* `Set` prototype with additional methods and properties, enhancing its
|
|
75
|
-
* functionality.
|
|
76
|
-
*
|
|
77
|
-
* The `Patch` function takes two arguments: the target object to be patched
|
|
78
|
-
* (in this case, `Set.prototype`), and an object containing the methods and
|
|
79
|
-
* properties to be added to the target object.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* // Using a method added by SetPrototypeExtensions
|
|
83
|
-
* const mySet = new Set();
|
|
84
|
-
* mySet.myNewMethod(); // Calls the new method added by the patch
|
|
85
|
-
*
|
|
86
|
-
* @const
|
|
87
|
-
* @type {Patch}
|
|
88
|
-
* @memberof module:set.extensions
|
|
89
|
-
*/
|
|
90
|
-
export const SetPrototypeExtensions = new Patch(Set.prototype, {
|
|
91
|
-
[Patch.kMutablyHidden]: {
|
|
92
|
-
/**
|
|
93
|
-
* Merges multiple iterables into the set. Each element from the iterables
|
|
94
|
-
* is added to the set, ensuring uniqueness of all elements. This method
|
|
95
|
-
* mutates the original set.
|
|
96
|
-
*
|
|
97
|
-
* @param {...Iterable} iterables - One or more iterable objects (like Set
|
|
98
|
-
* or Array) whose elements will be added to the set.
|
|
99
|
-
*/
|
|
100
|
-
concat(...iterables) {
|
|
101
|
-
for (const iterable of iterables) {
|
|
102
|
-
if (typeof iterable === 'string' ||
|
|
103
|
-
!Reflect.has(iterable, Symbol.iterator)) {
|
|
104
|
-
this.add(iterable);
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
for (const element of iterable) {
|
|
108
|
-
this.add(element);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
/**
|
|
113
|
-
* Checks to see if any value within the `Set` loosely equals the supplied
|
|
114
|
-
* value.
|
|
115
|
-
*
|
|
116
|
-
* @param {*} value any value that might be loosely equal to an item in the
|
|
117
|
-
* set, as opposed to {@link Set.has} which is the equivalent of a strict or
|
|
118
|
-
* triple equals (`===`) check
|
|
119
|
-
* @returns {boolean} `true` if any value within the set is loosely equal to
|
|
120
|
-
* the supplied value, `false` otherwise
|
|
121
|
-
*/
|
|
122
|
-
contains(value) {
|
|
123
|
-
for (const element of this) {
|
|
124
|
-
if (value == element) {
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return false;
|
|
129
|
-
},
|
|
130
|
-
/**
|
|
131
|
-
* Checks if every element in the set passes the test implemented by the
|
|
132
|
-
* provided function. The function is called with each element of the set.
|
|
133
|
-
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
134
|
-
*
|
|
135
|
-
* @param {Function} everyFn - The function to test each element. Receives
|
|
136
|
-
* the element, index (always NaN), and the set itself.
|
|
137
|
-
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
138
|
-
* `everyFn`.
|
|
139
|
-
* @throws {TypeError} If `everyFn` is not a function.
|
|
140
|
-
* @returns {boolean} True if every element passes the test, false otherwise.
|
|
141
|
-
*/
|
|
142
|
-
every(everyFn, thisArg) {
|
|
143
|
-
if (typeof everyFn !== 'function') {
|
|
144
|
-
throw new TypeError(`everyFn must be a function! Received ${String(everyFn)}`);
|
|
145
|
-
}
|
|
146
|
-
let found = 0;
|
|
147
|
-
for (const element of this) {
|
|
148
|
-
if (everyFn.call(thisArg, element, NaN, this)) {
|
|
149
|
-
found++;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return (found === this.size);
|
|
153
|
-
},
|
|
154
|
-
/**
|
|
155
|
-
* Finds the first element in the set satisfying the provided testing
|
|
156
|
-
* function. If no elements satisfy the testing function, undefined is
|
|
157
|
-
* returned. The function is called with each element of the set.
|
|
158
|
-
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
159
|
-
*
|
|
160
|
-
* @param {Function} findFn - The function to execute on each element. It
|
|
161
|
-
* receives the element, index (always NaN), and the set itself.
|
|
162
|
-
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
163
|
-
* `findFn`.
|
|
164
|
-
* @throws {TypeError} If `findFn` is not a function.
|
|
165
|
-
* @returns {*} The first element that satisfies `findFn`, or undefined.
|
|
166
|
-
*/
|
|
167
|
-
find(findFn, thisArg) {
|
|
168
|
-
if (typeof findFn !== 'function') {
|
|
169
|
-
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
|
|
170
|
-
}
|
|
171
|
-
for (const element of this) {
|
|
172
|
-
const match = findFn.call(thisArg, element, NaN, this);
|
|
173
|
-
if (match) {
|
|
174
|
-
return element;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return undefined;
|
|
178
|
-
},
|
|
179
|
-
/**
|
|
180
|
-
* Finds the last element in the set satisfying the provided testing function.
|
|
181
|
-
* If no elements satisfy the testing function, undefined is returned. The
|
|
182
|
-
* function is called with each element of the set in reverse order.
|
|
183
|
-
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
184
|
-
*
|
|
185
|
-
* @param {Function} findFn - The function to execute on each element. It
|
|
186
|
-
* receives the element, index (always NaN), and the set itself.
|
|
187
|
-
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
188
|
-
* `findFn`.
|
|
189
|
-
* @throws {TypeError} If `findFn` is not a function.
|
|
190
|
-
* @returns {*} The last element that satisfies `findFn`, or undefined.
|
|
191
|
-
*/
|
|
192
|
-
findLast(findFn, thisArg) {
|
|
193
|
-
if (typeof findFn !== 'function') {
|
|
194
|
-
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
|
|
195
|
-
}
|
|
196
|
-
const found = [];
|
|
197
|
-
for (const element of this) {
|
|
198
|
-
const match = findFn.call(thisArg, element, NaN, this);
|
|
199
|
-
if (match) {
|
|
200
|
-
found.push(element);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (found.length) {
|
|
204
|
-
return found[found.length - 1];
|
|
205
|
-
}
|
|
206
|
-
return undefined;
|
|
207
|
-
},
|
|
208
|
-
/**
|
|
209
|
-
* Determines if the current object is a `Set` object.
|
|
210
|
-
*
|
|
211
|
-
* This is a getter that uses the `isSet` function from the
|
|
212
|
-
* `SetExtensions` patch to check if the current object (`this`) is
|
|
213
|
-
* a `Set` object.
|
|
214
|
-
*
|
|
215
|
-
* @type {boolean}
|
|
216
|
-
* @readonly
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* const set = new Set()
|
|
220
|
-
* console.log(set.isSet) // Output: true
|
|
221
|
-
*
|
|
222
|
-
* const notSet = {}
|
|
223
|
-
* console.log(notSet.isSet) // Output: false
|
|
224
|
-
*/
|
|
225
|
-
get isSet() {
|
|
226
|
-
return pIsSet(this);
|
|
227
|
-
},
|
|
228
|
-
/**
|
|
229
|
-
* Checks if the current object is a Set and returns the
|
|
230
|
-
* corresponding value based on the result.
|
|
231
|
-
*
|
|
232
|
-
* This method uses the `isThenElse` function from the
|
|
233
|
-
* `SetExtensions` patch to determine if the current object
|
|
234
|
-
* (`this`) is a Set. If it is a Set, the `thenValue` is returned.
|
|
235
|
-
* Otherwise, the `elseValue` is returned.
|
|
236
|
-
*
|
|
237
|
-
* @param {any} thenValue - The value to return if the current object
|
|
238
|
-
* is a Set.
|
|
239
|
-
* @param {any} elseValue - The value to return if the current object
|
|
240
|
-
* is not a Set.
|
|
241
|
-
* @returns {any} The `thenValue` if the current object is a Set, or
|
|
242
|
-
* the `elseValue` if it is not a Set.
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* const set = new Set([1, 2, 3])
|
|
246
|
-
* console.log(set.ifSet('Is a Set', 'Not a Set')) // 'Is a Set'
|
|
247
|
-
*
|
|
248
|
-
* const notSet = {}
|
|
249
|
-
* console.log(notSet.ifSet('Is a Set', 'Not a Set')) // 'Not a Set'
|
|
250
|
-
*/
|
|
251
|
-
ifSet(thenValue, elseValue) {
|
|
252
|
-
return isThenElse(pIsSet(this), thenValue, elseValue);
|
|
253
|
-
},
|
|
254
|
-
/**
|
|
255
|
-
* A getter property that returns the number of elements in the set.
|
|
256
|
-
* This is an alias for the `size` property of the set.
|
|
257
|
-
*
|
|
258
|
-
* @returns {number} The number of elements in the set.
|
|
259
|
-
*/
|
|
260
|
-
get length() {
|
|
261
|
-
return this.size;
|
|
262
|
-
},
|
|
263
|
-
/**
|
|
264
|
-
* Creates a new array populated with the results of calling the provided
|
|
265
|
-
* function on every element in the set. The function is called with each
|
|
266
|
-
* element of the set. Note: Since sets do not have indices, the index
|
|
267
|
-
* parameter is always NaN.
|
|
268
|
-
*
|
|
269
|
-
* @param {Function} mapFn - The function to execute on each element. It
|
|
270
|
-
* receives the element, index (always NaN), and the set itself.
|
|
271
|
-
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
272
|
-
* `mapFn`.
|
|
273
|
-
* @throws {TypeError} If `mapFn` is not a function.
|
|
274
|
-
* @returns {Array} A new array with each element being the result of the
|
|
275
|
-
* `mapFn`.
|
|
276
|
-
*/
|
|
277
|
-
map(mapFn, thisArg) {
|
|
278
|
-
if (typeof mapFn !== 'function') {
|
|
279
|
-
throw new TypeError(`mapFn must be a function! Received ${String(mapFn)}`);
|
|
280
|
-
}
|
|
281
|
-
const transformed = [];
|
|
282
|
-
for (const element of this) {
|
|
283
|
-
transformed.push(mapFn.call(thisArg, element, NaN, this));
|
|
284
|
-
}
|
|
285
|
-
return transformed;
|
|
286
|
-
},
|
|
287
|
-
/**
|
|
288
|
-
* Applies a function against an accumulator and each element in the set to
|
|
289
|
-
* reduce it to a single value. The function is called with each element of
|
|
290
|
-
* the set. Note: Since sets do not have indices, the index parameter is
|
|
291
|
-
* always NaN.
|
|
292
|
-
*
|
|
293
|
-
* @param {Function} reduceFn - The function to execute on each element. It
|
|
294
|
-
* receives the accumulator, element, index (always NaN), and the set itself.
|
|
295
|
-
* @param {*} initialValue - The initial value to start reducing from.
|
|
296
|
-
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
297
|
-
* `reduceFn`.
|
|
298
|
-
* @throws {TypeError} If `reduceFn` is not a function.
|
|
299
|
-
* @returns {*} The reduced value.
|
|
300
|
-
*/
|
|
301
|
-
reduce(reduceFn, initialValue, thisArg) {
|
|
302
|
-
if (typeof reduceFn !== 'function') {
|
|
303
|
-
throw new TypeError(`reduceFn must be a Function! Received ${String(reduceFn)}`);
|
|
304
|
-
}
|
|
305
|
-
let accumulator = initialValue;
|
|
306
|
-
for (const element of this) {
|
|
307
|
-
accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this);
|
|
308
|
-
}
|
|
309
|
-
return accumulator;
|
|
310
|
-
},
|
|
311
|
-
/**
|
|
312
|
-
* Tests whether at least one element in the set passes the test implemented
|
|
313
|
-
* by the provided function. The function is called with each element of the
|
|
314
|
-
* set. Note: Since sets do not have indices, the index parameter is always NaN.
|
|
315
|
-
*
|
|
316
|
-
* @param {Function} someFn - The function to test each element. It receives
|
|
317
|
-
* the element, index (always NaN), and the set itself.
|
|
318
|
-
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
319
|
-
* `someFn`.
|
|
320
|
-
* @throws {TypeError} If `someFn` is not a function.
|
|
321
|
-
* @returns {boolean} True if at least one element passes the test, false
|
|
322
|
-
* otherwise.
|
|
323
|
-
*/
|
|
324
|
-
some(someFn, thisArg) {
|
|
325
|
-
if (typeof someFn !== 'function') {
|
|
326
|
-
throw new TypeError(`someFn must be a function! Received ${String(someFn)}`);
|
|
327
|
-
}
|
|
328
|
-
for (const element of this) {
|
|
329
|
-
if (someFn.call(thisArg, element, NaN, this)) {
|
|
330
|
-
return true;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return false;
|
|
334
|
-
},
|
|
335
|
-
},
|
|
336
|
-
});
|
|
337
|
-
// NOTE to self; this is repeated here otherwise a circular reference from
|
|
338
|
-
// Object<->Function<->Global occurs. See original source in global.this.js
|
|
339
|
-
// {@see globalThis.isThenElse}
|
|
340
|
-
function isThenElse(bv, tv, ev) {
|
|
341
|
-
function isFunction(value) { typeof value === 'function'; }
|
|
342
|
-
if (arguments.length > 1) {
|
|
343
|
-
var _then = isFunction(tv) ? tv(bv) : tv;
|
|
344
|
-
if (arguments.length > 2) {
|
|
345
|
-
var _else = isFunction(ev) ? tv(bv) : ev;
|
|
346
|
-
return bv ? _then : _else;
|
|
347
|
-
}
|
|
348
|
-
return bv || _then;
|
|
349
|
-
}
|
|
350
|
-
return bv;
|
|
351
|
-
}
|
|
352
|
-
//# sourceMappingURL=set.extensions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"set.extensions.js","sourceRoot":"","sources":["../../src/set.extensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,GAAG,EAAE;IAC1C,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;QACtB;;;;;;;;;;;;;;;;;;WAkBG;QACH,KAAK,CAAC,KAAK;YACT,OAAO,KAAK,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,KAAK,YAAY,GAAG,CAAA;QACzE,CAAC;QAED;;;;;;;;;;;;;;;;;;;;WAoBG;QACH,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS;YAC/B,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAC5D,CAAC;KACF;CACF,CAAC,CAAA;AAE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@
|
|
|
1
|
-
/**
|
|
2
|
-
* `StringExtensions` is a patch for the JavaScript built-in `String` class. It
|
|
3
|
-
* adds utility methods to the `String` class without modifying the global namespace
|
|
4
|
-
* directly. This patch includes methods for key validation, object type checking,
|
|
5
|
-
* and retrieving the string tag of an object. These methods are useful for
|
|
6
|
-
* enhancing the capabilities of the standard `String` class with additional
|
|
7
|
-
* utility functions.
|
|
8
|
-
*/
|
|
9
|
-
export const StringExtensions: Patch;
|
|
10
|
-
/**
|
|
11
|
-
* `StringPrototypeExtensions` provides a set of utility methods that are
|
|
12
|
-
* added to the `String` prototype. This allows all string instances to
|
|
13
|
-
* access new functionality directly, enhancing their capabilities beyond
|
|
14
|
-
* the standard `String` class methods. These extensions are applied using
|
|
15
|
-
* the `Patch` class from '@nejs/extension', ensuring that they do not
|
|
16
|
-
* interfere with the global namespace or existing properties.
|
|
17
|
-
*
|
|
18
|
-
* The extensions include methods for extracting substrings based on
|
|
19
|
-
* specific tokens, checking the presence of certain patterns, and more,
|
|
20
|
-
* making string manipulation tasks more convenient and expressive.
|
|
21
|
-
*/
|
|
22
|
-
export const StringPrototypeExtensions: Patch;
|
|
23
|
-
import { Patch } from '@nejs/extension';
|