@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,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FunctionExtensions = void 0;
|
|
3
|
+
exports.FunctionPrototypeExtensions = exports.FunctionExtensions = void 0;
|
|
4
4
|
const extension_1 = require("@nejs/extension");
|
|
5
|
+
const objectextensions_js_1 = require("./objectextensions.js");
|
|
6
|
+
const { getStringTag } = objectextensions_js_1.ObjectExtensions.patches;
|
|
5
7
|
/**
|
|
6
8
|
* The `FunctionExtensions` class is a patch applied to the built-in JavaScript
|
|
7
9
|
* `Function` constructor. It extends `Function` with additional utility methods
|
|
@@ -12,6 +14,68 @@ const extension_1 = require("@nejs/extension");
|
|
|
12
14
|
* capabilities of function handling and introspection in JavaScript.
|
|
13
15
|
*/
|
|
14
16
|
exports.FunctionExtensions = new extension_1.Patch(Function, {
|
|
17
|
+
/**
|
|
18
|
+
* Determines if a given value is an asynchronous function. It checks if the
|
|
19
|
+
* value is an instance of `Function` and if its string representation
|
|
20
|
+
* includes the keyword 'Async'. This method is particularly useful for
|
|
21
|
+
* identifying async functions.
|
|
22
|
+
*
|
|
23
|
+
* @param {*} value - The value to be checked.
|
|
24
|
+
* @returns {boolean} Returns `true` if the value is an async function,
|
|
25
|
+
* otherwise `false`.
|
|
26
|
+
*/
|
|
27
|
+
isAsync(value) {
|
|
28
|
+
const stringTag = /(\w+)]/g.exec(Object.prototype.toString.call(value))[1];
|
|
29
|
+
return (value instanceof Function &&
|
|
30
|
+
stringTag.includes('Async'));
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* The function checks if a given value is an async generator function
|
|
34
|
+
*
|
|
35
|
+
* @param {any} value - The `value` parameter is the value that we want to
|
|
36
|
+
* check if it is a generator function.
|
|
37
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
38
|
+
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
|
|
39
|
+
*/
|
|
40
|
+
isAsyncGenerator(value) {
|
|
41
|
+
const stringTag = getStringTag(value);
|
|
42
|
+
return (value instanceof Function &&
|
|
43
|
+
stringTag == 'AsyncGeneratorFunction');
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Checks if a given value is an arrow function. It verifies if the value is
|
|
47
|
+
* an instance of `Function`, if its string representation includes the '=>'
|
|
48
|
+
* symbol, and if it lacks a prototype, which is a characteristic of arrow
|
|
49
|
+
* functions in JavaScript.
|
|
50
|
+
*
|
|
51
|
+
* @param {*} value - The value to be checked.
|
|
52
|
+
* @returns {boolean} Returns `true` if the value is an arrow function,
|
|
53
|
+
* otherwise `false`.
|
|
54
|
+
*/
|
|
55
|
+
isBigArrow(value) {
|
|
56
|
+
return (value instanceof Function &&
|
|
57
|
+
String(value).includes('=>') &&
|
|
58
|
+
!String(value).startsWith('bound') &&
|
|
59
|
+
!Reflect.has(value, 'prototype'));
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Determines if a given value is a bound function. Bound functions are
|
|
63
|
+
* created using the `Function.prototype.bind` method, which allows setting
|
|
64
|
+
* the `this` value at the time of binding. This method checks if the value
|
|
65
|
+
* is an instance of `Function`, if its string representation starts with
|
|
66
|
+
* 'bound', and if it lacks a `prototype` property. These characteristics
|
|
67
|
+
* are indicative of bound functions in JavaScript.
|
|
68
|
+
*
|
|
69
|
+
* @param {*} value - The value to be checked, typically a function.
|
|
70
|
+
* @returns {boolean} Returns `true` if the value is a bound function,
|
|
71
|
+
* otherwise `false`. Bound functions have a specific format in their
|
|
72
|
+
* string representation and do not have their own `prototype` property.
|
|
73
|
+
*/
|
|
74
|
+
isBound(value) {
|
|
75
|
+
return (value instanceof Function &&
|
|
76
|
+
String(value).startsWith('bound') &&
|
|
77
|
+
!Reflect.has(value, 'prototype'));
|
|
78
|
+
},
|
|
15
79
|
/**
|
|
16
80
|
* Determines if a given value is a class. It checks if the value is an
|
|
17
81
|
* instance of `Function` and if its string representation includes the
|
|
@@ -35,22 +99,43 @@ exports.FunctionExtensions = new extension_1.Patch(Function, {
|
|
|
35
99
|
* otherwise `false`.
|
|
36
100
|
*/
|
|
37
101
|
isFunction(value) {
|
|
38
|
-
return value instanceof Function;
|
|
102
|
+
return value instanceof Function && !Function.isClass(value);
|
|
39
103
|
},
|
|
104
|
+
/**
|
|
105
|
+
* The function checks if a given value is a generator function
|
|
106
|
+
*
|
|
107
|
+
* @param {any} value - The `value` parameter is the value that we want to
|
|
108
|
+
* check if it is a generator function.
|
|
109
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
110
|
+
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
|
|
111
|
+
*/
|
|
112
|
+
isGenerator(value) {
|
|
113
|
+
const stringTag = getStringTag(value);
|
|
114
|
+
return (value instanceof Function &&
|
|
115
|
+
stringTag == 'GeneratorFunction');
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
exports.FunctionPrototypeExtensions = new extension_1.Patch(Function.prototype, {
|
|
40
119
|
/**
|
|
41
120
|
* Determines if a given value is an asynchronous function. It checks if the
|
|
42
121
|
* value is an instance of `Function` and if its string representation
|
|
43
122
|
* includes the keyword 'Async'. This method is particularly useful for
|
|
44
123
|
* identifying async functions.
|
|
45
124
|
*
|
|
46
|
-
* @param {*} value - The value to be checked.
|
|
47
125
|
* @returns {boolean} Returns `true` if the value is an async function,
|
|
48
126
|
* otherwise `false`.
|
|
49
127
|
*/
|
|
50
|
-
isAsync(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
128
|
+
get isAsync() {
|
|
129
|
+
return Function.isAsync(this);
|
|
130
|
+
},
|
|
131
|
+
/**
|
|
132
|
+
* The function checks if a given value is an async generator function
|
|
133
|
+
*
|
|
134
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
135
|
+
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
|
|
136
|
+
*/
|
|
137
|
+
get isAsyncGenerator() {
|
|
138
|
+
return Function.isAsyncGenerator(this);
|
|
54
139
|
},
|
|
55
140
|
/**
|
|
56
141
|
* Checks if a given value is an arrow function. It verifies if the value is
|
|
@@ -58,15 +143,11 @@ exports.FunctionExtensions = new extension_1.Patch(Function, {
|
|
|
58
143
|
* symbol, and if it lacks a prototype, which is a characteristic of arrow
|
|
59
144
|
* functions in JavaScript.
|
|
60
145
|
*
|
|
61
|
-
* @param {*} value - The value to be checked.
|
|
62
146
|
* @returns {boolean} Returns `true` if the value is an arrow function,
|
|
63
147
|
* otherwise `false`.
|
|
64
148
|
*/
|
|
65
|
-
isBigArrow(
|
|
66
|
-
return (
|
|
67
|
-
String(value).includes('=>') &&
|
|
68
|
-
!String(value).startsWith('bound') &&
|
|
69
|
-
!Reflect.has(value, 'prototype'));
|
|
149
|
+
get isBigArrow() {
|
|
150
|
+
return Function.isBigArrow(this);
|
|
70
151
|
},
|
|
71
152
|
/**
|
|
72
153
|
* Determines if a given value is a bound function. Bound functions are
|
|
@@ -76,15 +157,44 @@ exports.FunctionExtensions = new extension_1.Patch(Function, {
|
|
|
76
157
|
* 'bound', and if it lacks a `prototype` property. These characteristics
|
|
77
158
|
* are indicative of bound functions in JavaScript.
|
|
78
159
|
*
|
|
79
|
-
* @param {*} value - The value to be checked, typically a function.
|
|
80
160
|
* @returns {boolean} Returns `true` if the value is a bound function,
|
|
81
161
|
* otherwise `false`. Bound functions have a specific format in their
|
|
82
162
|
* string representation and do not have their own `prototype` property.
|
|
83
163
|
*/
|
|
84
|
-
isBound(
|
|
85
|
-
return (
|
|
86
|
-
|
|
87
|
-
|
|
164
|
+
get isBound() {
|
|
165
|
+
return Function.isBound(this);
|
|
166
|
+
},
|
|
167
|
+
/**
|
|
168
|
+
* Determines if a given value is a class. It checks if the value is an
|
|
169
|
+
* instance of `Function` and if its string representation includes the
|
|
170
|
+
* keyword 'class'. This method is useful for distinguishing classes from
|
|
171
|
+
* other function types in JavaScript.
|
|
172
|
+
*
|
|
173
|
+
* @returns {boolean} Returns `true` if the value is a class, otherwise
|
|
174
|
+
* `false`.
|
|
175
|
+
*/
|
|
176
|
+
get isClass() {
|
|
177
|
+
return Function.isClass(this);
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Checks if a given value is a regular function. This method verifies if
|
|
181
|
+
* the value is an instance of `Function`, which includes regular functions,
|
|
182
|
+
* classes, and async functions but excludes arrow functions.
|
|
183
|
+
*
|
|
184
|
+
* @returns {boolean} Returns `true` if the value is a regular function,
|
|
185
|
+
* otherwise `false`.
|
|
186
|
+
*/
|
|
187
|
+
get isFunction() {
|
|
188
|
+
return Function.isFunction(this);
|
|
189
|
+
},
|
|
190
|
+
/**
|
|
191
|
+
* The function checks if a given value is a generator function
|
|
192
|
+
*
|
|
193
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
194
|
+
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
|
|
195
|
+
*/
|
|
196
|
+
get isGenerator() {
|
|
197
|
+
return Function.isGenerator(this);
|
|
88
198
|
},
|
|
89
199
|
});
|
|
90
200
|
//# sourceMappingURL=functionextensions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functionextensions.js","sourceRoot":"","sources":["../../src/functionextensions.js"],"names":[],"mappings":";;;AAAA,+CAAuC;
|
|
1
|
+
{"version":3,"file":"functionextensions.js","sourceRoot":"","sources":["../../src/functionextensions.js"],"names":[],"mappings":";;;AAAA,+CAAuC;AACvC,+DAAwD;AAExD,MAAM,EAAE,YAAY,EAAE,GAAG,sCAAgB,CAAC,OAAO,CAAA;AAEjD;;;;;;;;GAQG;AACU,QAAA,kBAAkB,GAAG,IAAI,iBAAK,CAAC,QAAQ,EAAE;IACpD;;;;;;;;;OASG;IACH,OAAO,CAAC,KAAK;QACX,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC1E,OAAO,CACL,KAAK,YAAY,QAAQ;YACzB,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAC5B,CAAA;IACH,CAAC;IAED;;;;;;;OAOG;IACH,gBAAgB,CAAC,KAAK;QACpB,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;QAErC,OAAO,CACL,KAAK,YAAY,QAAQ;YACzB,SAAS,IAAI,wBAAwB,CACtC,CAAA;IACH,CAAC;IAED;;;;;;;;;OASG;IACH,UAAU,CAAC,KAAK;QACd,OAAO,CACL,KAAK,YAAY,QAAQ;YACzB,MAAM,CAAC,KAAK,CAAC,CAAC,QAA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,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,IAAI,OAAO;QACT,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;IAED;;;;;;;;OAQG;IACH,IAAI,OAAO;QACT,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,UAAU;QACZ,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IAED;;;;;OAKG;IACH,IAAI,WAAW;QACb,OAAO,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;CACF,CAAC,CAAA"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Controls = exports.Patches = exports.Extensions = exports.all = void 0;
|
|
|
4
4
|
const functionextensions_js_1 = require("./functionextensions.js");
|
|
5
5
|
const objectextensions_js_1 = require("./objectextensions.js");
|
|
6
6
|
const mapextensions_js_1 = require("./mapextensions.js");
|
|
7
|
+
const setextensions_js_1 = require("./setextensions.js");
|
|
7
8
|
const reflectextensions_js_1 = require("./reflectextensions.js");
|
|
8
9
|
const stringextensions_js_1 = require("./stringextensions.js");
|
|
9
10
|
const symbolextensions_js_1 = require("./symbolextensions.js");
|
|
@@ -21,8 +22,10 @@ const Patches = new Map([
|
|
|
21
22
|
[String, stringextensions_js_1.StringExtensions],
|
|
22
23
|
[Symbol, symbolextensions_js_1.SymbolExtensions],
|
|
23
24
|
[Object.prototype, objectextensions_js_1.ObjectPrototypeExtensions],
|
|
25
|
+
[Function.prototype, functionextensions_js_1.FunctionPrototypeExtensions],
|
|
24
26
|
[Array.prototype, arrayextensions_js_1.ArrayPrototypeExtensions],
|
|
25
27
|
[Map.prototype, mapextensions_js_1.MapPrototypeExtensions],
|
|
28
|
+
[Set.prototype, setextensions_js_1.SetPrototypeExtensions],
|
|
26
29
|
[globalThis, globals_js_1.GlobalFunctionsAndProps],
|
|
27
30
|
]);
|
|
28
31
|
exports.Patches = Patches;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;AAAA,mEAAyF;AACzF,+DAAmF;AACnF,yDAA2D;AAC3D,yDAA2D;AAC3D,iEAA0D;AAC1D,+DAAwD;AACxD,+DAAwD;AACxD,6DAA+D;AAC/D,8DAA6E;AAC7E,6CAAsD;AACtD,sDAAyD;AACzD,sDAAyD;AAEzD,oEAGsC;AAEtC,0DAGiC;AAEjC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC;IACtB,CAAC,MAAM,EAAE,sCAAgB,CAAC;IAC1B,CAAC,QAAQ,EAAE,0CAAkB,CAAC;IAC9B,CAAC,OAAO,EAAE,wCAAiB,CAAC;IAC5B,CAAC,MAAM,EAAE,sCAAgB,CAAC;IAC1B,CAAC,MAAM,EAAE,sCAAgB,CAAC;IAE1B,CAAC,MAAM,CAAC,SAAS,EAAE,+CAAyB,CAAC;IAC7C,CAAC,QAAQ,CAAC,SAAS,EAAE,mDAA2B,CAAC;IACjD,CAAC,KAAK,CAAC,SAAS,EAAE,6CAAwB,CAAC;IAC3C,CAAC,GAAG,CAAC,SAAS,EAAE,yCAAsB,CAAC;IACvC,CAAC,GAAG,CAAC,SAAS,EAAE,yCAAsB,CAAC;IACvC,CAAC,UAAU,EAAE,oCAAuB,CAAC;CACtC,CAAC,CAAA;AA6EA,0BAAO;AA3ET,MAAM,UAAU,GAAG;IACjB,CAAC,oCAAoB,CAAC,GAAG,CAAC,EAAE,oCAAoB;IAChD,CAAC,0CAAuB,CAAC,GAAG,CAAC,EAAE,0CAAuB;IACtD,CAAC,0CAAuB,CAAC,GAAG,CAAC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G,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,0BAAU,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,EAAH,WAAG;CACJ,CAAA;AAED,kBAAe,OAAO,CAAA"}
|
|
@@ -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,KAAK,IAAI,OAAO,EAAE,CAAC;gBACrB,OAAO,IAAI,CAAA;YACb,C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AAI,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"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Patch } from '@nejs/extension';
|
|
2
|
+
import { ObjectExtensions } from './objectextensions.js';
|
|
3
|
+
const { getStringTag } = ObjectExtensions.patches;
|
|
2
4
|
/**
|
|
3
5
|
* The `FunctionExtensions` class is a patch applied to the built-in JavaScript
|
|
4
6
|
* `Function` constructor. It extends `Function` with additional utility methods
|
|
@@ -9,6 +11,68 @@ import { Patch } from '@nejs/extension';
|
|
|
9
11
|
* capabilities of function handling and introspection in JavaScript.
|
|
10
12
|
*/
|
|
11
13
|
export const FunctionExtensions = new Patch(Function, {
|
|
14
|
+
/**
|
|
15
|
+
* Determines if a given value is an asynchronous function. It checks if the
|
|
16
|
+
* value is an instance of `Function` and if its string representation
|
|
17
|
+
* includes the keyword 'Async'. This method is particularly useful for
|
|
18
|
+
* identifying async functions.
|
|
19
|
+
*
|
|
20
|
+
* @param {*} value - The value to be checked.
|
|
21
|
+
* @returns {boolean} Returns `true` if the value is an async function,
|
|
22
|
+
* otherwise `false`.
|
|
23
|
+
*/
|
|
24
|
+
isAsync(value) {
|
|
25
|
+
const stringTag = /(\w+)]/g.exec(Object.prototype.toString.call(value))[1];
|
|
26
|
+
return (value instanceof Function &&
|
|
27
|
+
stringTag.includes('Async'));
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* The function checks if a given value is an async generator function
|
|
31
|
+
*
|
|
32
|
+
* @param {any} value - The `value` parameter is the value that we want to
|
|
33
|
+
* check if it is a generator function.
|
|
34
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
35
|
+
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
|
|
36
|
+
*/
|
|
37
|
+
isAsyncGenerator(value) {
|
|
38
|
+
const stringTag = getStringTag(value);
|
|
39
|
+
return (value instanceof Function &&
|
|
40
|
+
stringTag == 'AsyncGeneratorFunction');
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Checks if a given value is an arrow function. It verifies if the value is
|
|
44
|
+
* an instance of `Function`, if its string representation includes the '=>'
|
|
45
|
+
* symbol, and if it lacks a prototype, which is a characteristic of arrow
|
|
46
|
+
* functions in JavaScript.
|
|
47
|
+
*
|
|
48
|
+
* @param {*} value - The value to be checked.
|
|
49
|
+
* @returns {boolean} Returns `true` if the value is an arrow function,
|
|
50
|
+
* otherwise `false`.
|
|
51
|
+
*/
|
|
52
|
+
isBigArrow(value) {
|
|
53
|
+
return (value instanceof Function &&
|
|
54
|
+
String(value).includes('=>') &&
|
|
55
|
+
!String(value).startsWith('bound') &&
|
|
56
|
+
!Reflect.has(value, 'prototype'));
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Determines if a given value is a bound function. Bound functions are
|
|
60
|
+
* created using the `Function.prototype.bind` method, which allows setting
|
|
61
|
+
* the `this` value at the time of binding. This method checks if the value
|
|
62
|
+
* is an instance of `Function`, if its string representation starts with
|
|
63
|
+
* 'bound', and if it lacks a `prototype` property. These characteristics
|
|
64
|
+
* are indicative of bound functions in JavaScript.
|
|
65
|
+
*
|
|
66
|
+
* @param {*} value - The value to be checked, typically a function.
|
|
67
|
+
* @returns {boolean} Returns `true` if the value is a bound function,
|
|
68
|
+
* otherwise `false`. Bound functions have a specific format in their
|
|
69
|
+
* string representation and do not have their own `prototype` property.
|
|
70
|
+
*/
|
|
71
|
+
isBound(value) {
|
|
72
|
+
return (value instanceof Function &&
|
|
73
|
+
String(value).startsWith('bound') &&
|
|
74
|
+
!Reflect.has(value, 'prototype'));
|
|
75
|
+
},
|
|
12
76
|
/**
|
|
13
77
|
* Determines if a given value is a class. It checks if the value is an
|
|
14
78
|
* instance of `Function` and if its string representation includes the
|
|
@@ -32,22 +96,43 @@ export const FunctionExtensions = new Patch(Function, {
|
|
|
32
96
|
* otherwise `false`.
|
|
33
97
|
*/
|
|
34
98
|
isFunction(value) {
|
|
35
|
-
return value instanceof Function;
|
|
99
|
+
return value instanceof Function && !Function.isClass(value);
|
|
36
100
|
},
|
|
101
|
+
/**
|
|
102
|
+
* The function checks if a given value is a generator function
|
|
103
|
+
*
|
|
104
|
+
* @param {any} value - The `value` parameter is the value that we want to
|
|
105
|
+
* check if it is a generator function.
|
|
106
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
107
|
+
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
|
|
108
|
+
*/
|
|
109
|
+
isGenerator(value) {
|
|
110
|
+
const stringTag = getStringTag(value);
|
|
111
|
+
return (value instanceof Function &&
|
|
112
|
+
stringTag == 'GeneratorFunction');
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
export const FunctionPrototypeExtensions = new Patch(Function.prototype, {
|
|
37
116
|
/**
|
|
38
117
|
* Determines if a given value is an asynchronous function. It checks if the
|
|
39
118
|
* value is an instance of `Function` and if its string representation
|
|
40
119
|
* includes the keyword 'Async'. This method is particularly useful for
|
|
41
120
|
* identifying async functions.
|
|
42
121
|
*
|
|
43
|
-
* @param {*} value - The value to be checked.
|
|
44
122
|
* @returns {boolean} Returns `true` if the value is an async function,
|
|
45
123
|
* otherwise `false`.
|
|
46
124
|
*/
|
|
47
|
-
isAsync(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
125
|
+
get isAsync() {
|
|
126
|
+
return Function.isAsync(this);
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* The function checks if a given value is an async generator function
|
|
130
|
+
*
|
|
131
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
132
|
+
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
|
|
133
|
+
*/
|
|
134
|
+
get isAsyncGenerator() {
|
|
135
|
+
return Function.isAsyncGenerator(this);
|
|
51
136
|
},
|
|
52
137
|
/**
|
|
53
138
|
* Checks if a given value is an arrow function. It verifies if the value is
|
|
@@ -55,15 +140,11 @@ export const FunctionExtensions = new Patch(Function, {
|
|
|
55
140
|
* symbol, and if it lacks a prototype, which is a characteristic of arrow
|
|
56
141
|
* functions in JavaScript.
|
|
57
142
|
*
|
|
58
|
-
* @param {*} value - The value to be checked.
|
|
59
143
|
* @returns {boolean} Returns `true` if the value is an arrow function,
|
|
60
144
|
* otherwise `false`.
|
|
61
145
|
*/
|
|
62
|
-
isBigArrow(
|
|
63
|
-
return (
|
|
64
|
-
String(value).includes('=>') &&
|
|
65
|
-
!String(value).startsWith('bound') &&
|
|
66
|
-
!Reflect.has(value, 'prototype'));
|
|
146
|
+
get isBigArrow() {
|
|
147
|
+
return Function.isBigArrow(this);
|
|
67
148
|
},
|
|
68
149
|
/**
|
|
69
150
|
* Determines if a given value is a bound function. Bound functions are
|
|
@@ -73,15 +154,44 @@ export const FunctionExtensions = new Patch(Function, {
|
|
|
73
154
|
* 'bound', and if it lacks a `prototype` property. These characteristics
|
|
74
155
|
* are indicative of bound functions in JavaScript.
|
|
75
156
|
*
|
|
76
|
-
* @param {*} value - The value to be checked, typically a function.
|
|
77
157
|
* @returns {boolean} Returns `true` if the value is a bound function,
|
|
78
158
|
* otherwise `false`. Bound functions have a specific format in their
|
|
79
159
|
* string representation and do not have their own `prototype` property.
|
|
80
160
|
*/
|
|
81
|
-
isBound(
|
|
82
|
-
return (
|
|
83
|
-
|
|
84
|
-
|
|
161
|
+
get isBound() {
|
|
162
|
+
return Function.isBound(this);
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Determines if a given value is a class. It checks if the value is an
|
|
166
|
+
* instance of `Function` and if its string representation includes the
|
|
167
|
+
* keyword 'class'. This method is useful for distinguishing classes from
|
|
168
|
+
* other function types in JavaScript.
|
|
169
|
+
*
|
|
170
|
+
* @returns {boolean} Returns `true` if the value is a class, otherwise
|
|
171
|
+
* `false`.
|
|
172
|
+
*/
|
|
173
|
+
get isClass() {
|
|
174
|
+
return Function.isClass(this);
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* Checks if a given value is a regular function. This method verifies if
|
|
178
|
+
* the value is an instance of `Function`, which includes regular functions,
|
|
179
|
+
* classes, and async functions but excludes arrow functions.
|
|
180
|
+
*
|
|
181
|
+
* @returns {boolean} Returns `true` if the value is a regular function,
|
|
182
|
+
* otherwise `false`.
|
|
183
|
+
*/
|
|
184
|
+
get isFunction() {
|
|
185
|
+
return Function.isFunction(this);
|
|
186
|
+
},
|
|
187
|
+
/**
|
|
188
|
+
* The function checks if a given value is a generator function
|
|
189
|
+
*
|
|
190
|
+
* @returns {boolean} `true` if the value is an instance of a function and
|
|
191
|
+
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
|
|
192
|
+
*/
|
|
193
|
+
get isGenerator() {
|
|
194
|
+
return Function.isGenerator(this);
|
|
85
195
|
},
|
|
86
196
|
});
|
|
87
197
|
//# sourceMappingURL=functionextensions.js.map
|