@nejs/basic-extensions 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +518 -103
  2. package/dist/@nejs/basic-extensions.bundle.1.8.0.js +4 -0
  3. package/dist/@nejs/basic-extensions.bundle.1.8.0.js.map +7 -0
  4. package/dist/cjs/functionextensions.d.ts +1 -0
  5. package/dist/cjs/functionextensions.js +128 -18
  6. package/dist/cjs/functionextensions.js.map +1 -1
  7. package/dist/cjs/index.d.ts +5 -2
  8. package/dist/cjs/index.js +28 -5
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/newClasses/deferred.d.ts +126 -0
  11. package/dist/cjs/newClasses/deferred.js +306 -0
  12. package/dist/cjs/newClasses/deferred.js.map +1 -0
  13. package/dist/cjs/setextensions.d.ts +2 -0
  14. package/dist/cjs/setextensions.js +204 -0
  15. package/dist/cjs/setextensions.js.map +1 -0
  16. package/dist/mjs/functionextensions.d.ts +1 -0
  17. package/dist/mjs/functionextensions.js +127 -17
  18. package/dist/mjs/functionextensions.js.map +1 -1
  19. package/dist/mjs/index.d.ts +5 -2
  20. package/dist/mjs/index.js +29 -6
  21. package/dist/mjs/index.js.map +1 -1
  22. package/dist/mjs/newClasses/deferred.d.ts +126 -0
  23. package/dist/mjs/newClasses/deferred.js +230 -0
  24. package/dist/mjs/newClasses/deferred.js.map +1 -0
  25. package/dist/mjs/setextensions.d.ts +2 -0
  26. package/dist/mjs/setextensions.js +201 -0
  27. package/dist/mjs/setextensions.js.map +1 -0
  28. package/docs/index.html +6119 -3461
  29. package/package.json +7 -4
  30. package/src/functionextensions.js +150 -24
  31. package/src/index.js +35 -6
  32. package/src/newClasses/deferred.js +253 -0
  33. package/src/setextensions.js +242 -0
  34. package/tests/newClasses/deferred.test.js +86 -0
  35. package/tests/setextensions.test.js +89 -0
  36. package/dist/@nejs/basic-extensions.bundle.1.6.1.js +0 -4
  37. package/dist/@nejs/basic-extensions.bundle.1.6.1.js.map +0 -7
