@nejs/basic-extensions 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +374 -103
- package/dist/@nejs/basic-extensions.bundle.1.7.0.js +4 -0
- package/dist/@nejs/basic-extensions.bundle.1.7.0.js.map +7 -0
- package/dist/cjs/functionextensions.d.ts +1 -0
- package/dist/cjs/functionextensions.js +128 -18
- package/dist/cjs/functionextensions.js.map +1 -1
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/setextensions.d.ts +2 -0
- package/dist/cjs/setextensions.js +204 -0
- package/dist/cjs/setextensions.js.map +1 -0
- package/dist/mjs/functionextensions.d.ts +1 -0
- package/dist/mjs/functionextensions.js +127 -17
- package/dist/mjs/functionextensions.js.map +1 -1
- package/dist/mjs/index.js +4 -1
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/setextensions.d.ts +2 -0
- package/dist/mjs/setextensions.js +201 -0
- package/dist/mjs/setextensions.js.map +1 -0
- package/docs/index.html +5020 -3328
- package/package.json +6 -3
- package/src/functionextensions.js +150 -24
- package/src/index.js +4 -1
- package/src/setextensions.js +242 -0
- package/tests/setextensions.test.js +89 -0
- package/dist/@nejs/basic-extensions.bundle.1.6.1.js +0 -4
- package/dist/@nejs/basic-extensions.bundle.1.6.1.js.map +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functionextensions.js","sourceRoot":"","sources":["../../src/functionextensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"functionextensions.js","sourceRoot":"","sources":["../../src/functionextensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,MAAM,EAAE,YAAY,EAAE,GAAG,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1,7 @@
|
|
|
1
|
-
import { FunctionExtensions } from './functionextensions.js';
|
|
1
|
+
import { FunctionExtensions, FunctionPrototypeExtensions } from './functionextensions.js';
|
|
2
2
|
import { ObjectExtensions, ObjectPrototypeExtensions } from './objectextensions.js';
|
|
3
3
|
import { MapPrototypeExtensions } from './mapextensions.js';
|
|
4
|
+
import { SetPrototypeExtensions } from './setextensions.js';
|
|
4
5
|
import { ReflectExtensions } from './reflectextensions.js';
|
|
5
6
|
import { StringExtensions } from './stringextensions.js';
|
|
6
7
|
import { SymbolExtensions } from './symbolextensions.js';
|
|
@@ -18,8 +19,10 @@ const Patches = new Map([
|
|
|
18
19
|
[String, StringExtensions],
|
|
19
20
|
[Symbol, SymbolExtensions],
|
|
20
21
|
[Object.prototype, ObjectPrototypeExtensions],
|
|
22
|
+
[Function.prototype, FunctionPrototypeExtensions],
|
|
21
23
|
[Array.prototype, ArrayPrototypeExtensions],
|
|
22
24
|
[Map.prototype, MapPrototypeExtensions],
|
|
25
|
+
[Set.prototype, SetPrototypeExtensions],
|
|
23
26
|
[globalThis, GlobalFunctionsAndProps],
|
|
24
27
|
]);
|
|
25
28
|
const Extensions = {
|
package/dist/mjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AACzF,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EA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,CAAC,GAAG,EAAE;IACvB,MAAM,UAAU,GAAG;QACjB,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/B,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KACzC,CAAA;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE;QACxD,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;YACxD,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;YAEzC,IAAI,KAAK,CAAC,UAAU;gBAClB,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;;gBAEnD,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAA;YAEnC,OAAO,WAAW,CAAA;QACpB,CAAC,EAAE,WAAW,CAAC,CAAA;QAEf,OAAO,WAAW,CAAA;IACpB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,IAAI,CAAA;AACb,CAAC,CAAC,EAAE,CAAA;AAEJ,MAAM,OAAO,GAAG;IACd,GAAG,QAAQ;IACX,UAAU,EAAE,UAAU;IACtB,OAAO,EAAE,OAAO;IAChB,GAAG;CACJ,CAAA;AAED,eAAe,OAAO,CAAA;AAEtB,OAAO,EACL,UAAU,EACV,OAAO,EACP,QAAQ,GACT,CAAA"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Patch } from '@nejs/extension';
|
|
2
|
+
export const SetPrototypeExtensions = new Patch(Set.prototype, {
|
|
3
|
+
/**
|
|
4
|
+
* Merges multiple iterables into the set. Each element from the iterables
|
|
5
|
+
* is added to the set, ensuring uniqueness of all elements. This method
|
|
6
|
+
* mutates the original set.
|
|
7
|
+
*
|
|
8
|
+
* @param {...Iterable} iterables - One or more iterable objects (like Set
|
|
9
|
+
* or Array) whose elements will be added to the set.
|
|
10
|
+
*/
|
|
11
|
+
concat(...iterables) {
|
|
12
|
+
for (const iterable of iterables) {
|
|
13
|
+
if (typeof iterable === 'string' ||
|
|
14
|
+
!Reflect.has(iterable, Symbol.iterator)) {
|
|
15
|
+
this.add(iterable);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
for (const element of iterable) {
|
|
19
|
+
this.add(element);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
* Checks to see if any value within the `Set` loosely equals the supplied
|
|
25
|
+
* value.
|
|
26
|
+
*
|
|
27
|
+
* @param {*} value any value that might be loosely equal to an item in the
|
|
28
|
+
* set, as opposed to {@link Set.has} which is the equivalent of a strict or
|
|
29
|
+
* triple equals (`===`) check
|
|
30
|
+
* @returns {boolean} `true` if any value within the set is loosely equal to
|
|
31
|
+
* the supplied value, `false` otherwise
|
|
32
|
+
*/
|
|
33
|
+
contains(value) {
|
|
34
|
+
for (const element of this) {
|
|
35
|
+
if (value == element) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* Checks if every element in the set passes the test implemented by the
|
|
43
|
+
* provided function. The function is called with each element of the set.
|
|
44
|
+
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
45
|
+
*
|
|
46
|
+
* @param {Function} everyFn - The function to test each element. Receives
|
|
47
|
+
* the element, index (always NaN), and the set itself.
|
|
48
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
49
|
+
* `everyFn`.
|
|
50
|
+
* @throws {TypeError} If `everyFn` is not a function.
|
|
51
|
+
* @returns {boolean} True if every element passes the test, false otherwise.
|
|
52
|
+
*/
|
|
53
|
+
every(everyFn, thisArg) {
|
|
54
|
+
if (typeof everyFn !== 'function') {
|
|
55
|
+
throw new TypeError(`everyFn must be a function! Received ${String(everyFn)}`);
|
|
56
|
+
}
|
|
57
|
+
let found = 0;
|
|
58
|
+
for (const element of this) {
|
|
59
|
+
if (everyFn.call(thisArg, element, NaN, this)) {
|
|
60
|
+
found++;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return (found === this.size);
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Finds the first element in the set satisfying the provided testing
|
|
67
|
+
* function. If no elements satisfy the testing function, undefined is
|
|
68
|
+
* returned. The function is called with each element of the set.
|
|
69
|
+
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
70
|
+
*
|
|
71
|
+
* @param {Function} findFn - The function to execute on each element. It
|
|
72
|
+
* receives the element, index (always NaN), and the set itself.
|
|
73
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
74
|
+
* `findFn`.
|
|
75
|
+
* @throws {TypeError} If `findFn` is not a function.
|
|
76
|
+
* @returns {*} The first element that satisfies `findFn`, or undefined.
|
|
77
|
+
*/
|
|
78
|
+
find(findFn, thisArg) {
|
|
79
|
+
if (typeof findFn !== 'function') {
|
|
80
|
+
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
|
|
81
|
+
}
|
|
82
|
+
for (const element of this) {
|
|
83
|
+
const match = findFn.call(thisArg, element, NaN, this);
|
|
84
|
+
if (match) {
|
|
85
|
+
return element;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Finds the last element in the set satisfying the provided testing function.
|
|
92
|
+
* If no elements satisfy the testing function, undefined is returned. The
|
|
93
|
+
* function is called with each element of the set in reverse order.
|
|
94
|
+
* Note: Since sets do not have indices, the index parameter is always NaN.
|
|
95
|
+
*
|
|
96
|
+
* @param {Function} findFn - The function to execute on each element. It
|
|
97
|
+
* receives the element, index (always NaN), and the set itself.
|
|
98
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
99
|
+
* `findFn`.
|
|
100
|
+
* @throws {TypeError} If `findFn` is not a function.
|
|
101
|
+
* @returns {*} The last element that satisfies `findFn`, or undefined.
|
|
102
|
+
*/
|
|
103
|
+
findLast(findFn, thisArg) {
|
|
104
|
+
if (typeof findFn !== 'function') {
|
|
105
|
+
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
|
|
106
|
+
}
|
|
107
|
+
const found = [];
|
|
108
|
+
for (const element of this) {
|
|
109
|
+
const match = findFn.call(thisArg, element, NaN, this);
|
|
110
|
+
if (match) {
|
|
111
|
+
found.push(element);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (found.length) {
|
|
115
|
+
return found[found.length - 1];
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* A getter property that returns the number of elements in the set.
|
|
121
|
+
* This is an alias for the `size` property of the set.
|
|
122
|
+
*
|
|
123
|
+
* @returns {number} The number of elements in the set.
|
|
124
|
+
*/
|
|
125
|
+
get length() {
|
|
126
|
+
return this.size;
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Creates a new array populated with the results of calling the provided
|
|
130
|
+
* function on every element in the set. The function is called with each
|
|
131
|
+
* element of the set. Note: Since sets do not have indices, the index
|
|
132
|
+
* parameter is always NaN.
|
|
133
|
+
*
|
|
134
|
+
* @param {Function} mapFn - The function to execute on each element. It
|
|
135
|
+
* receives the element, index (always NaN), and the set itself.
|
|
136
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
137
|
+
* `mapFn`.
|
|
138
|
+
* @throws {TypeError} If `mapFn` is not a function.
|
|
139
|
+
* @returns {Array} A new array with each element being the result of the
|
|
140
|
+
* `mapFn`.
|
|
141
|
+
*/
|
|
142
|
+
map(mapFn, thisArg) {
|
|
143
|
+
if (typeof mapFn !== 'function') {
|
|
144
|
+
throw new TypeError(`mapFn must be a function! Received ${String(mapFn)}`);
|
|
145
|
+
}
|
|
146
|
+
const transformed = [];
|
|
147
|
+
for (const element of this) {
|
|
148
|
+
transformed.push(mapFn.call(thisArg, element, NaN, this));
|
|
149
|
+
}
|
|
150
|
+
return transformed;
|
|
151
|
+
},
|
|
152
|
+
/**
|
|
153
|
+
* Applies a function against an accumulator and each element in the set to
|
|
154
|
+
* reduce it to a single value. The function is called with each element of
|
|
155
|
+
* the set. Note: Since sets do not have indices, the index parameter is
|
|
156
|
+
* always NaN.
|
|
157
|
+
*
|
|
158
|
+
* @param {Function} reduceFn - The function to execute on each element. It
|
|
159
|
+
* receives the accumulator, element, index (always NaN), and the set itself.
|
|
160
|
+
* @param {*} initialValue - The initial value to start reducing from.
|
|
161
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
162
|
+
* `reduceFn`.
|
|
163
|
+
* @throws {TypeError} If `reduceFn` is not a function.
|
|
164
|
+
* @returns {*} The reduced value.
|
|
165
|
+
*/
|
|
166
|
+
reduce(reduceFn, initialValue, thisArg) {
|
|
167
|
+
if (typeof reduceFn !== 'function') {
|
|
168
|
+
throw new TypeError(`reduceFn must be a Function! Received ${String(reduceFn)}`);
|
|
169
|
+
}
|
|
170
|
+
let accumulator = initialValue;
|
|
171
|
+
for (const element of this) {
|
|
172
|
+
accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this);
|
|
173
|
+
}
|
|
174
|
+
return accumulator;
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* Tests whether at least one element in the set passes the test implemented
|
|
178
|
+
* by the provided function. The function is called with each element of the
|
|
179
|
+
* set. Note: Since sets do not have indices, the index parameter is always NaN.
|
|
180
|
+
*
|
|
181
|
+
* @param {Function} someFn - The function to test each element. It receives
|
|
182
|
+
* the element, index (always NaN), and the set itself.
|
|
183
|
+
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
|
|
184
|
+
* `someFn`.
|
|
185
|
+
* @throws {TypeError} If `someFn` is not a function.
|
|
186
|
+
* @returns {boolean} True if at least one element passes the test, false
|
|
187
|
+
* otherwise.
|
|
188
|
+
*/
|
|
189
|
+
some(someFn, thisArg) {
|
|
190
|
+
if (typeof someFn !== 'function') {
|
|
191
|
+
throw new TypeError(`someFn must be a function! Received ${String(someFn)}`);
|
|
192
|
+
}
|
|
193
|
+
for (const element of this) {
|
|
194
|
+
if (someFn.call(thisArg, element, NaN, this)) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
//# sourceMappingURL=setextensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setextensions.js","sourceRoot":"","sources":["../../src/setextensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE;IAC7D;;;;;;;OAOG;IACH,MAAM,CAAC,GAAG,SAAS;QACjB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,IACE,OAAO,QAAQ,KAAK,QAAQ;gBAC5B,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,EACvC,CAAC;gBACD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;gBAClB,SAAQ;YACV,CAAC;YAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAC/B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAK;QACZ,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;gBACrB,OAAO,IAAI,CAAA;YACb,CAAC;QAC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