@@ -0,0 +1,306 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _Deferred_promise, _Deferred_reject, _Deferred_resolve, _Deferred_settled;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DeferredExtension = exports.Deferred = void 0;
16
+ const extension_1 = require("@nejs/extension");
17
+ /**
18
+ * Deferreds, which were first introduced by jQuery for browsers in the early
19
+ * 2000s, are a way to manage asynchronous operations. They have been widely
20
+ * used and replicated by engineers since then. Although the Promise class in
21
+ * modern JavaScript provides a static method called `withResolvers` that
22
+ * returns an object with similar properties to a Deferred, it is not directly
23
+ * supported by Node.js.
24
+ *
25
+ * ```
26
+ * const withResolvers = Promise.withResolvers()
27
+ * Reflect.has(withResolvers, 'promise') // true
28
+ * Reflect.has(withResolvers, 'resolve') // true
29
+ * Reflect.has(withResolvers, 'reject') // true
30
+ * ```
31
+ *
32
+ * This Deferred class extends the Promise class, allowing it to capture the
33
+ * value or reason for easy access after resolution, akin to
34
+ * {@link Promise.withResolvers}. As it extends {@link Promise}, it is
35
+ * 'thenable' and works with `await` as if it were a native Promise. This
36
+ * allows seamless integration with code expecting Promise-like objects.
37
+ */
38
+ class Deferred extends Promise {
39
+ /**
40
+ * The constructor for Deferred instances. By default, a new Deferred will
41
+ * have three important properties: `promise`, `resolve`, and `reject`.
42
+ *
43
+ * The constructor takes an object called `options`. It can have the
44
+ * following properties:
45
+ *
46
+ * ```
47
+ * interface BaseDeferredOptions {
48
+ * // Deferreds store the value or reason. To turn this off, pass true
49
+ * // to this option.
50
+ * doNotTrackAnswers?: boolean;
51
+ * }
52
+ *
53
+ * interface ResolveDeferredOptions {
54
+ * // Passing in an option object with a resolve value will auto resolve
55
+ * // the Deferred with your value. An error will be raised if both
56
+ * // resolve and reject are supplied at the same time.
57
+ * resolve?: (value: any) => void;
58
+ * }
59
+ *
60
+ * interface RejectDeferredOptions {
61
+ * // Passing in an option object with a reject reason will auto reject
62
+ * // the Deferred with your reason. An error will be raised if both
63
+ * // resolve and reject are supplied at the same time.
64
+ * reject?: (reason: any) => void;
65
+ * }
66
+ *
67
+ * type DeferredOptions = BaseDeferredOptions &
68
+ * (ResolveDeferredOptions | RejectDeferredOptions)
69
+ * ```
70
+ *
71
+ * @param {object} options see above for examples on supported options, but
72
+ * when supplied, the constructor can take instructions on how to auto
73
+ * resolve or reject the deferred created here.
74
+ */
75
+ constructor(options) {
76
+ // Check if options is an object, if not, assign an empty object to config
77
+ const config = (options && typeof (options) === 'object'
78
+ ? options
79
+ : {});
80
+ // Throw an error if both resolve and reject options are provided
81
+ if (config?.resolve && config?.reject) {
82
+ throw new TypeError('resolve and reject options cannot be simultaneously provided');
83
+ }
84
+ // Create an empty object to store the resolve and reject functions
85
+ let _resolve, _reject;
86
+ // Create a new promise and assign its resolve and reject functions to resolvers
87
+ super((resolve, reject) => {
88
+ _resolve = resolve;
89
+ _reject = reject;
90
+ if (config?.executor && typeof (config?.executor) === 'function') {
91
+ config?.executor(resolve, reject);
92
+ }
93
+ });
94
+ /**
95
+ * The promise backing this deferred object. Created when the constructor
96
+ * runs, this promise is what all `Promise.prototype` functions are routed
97
+ * to.
98
+ *
99
+ * @type {Promise}
100
+ */
101
+ _Deferred_promise.set(this, null
102
+ /**
103
+ * The reject() resolver that will be assigned when a new instance is
104
+ * created. Invoking this function with or without a `reason` will cause
105
+ * the deferred's promise to be settled.
106
+ *
107
+ * @type {function}
108
+ */
109
+ );
110
+ /**
111
+ * The reject() resolver that will be assigned when a new instance is
112
+ * created. Invoking this function with or without a `reason` will cause
113
+ * the deferred's promise to be settled.
114
+ *
115
+ * @type {function}
116
+ */
117
+ _Deferred_reject.set(this, null
118
+ /**
119
+ * The resolve() resolver that will be assigned when a new instance is
120
+ * created. Invoking this function with or without a `value` will cause
121
+ * the deferred's promise to be settled.
122
+ *
123
+ * @type {function}
124
+ */
125
+ );
126
+ /**
127
+ * The resolve() resolver that will be assigned when a new instance is
128
+ * created. Invoking this function with or without a `value` will cause
129
+ * the deferred's promise to be settled.
130
+ *
131
+ * @type {function}
132
+ */
133
+ _Deferred_resolve.set(this, null
134
+ /**
135
+ * When the Deferred is settled with {@link Deferred.resolve}, the `value`
136
+ * passed to that function will be set here as well.
137
+ *
138
+ * @type {*}
139
+ */
140
+ );
141
+ /**
142
+ * When the Deferred is settled with {@link Deferred.resolve}, the `value`
143
+ * passed to that function will be set here as well.
144
+ *
145
+ * @type {*}
146
+ */
147
+ this.value = null;
148
+ /**
149
+ * When the Deferred is settled with {@link Deferred.reject}, the `reason`
150
+ * passed to that rejection will also be stored here.
151
+ *
152
+ * @type {*}
153
+ */
154
+ this.reason = null;
155
+ /**
156
+ * When either {@link Deferred.resolve} or {@link Deferred.reject} are called,
157
+ * this property is set to `true`. Its current status at any time can be
158
+ * queried using the {@link Deferred.settled} getter.
159
+ *
160
+ * @type {boolean}
161
+ */
162
+ _Deferred_settled.set(this, false
163
+ /**
164
+ * The constructor for Deferred instances. By default, a new Deferred will
165
+ * have three important properties: `promise`, `resolve`, and `reject`.
166
+ *
167
+ * The constructor takes an object called `options`. It can have the
168
+ * following properties:
169
+ *
170
+ * ```
171
+ * interface BaseDeferredOptions {
172
+ * // Deferreds store the value or reason. To turn this off, pass true
173
+ * // to this option.
174
+ * doNotTrackAnswers?: boolean;
175
+ * }
176
+ *
177
+ * interface ResolveDeferredOptions {
178
+ * // Passing in an option object with a resolve value will auto resolve
179
+ * // the Deferred with your value. An error will be raised if both
180
+ * // resolve and reject are supplied at the same time.
181
+ * resolve?: (value: any) => void;
182
+ * }
183
+ *
184
+ * interface RejectDeferredOptions {
185
+ * // Passing in an option object with a reject reason will auto reject
186
+ * // the Deferred with your reason. An error will be raised if both
187
+ * // resolve and reject are supplied at the same time.
188
+ * reject?: (reason: any) => void;
189
+ * }
190
+ *
191
+ * type DeferredOptions = BaseDeferredOptions &
192
+ * (ResolveDeferredOptions | RejectDeferredOptions)
193
+ * ```
194
+ *
195
+ * @param {object} options see above for examples on supported options, but
196
+ * when supplied, the constructor can take instructions on how to auto
197
+ * resolve or reject the deferred created here.
198
+ */
199
+ );
200
+ // Define the resolve function for the Deferred instance
201
+ __classPrivateFieldSet(this, _Deferred_resolve, (value) => {
202
+ // If doNotTrackAnswers is not set to true, store the value
203
+ if (config?.doNotTrackAnswers !== true) {
204
+ this.value = value;
205
+ }
206
+ // Mark the Deferred instance as settled
207
+ __classPrivateFieldSet(this, _Deferred_settled, true, "f");
208
+ // Resolve the promise with the provided value
209
+ return _resolve(value);
210
+ }, "f");
211
+ // Define the reject function for the Deferred instance
212
+ __classPrivateFieldSet(this, _Deferred_reject, async (reason) => {
213
+ // If doNotTrackAnswers is not set to true, store the reason
214
+ if (config?.doNotTrackAnswers !== true) {
215
+ this.reason = reason;
216
+ }
217
+ // Mark the Deferred instance as settled
218
+ __classPrivateFieldSet(this, _Deferred_settled, true, "f");
219
+ // Reject the promise with the provided reason
220
+ return _reject(reason);
221
+ }, "f");
222
+ __classPrivateFieldSet(this, _Deferred_promise, this, "f");
223
+ // If a resolve option is provided, resolve the Deferred instance with it
224
+ if (config?.resolve) {
225
+ __classPrivateFieldGet(this, _Deferred_resolve, "f").call(this, config?.resolve);
226
+ }
227
+ // If a reject option is provided, reject the Deferred instance with it
228
+ else if (config?.reject) {
229
+ __classPrivateFieldGet(this, _Deferred_reject, "f").call(this, config?.reject);
230
+ }
231
+ }
232
+ /**
233
+ * Returns a boolean value that indicates whether or not this Deferred
234
+ * has been settled (either resolve or reject have been invoked).
235
+ *
236
+ * @returns {boolean} `true` if either {@link Deferred.resolve} or
237
+ * {@link Deferred.reject} have been invoked; `false` otherwise
238
+ */
239
+ get settled() {
240
+ return __classPrivateFieldGet(this, _Deferred_settled, "f");
241
+ }
242
+ /**
243
+ * Accessor for the promise managed by this Deferred instance.
244
+ *
245
+ * This getter provides access to the internal promise which is controlled
246
+ * by the Deferred's resolve and reject methods. It allows external code to
247
+ * attach callbacks for the resolution or rejection of the Deferred without
248
+ * the ability to directly resolve or reject it.
249
+ *
250
+ * @returns {Promise} The promise controlled by this Deferred instance.
251
+ */
252
+ get promise() {
253
+ return __classPrivateFieldGet(this, _Deferred_promise, "f");
254
+ }
255
+ /**
256
+ * Resolves the Deferred with the given value. If the value is a thenable
257
+ * (i.e., has a "then" method), the Deferred will "follow" that thenable,
258
+ * adopting its eventual state; otherwise, the Deferred will be fulfilled
259
+ * with the value. This function behaves the same as Promise.resolve.
260
+ *
261
+ * @param {*} value - The value to resolve the Deferred with.
262
+ * @returns {Promise} A Promise that is resolved with the given value.
263
+ */
264
+ resolve(value) {
265
+ return __classPrivateFieldGet(this, _Deferred_resolve, "f").call(this, value);
266
+ }
267
+ /**
268
+ * Rejects the Deferred with the given reason. This function behaves the
269
+ * same as Promise.reject. The Deferred will be rejected with the provided
270
+ * reason.
271
+ *
272
+ * @param {*} reason - The reason to reject the Deferred with.
273
+ * @returns {Promise} A Promise that is rejected with the given reason.
274
+ */
275
+ reject(reason) {
276
+ return __classPrivateFieldGet(this, _Deferred_reject, "f").call(this, reason);
277
+ }
278
+ /**
279
+ * A getter for the species symbol which returns a custom DeferredPromise
280
+ * class. This class extends from Deferred and is used to ensure that the
281
+ * constructor signature matches that of a Promise. The executor function
282
+ * passed to the constructor of this class is used to initialize the Deferred
283
+ * object with resolve and reject functions, similar to how a Promise would
284
+ * be initialized.
285
+ *
286
+ * @returns {DeferredPromise} A DeferredPromise class that extends Deferred.
287
+ */
288
+ static get [(_Deferred_promise = new WeakMap(), _Deferred_reject = new WeakMap(), _Deferred_resolve = new WeakMap(), _Deferred_settled = new WeakMap(), Symbol.species)]() {
289
+ return class DeferredPromise extends Deferred {
290
+ /**
291
+ * The constructor for the DeferredPromise class.
292
+ * It takes an executor function which is used to initialize the Deferred.
293
+ *
294
+ * @param {Function} executor - A function that is passed with the resolve
295
+ * and reject functions. The executor is expected to initialize the
296
+ * Deferred by calling resolve or reject at some point.
297
+ */
298
+ constructor(executor) {
299
+ super({ executor });
300
+ }
301
+ };
302
+ }
303
+ }
304
+ exports.Deferred = Deferred;
305
+ exports.DeferredExtension = new extension_1.Extension(Deferred);
306
+ //# sourceMappingURL=deferred.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deferred.js","sourceRoot":"","sources":["../../../src/newClasses/deferred.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAA2C;AAE3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,QAAS,SAAQ,OAAO;IAqDnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,YAAY,OAAO;QACjB,0EAA0E;QAC1E,MAAM,MAAM,GAAG,CAAC,OAAO,IAAI,OAAM,CAAC,OAAO,CAAC,KAAK,QAAQ;YACrD,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,EAAE,CACL,CAAA;QAED,iEAAiE;QACjE,IAAI,MAAM,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;YACtC,MAAM,IAAI,SAAS,CACjB,8DAA8D,CAC/D,CAAA;QACH,CAAC;QAED,mEAAmE;QACnE,IAAI,QAAQ,EAAE,OAAO,CAAC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@@
1
+ export const SetPrototypeExtensions: Patch;
2
+ import { Patch } from '@nejs/extension';
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SetPrototypeExtensions = void 0;
4
+ const extension_1 = require("@nejs/extension");
5
+ exports.SetPrototypeExtensions = new extension_1.Patch(Set.prototype, {
6
+ /**
7
+ * Merges multiple iterables into the set. Each element from the iterables
8
+ * is added to the set, ensuring uniqueness of all elements. This method
9
+ * mutates the original set.
10
+ *
11
+ * @param {...Iterable} iterables - One or more iterable objects (like Set
12
+ * or Array) whose elements will be added to the set.
13
+ */
14
+ concat(...iterables) {
15
+ for (const iterable of iterables) {
16
+ if (typeof iterable === 'string' ||
17
+ !Reflect.has(iterable, Symbol.iterator)) {
18
+ this.add(iterable);
19
+ continue;
20
+ }
21
+ for (const element of iterable) {
22
+ this.add(element);
23
+ }
24
+ }
25
+ },
26
+ /**
27
+ * Checks to see if any value within the `Set` loosely equals the supplied
28
+ * value.
29
+ *
30
+ * @param {*} value any value that might be loosely equal to an item in the
31
+ * set, as opposed to {@link Set.has} which is the equivalent of a strict or
32
+ * triple equals (`===`) check
33
+ * @returns {boolean} `true` if any value within the set is loosely equal to
34
+ * the supplied value, `false` otherwise
35
+ */
36
+ contains(value) {
37
+ for (const element of this) {
38
+ if (value == element) {
39
+ return true;
40
+ }
41
+ }
42
+ return false;
43
+ },
44
+ /**
45
+ * Checks if every element in the set passes the test implemented by the
46
+ * provided function. The function is called with each element of the set.
47
+ * Note: Since sets do not have indices, the index parameter is always NaN.
48
+ *
49
+ * @param {Function} everyFn - The function to test each element. Receives
50
+ * the element, index (always NaN), and the set itself.
51
+ * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
52
+ * `everyFn`.
53
+ * @throws {TypeError} If `everyFn` is not a function.
54
+ * @returns {boolean} True if every element passes the test, false otherwise.
55
+ */
56
+ every(everyFn, thisArg) {
57
+ if (typeof everyFn !== 'function') {
58
+ throw new TypeError(`everyFn must be a function! Received ${String(everyFn)}`);
59
+ }
60
+ let found = 0;
61
+ for (const element of this) {
62
+ if (everyFn.call(thisArg, element, NaN, this)) {
63
+ found++;
64
+ }
65
+ }
66
+ return (found === this.size);
67
+ },
68
+ /**
69
+ * Finds the first element in the set satisfying the provided testing
70
+ * function. If no elements satisfy the testing function, undefined is
71
+ * returned. The function is called with each element of the set.
72
+ * Note: Since sets do not have indices, the index parameter is always NaN.
73
+ *
74
+ * @param {Function} findFn - The function to execute on each element. It
75
+ * receives the element, index (always NaN), and the set itself.
76
+ * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
77
+ * `findFn`.
78
+ * @throws {TypeError} If `findFn` is not a function.
79
+ * @returns {*} The first element that satisfies `findFn`, or undefined.
80
+ */
81
+ find(findFn, thisArg) {
82
+ if (typeof findFn !== 'function') {
83
+ throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
84
+ }
85
+ for (const element of this) {
86
+ const match = findFn.call(thisArg, element, NaN, this);
87
+ if (match) {
88
+ return element;
89
+ }
90
+ }
91
+ return undefined;
92
+ },
93
+ /**
94
+ * Finds the last element in the set satisfying the provided testing function.
95
+ * If no elements satisfy the testing function, undefined is returned. The
96
+ * function is called with each element of the set in reverse order.
97
+ * Note: Since sets do not have indices, the index parameter is always NaN.
98
+ *
99
+ * @param {Function} findFn - The function to execute on each element. It
100
+ * receives the element, index (always NaN), and the set itself.
101
+ * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
102
+ * `findFn`.
103
+ * @throws {TypeError} If `findFn` is not a function.
104
+ * @returns {*} The last element that satisfies `findFn`, or undefined.
105
+ */
106
+ findLast(findFn, thisArg) {
107
+ if (typeof findFn !== 'function') {
108
+ throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
109
+ }
110
+ const found = [];
111
+ for (const element of this) {
112
+ const match = findFn.call(thisArg, element, NaN, this);
113
+ if (match) {
114
+ found.push(element);
115
+ }
116
+ }
117
+ if (found.length) {
118
+ return found[found.length - 1];
119
+ }
120
+ return undefined;
121
+ },
122
+ /**
123
+ * A getter property that returns the number of elements in the set.
124
+ * This is an alias for the `size` property of the set.
125
+ *
126
+ * @returns {number} The number of elements in the set.
127
+ */
128
+ get length() {
129
+ return this.size;
130
+ },
131
+ /**
132
+ * Creates a new array populated with the results of calling the provided
133
+ * function on every element in the set. The function is called with each
134
+ * element of the set. Note: Since sets do not have indices, the index
135
+ * parameter is always NaN.
136
+ *
137
+ * @param {Function} mapFn - The function to execute on each element. It
138
+ * receives the element, index (always NaN), and the set itself.
139
+ * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
140
+ * `mapFn`.
141
+ * @throws {TypeError} If `mapFn` is not a function.
142
+ * @returns {Array} A new array with each element being the result of the
143
+ * `mapFn`.
144
+ */
145
+ map(mapFn, thisArg) {
146
+ if (typeof mapFn !== 'function') {
147
+ throw new TypeError(`mapFn must be a function! Received ${String(mapFn)}`);
148
+ }
149
+ const transformed = [];
150
+ for (const element of this) {
151
+ transformed.push(mapFn.call(thisArg, element, NaN, this));
152
+ }
153
+ return transformed;
154
+ },
155
+ /**
156
+ * Applies a function against an accumulator and each element in the set to
157
+ * reduce it to a single value. The function is called with each element of
158
+ * the set. Note: Since sets do not have indices, the index parameter is
159
+ * always NaN.
160
+ *
161
+ * @param {Function} reduceFn - The function to execute on each element. It
162
+ * receives the accumulator, element, index (always NaN), and the set itself.
163
+ * @param {*} initialValue - The initial value to start reducing from.
164
+ * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
165
+ * `reduceFn`.
166
+ * @throws {TypeError} If `reduceFn` is not a function.
167
+ * @returns {*} The reduced value.
168
+ */
169
+ reduce(reduceFn, initialValue, thisArg) {
170
+ if (typeof reduceFn !== 'function') {
171
+ throw new TypeError(`reduceFn must be a Function! Received ${String(reduceFn)}`);
172
+ }
173
+ let accumulator = initialValue;
174
+ for (const element of this) {
175
+ accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this);
176
+ }
177
+ return accumulator;
178
+ },
179
+ /**
180
+ * Tests whether at least one element in the set passes the test implemented
181
+ * by the provided function. The function is called with each element of the
182
+ * set. Note: Since sets do not have indices, the index parameter is always NaN.
183
+ *
184
+ * @param {Function} someFn - The function to test each element. It receives
185
+ * the element, index (always NaN), and the set itself.
186
+ * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
187
+ * `someFn`.
188
+ * @throws {TypeError} If `someFn` is not a function.
189
+ * @returns {boolean} True if at least one element passes the test, false
190
+ * otherwise.
191
+ */
192
+ some(someFn, thisArg) {
193
+ if (typeof someFn !== 'function') {
194
+ throw new TypeError(`someFn must be a function! Received ${String(someFn)}`);
195
+ }
196
+ for (const element of this) {
197
+ if (someFn.call(thisArg, element, NaN, this)) {
198
+ return true;
199
+ }
200
+ }
201
+ return false;
202
+ },
203
+ });
204
+ //# sourceMappingURL=setextensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setextensions.js","sourceRoot":"","sources":["../../src/setextensions.js"],"names":[],"mappings":";;;AAAA,+CAAwC;AAE3B,QAAA,sBAAsB,GAAG,IAAI,iBAAK,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,KAA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,WAAW,GAAG,YAAY,CAAA;QAC9B,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;QACvE,CAAC;QAED,OAAO,WAAW,CAAA;IACpB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,MAAM,EAAE,OAAO;QAClB,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,MAAM,IAAI,SAAS,CACjB,uCAAuC,MAAM,CAAC,MAAM,CAAC,EAAE,CACxD,CAAA;QACH,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;gBAC7C,OAAO,IAAI,CAAA;YACb,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF,CAAC,CAAA"}
@@ -8,4 +8,5 @@
8
8
  * capabilities of function handling and introspection in JavaScript.
9
9
  */
10
10
  export const FunctionExtensions: Patch;
11
+ export const FunctionPrototypeExtensions: Patch;
11
12
  import { Patch } from '@nejs/extension';