@nejs/basic-extensions 2.6.0 → 2.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/.vscode/settings.json +5 -0
- package/README.md +6129 -1574
- package/dist/@nejs/basic-extensions.bundle.2.7.0.js +19 -0
- package/dist/@nejs/basic-extensions.bundle.2.7.0.js.map +7 -0
- package/dist/cjs/array.extensions.d.ts +39 -0
- package/dist/cjs/array.extensions.js +303 -0
- package/dist/cjs/array.extensions.js.map +1 -0
- package/dist/cjs/big.int.extension.d.ts +31 -0
- package/dist/cjs/big.int.extension.js +164 -0
- package/dist/cjs/big.int.extension.js.map +1 -0
- package/dist/cjs/{newClasses → classes}/asyncIterable.js +32 -44
- package/dist/cjs/classes/asyncIterable.js.map +1 -0
- package/dist/cjs/{newClasses → classes}/deferred.js +66 -138
- package/dist/cjs/classes/deferred.js.map +1 -0
- package/dist/cjs/{newClasses → classes}/descriptor.js +56 -90
- package/dist/cjs/classes/descriptor.js.map +1 -0
- package/dist/cjs/classes/index.d.ts +13 -0
- package/dist/cjs/classes/index.js +57 -0
- package/dist/cjs/classes/index.js.map +1 -0
- package/dist/cjs/classes/introspector.d.ts +20 -0
- package/dist/cjs/classes/introspector.js +130 -0
- package/dist/cjs/classes/introspector.js.map +1 -0
- package/dist/cjs/{newClasses → classes}/iterable.js +42 -63
- package/dist/cjs/classes/iterable.js.map +1 -0
- package/dist/cjs/classes/param.parser.d.ts +227 -0
- package/dist/cjs/classes/param.parser.js +242 -0
- package/dist/cjs/classes/param.parser.js.map +1 -0
- package/dist/cjs/classes/pluggable.proxy.d.ts +152 -0
- package/dist/cjs/classes/pluggable.proxy.js +444 -0
- package/dist/cjs/classes/pluggable.proxy.js.map +1 -0
- package/dist/cjs/{newClasses → classes}/refmap.js +18 -30
- package/dist/cjs/classes/refmap.js.map +1 -0
- package/dist/cjs/{newClasses → classes}/refset.js +28 -47
- package/dist/cjs/classes/refset.js.map +1 -0
- package/dist/cjs/classes/symkeys.d.ts +292 -0
- package/dist/cjs/classes/symkeys.js +424 -0
- package/dist/cjs/classes/symkeys.js.map +1 -0
- package/dist/cjs/classes/type.d.ts +56 -0
- package/dist/cjs/classes/type.js +405 -0
- package/dist/cjs/classes/type.js.map +1 -0
- package/dist/cjs/function.extensions.js +757 -0
- package/dist/cjs/function.extensions.js.map +1 -0
- package/dist/cjs/global.this.js +261 -0
- package/dist/cjs/global.this.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -3
- package/dist/cjs/index.js +62 -32
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/json.extensions.d.ts +2 -0
- package/dist/cjs/json.extensions.js +107 -0
- package/dist/cjs/json.extensions.js.map +1 -0
- package/dist/{mjs/mapextensions.d.ts → cjs/map.extensions.d.ts} +1 -0
- package/dist/cjs/map.extensions.js +142 -0
- package/dist/cjs/map.extensions.js.map +1 -0
- package/dist/cjs/number.extension.d.ts +44 -0
- package/dist/cjs/number.extension.js +260 -0
- package/dist/cjs/number.extension.js.map +1 -0
- package/dist/cjs/object.extensions.d.ts +62 -0
- package/dist/cjs/object.extensions.js +1116 -0
- package/dist/cjs/object.extensions.js.map +1 -0
- package/dist/cjs/proxy.extensions.d.ts +2 -0
- package/dist/cjs/proxy.extensions.js +207 -0
- package/dist/cjs/proxy.extensions.js.map +1 -0
- package/dist/cjs/reflect.extensions.js +316 -0
- package/dist/cjs/reflect.extensions.js.map +1 -0
- package/dist/cjs/regular.expression.extensions.d.ts +2 -0
- package/dist/cjs/regular.expression.extensions.js +423 -0
- package/dist/cjs/regular.expression.extensions.js.map +1 -0
- package/dist/cjs/set.extensions.d.ts +40 -0
- package/dist/cjs/{setextensions.js → set.extensions.js} +150 -2
- package/dist/cjs/set.extensions.js.map +1 -0
- package/dist/cjs/string.extensions.js +471 -0
- package/dist/cjs/string.extensions.js.map +1 -0
- package/dist/{mjs/symbolextensions.d.ts → cjs/symbol.extensions.d.ts} +1 -0
- package/dist/cjs/symbol.extensions.js +259 -0
- package/dist/cjs/symbol.extensions.js.map +1 -0
- package/dist/cjs/{weakrefextensions.js → weakref.extensions.js} +1 -1
- package/dist/cjs/weakref.extensions.js.map +1 -0
- package/dist/mjs/array.extensions.d.ts +39 -0
- package/dist/mjs/array.extensions.js +300 -0
- package/dist/mjs/array.extensions.js.map +1 -0
- package/dist/mjs/big.int.extension.d.ts +31 -0
- package/dist/mjs/big.int.extension.js +161 -0
- package/dist/mjs/big.int.extension.js.map +1 -0
- package/dist/mjs/classes/asyncIterable.js.map +1 -0
- package/dist/mjs/classes/deferred.js.map +1 -0
- package/dist/mjs/{newClasses → classes}/descriptor.js +7 -4
- package/dist/mjs/classes/descriptor.js.map +1 -0
- package/dist/mjs/classes/index.d.ts +13 -0
- package/dist/mjs/classes/index.js +40 -0
- package/dist/mjs/classes/index.js.map +1 -0
- package/dist/mjs/classes/introspector.d.ts +20 -0
- package/dist/mjs/classes/introspector.js +126 -0
- package/dist/mjs/classes/introspector.js.map +1 -0
- package/dist/mjs/classes/iterable.js.map +1 -0
- package/dist/mjs/classes/param.parser.d.ts +227 -0
- package/dist/mjs/classes/param.parser.js +238 -0
- package/dist/mjs/classes/param.parser.js.map +1 -0
- package/dist/mjs/classes/pluggable.proxy.d.ts +152 -0
- package/dist/mjs/classes/pluggable.proxy.js +438 -0
- package/dist/mjs/classes/pluggable.proxy.js.map +1 -0
- package/dist/mjs/{newClasses → classes}/refmap.js +3 -3
- package/dist/mjs/classes/refmap.js.map +1 -0
- package/dist/mjs/classes/refset.js.map +1 -0
- package/dist/mjs/classes/symkeys.d.ts +292 -0
- package/dist/mjs/classes/symkeys.js +420 -0
- package/dist/mjs/classes/symkeys.js.map +1 -0
- package/dist/mjs/classes/type.d.ts +56 -0
- package/dist/mjs/classes/type.js +401 -0
- package/dist/mjs/classes/type.js.map +1 -0
- package/dist/mjs/function.extensions.js +754 -0
- package/dist/mjs/function.extensions.js.map +1 -0
- package/dist/mjs/global.this.js +258 -0
- package/dist/mjs/global.this.js.map +1 -0
- package/dist/mjs/index.d.ts +4 -3
- package/dist/mjs/index.js +49 -19
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/json.extensions.d.ts +2 -0
- package/dist/mjs/json.extensions.js +104 -0
- package/dist/mjs/json.extensions.js.map +1 -0
- package/dist/{cjs/mapextensions.d.ts → mjs/map.extensions.d.ts} +1 -0
- package/dist/mjs/map.extensions.js +139 -0
- package/dist/mjs/map.extensions.js.map +1 -0
- package/dist/mjs/number.extension.d.ts +44 -0
- package/dist/mjs/number.extension.js +257 -0
- package/dist/mjs/number.extension.js.map +1 -0
- package/dist/mjs/object.extensions.d.ts +62 -0
- package/dist/mjs/object.extensions.js +1112 -0
- package/dist/mjs/object.extensions.js.map +1 -0
- package/dist/mjs/proxy.extensions.d.ts +2 -0
- package/dist/mjs/proxy.extensions.js +204 -0
- package/dist/mjs/proxy.extensions.js.map +1 -0
- package/dist/mjs/reflect.extensions.js +313 -0
- package/dist/mjs/reflect.extensions.js.map +1 -0
- package/dist/mjs/regular.expression.extensions.d.ts +2 -0
- package/dist/mjs/regular.expression.extensions.js +420 -0
- package/dist/mjs/regular.expression.extensions.js.map +1 -0
- package/dist/mjs/set.extensions.d.ts +40 -0
- package/dist/mjs/{setextensions.js → set.extensions.js} +149 -1
- package/dist/mjs/set.extensions.js.map +1 -0
- package/dist/mjs/string.extensions.js +468 -0
- package/dist/mjs/string.extensions.js.map +1 -0
- package/dist/{cjs/symbolextensions.d.ts → mjs/symbol.extensions.d.ts} +1 -0
- package/dist/mjs/symbol.extensions.js +256 -0
- package/dist/mjs/symbol.extensions.js.map +1 -0
- package/dist/mjs/{weakrefextensions.js → weakref.extensions.js} +1 -1
- package/dist/mjs/weakref.extensions.js.map +1 -0
- package/docs/index.html +24045 -5805
- package/package.json +6 -4
- package/repl.bootstrap.js +21 -0
- package/src/array.extensions.js +322 -0
- package/src/big.int.extension.js +163 -0
- package/src/{newClasses → classes}/descriptor.js +16 -12
- package/src/classes/index.js +51 -0
- package/src/classes/introspector.js +167 -0
- package/src/classes/param.parser.js +253 -0
- package/src/classes/pluggable.proxy.js +485 -0
- package/src/{newClasses → classes}/refmap.js +5 -3
- package/src/classes/symkeys.js +464 -0
- package/src/classes/type.js +427 -0
- package/src/function.extensions.js +818 -0
- package/src/global.this.js +304 -0
- package/src/index.js +56 -23
- package/src/json.extensions.js +108 -0
- package/src/map.extensions.js +144 -0
- package/src/number.extension.js +273 -0
- package/src/object.extensions.js +1222 -0
- package/src/proxy.extensions.js +229 -0
- package/src/reflect.extensions.js +346 -0
- package/src/regular.expression.extensions.js +451 -0
- package/src/{setextensions.js → set.extensions.js} +151 -2
- package/src/string.extensions.js +515 -0
- package/src/symbol.extensions.js +268 -0
- package/tests/newClasses/refmap.test.js +3 -2
- package/tsconfig.base.json +5 -3
- package/tsconfig.cjs.json +2 -2
- package/tsconfig.esm.json +2 -2
- package/dist/@nejs/basic-extensions.bundle.2.5.0.js +0 -8
- package/dist/@nejs/basic-extensions.bundle.2.5.0.js.map +0 -7
- package/dist/cjs/arrayextensions.d.ts +0 -10
- package/dist/cjs/arrayextensions.js +0 -73
- package/dist/cjs/arrayextensions.js.map +0 -1
- package/dist/cjs/functionextensions.js +0 -202
- package/dist/cjs/functionextensions.js.map +0 -1
- package/dist/cjs/globals.js +0 -166
- package/dist/cjs/globals.js.map +0 -1
- package/dist/cjs/mapextensions.js +0 -32
- package/dist/cjs/mapextensions.js.map +0 -1
- package/dist/cjs/newClasses/asyncIterable.js.map +0 -1
- package/dist/cjs/newClasses/deferred.js.map +0 -1
- package/dist/cjs/newClasses/descriptor.js.map +0 -1
- package/dist/cjs/newClasses/iterable.js.map +0 -1
- package/dist/cjs/newClasses/refmap.js.map +0 -1
- package/dist/cjs/newClasses/refset.js.map +0 -1
- package/dist/cjs/objectextensions.d.ts +0 -11
- package/dist/cjs/objectextensions.js +0 -232
- package/dist/cjs/objectextensions.js.map +0 -1
- package/dist/cjs/reflectextensions.js +0 -111
- package/dist/cjs/reflectextensions.js.map +0 -1
- package/dist/cjs/setextensions.d.ts +0 -2
- package/dist/cjs/setextensions.js.map +0 -1
- package/dist/cjs/stringextensions.js +0 -158
- package/dist/cjs/stringextensions.js.map +0 -1
- package/dist/cjs/symbolextensions.js +0 -69
- package/dist/cjs/symbolextensions.js.map +0 -1
- package/dist/cjs/weakrefextensions.js.map +0 -1
- package/dist/mjs/arrayextensions.d.ts +0 -10
- package/dist/mjs/arrayextensions.js +0 -70
- package/dist/mjs/arrayextensions.js.map +0 -1
- package/dist/mjs/functionextensions.js +0 -199
- package/dist/mjs/functionextensions.js.map +0 -1
- package/dist/mjs/globals.js +0 -163
- package/dist/mjs/globals.js.map +0 -1
- package/dist/mjs/mapextensions.js +0 -29
- package/dist/mjs/mapextensions.js.map +0 -1
- package/dist/mjs/newClasses/asyncIterable.js.map +0 -1
- package/dist/mjs/newClasses/deferred.js.map +0 -1
- package/dist/mjs/newClasses/descriptor.js.map +0 -1
- package/dist/mjs/newClasses/iterable.js.map +0 -1
- package/dist/mjs/newClasses/refmap.js.map +0 -1
- package/dist/mjs/newClasses/refset.js.map +0 -1
- package/dist/mjs/objectextensions.d.ts +0 -11
- package/dist/mjs/objectextensions.js +0 -229
- package/dist/mjs/objectextensions.js.map +0 -1
- package/dist/mjs/reflectextensions.js +0 -108
- package/dist/mjs/reflectextensions.js.map +0 -1
- package/dist/mjs/setextensions.d.ts +0 -2
- package/dist/mjs/setextensions.js.map +0 -1
- package/dist/mjs/stringextensions.js +0 -155
- package/dist/mjs/stringextensions.js.map +0 -1
- package/dist/mjs/symbolextensions.js +0 -66
- package/dist/mjs/symbolextensions.js.map +0 -1
- package/dist/mjs/weakrefextensions.js.map +0 -1
- package/src/arrayextensions.js +0 -75
- package/src/functionextensions.js +0 -225
- package/src/globals.js +0 -196
- package/src/mapextensions.js +0 -32
- package/src/objectextensions.js +0 -256
- package/src/reflectextensions.js +0 -118
- package/src/stringextensions.js +0 -166
- package/src/symbolextensions.js +0 -69
- /package/dist/cjs/{newClasses → classes}/asyncIterable.d.ts +0 -0
- /package/dist/cjs/{newClasses → classes}/deferred.d.ts +0 -0
- /package/dist/cjs/{newClasses → classes}/descriptor.d.ts +0 -0
- /package/dist/cjs/{newClasses → classes}/iterable.d.ts +0 -0
- /package/dist/cjs/{newClasses → classes}/refmap.d.ts +0 -0
- /package/dist/cjs/{newClasses → classes}/refset.d.ts +0 -0
- /package/dist/cjs/{functionextensions.d.ts → function.extensions.d.ts} +0 -0
- /package/dist/cjs/{globals.d.ts → global.this.d.ts} +0 -0
- /package/dist/cjs/{reflectextensions.d.ts → reflect.extensions.d.ts} +0 -0
- /package/dist/cjs/{stringextensions.d.ts → string.extensions.d.ts} +0 -0
- /package/dist/cjs/{weakrefextensions.d.ts → weakref.extensions.d.ts} +0 -0
- /package/dist/mjs/{newClasses → classes}/asyncIterable.d.ts +0 -0
- /package/dist/mjs/{newClasses → classes}/asyncIterable.js +0 -0
- /package/dist/mjs/{newClasses → classes}/deferred.d.ts +0 -0
- /package/dist/mjs/{newClasses → classes}/deferred.js +0 -0
- /package/dist/mjs/{newClasses → classes}/descriptor.d.ts +0 -0
- /package/dist/mjs/{newClasses → classes}/iterable.d.ts +0 -0
- /package/dist/mjs/{newClasses → classes}/iterable.js +0 -0
- /package/dist/mjs/{newClasses → classes}/refmap.d.ts +0 -0
- /package/dist/mjs/{newClasses → classes}/refset.d.ts +0 -0
- /package/dist/mjs/{newClasses → classes}/refset.js +0 -0
- /package/dist/mjs/{functionextensions.d.ts → function.extensions.d.ts} +0 -0
- /package/dist/mjs/{globals.d.ts → global.this.d.ts} +0 -0
- /package/dist/mjs/{reflectextensions.d.ts → reflect.extensions.d.ts} +0 -0
- /package/dist/mjs/{stringextensions.d.ts → string.extensions.d.ts} +0 -0
- /package/dist/mjs/{weakrefextensions.d.ts → weakref.extensions.d.ts} +0 -0
- /package/src/{newClasses → classes}/asyncIterable.js +0 -0
- /package/src/{newClasses → classes}/deferred.js +0 -0
- /package/src/{newClasses → classes}/iterable.js +0 -0
- /package/src/{newClasses → classes}/refset.js +0 -0
- /package/src/{weakrefextensions.js → weakref.extensions.js} +0 -0
package/src/arrayextensions.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Patch } from '@nejs/extension'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The `ArrayPrototypeExtensions` patch extends the prototype of the built-in
|
|
5
|
-
* JavaScript `Array` with additional properties for convenience and improved
|
|
6
|
-
* readability. By applying this patch, all array instances gain new getter
|
|
7
|
-
* properties `first` and `last`, which provide quick access to the first and
|
|
8
|
-
* last elements of the array, respectively. This enhancement simplifies common
|
|
9
|
-
* operations on arrays and makes code more expressive and concise.
|
|
10
|
-
*/
|
|
11
|
-
export const ArrayPrototypeExtensions = new Patch(Array.prototype, {
|
|
12
|
-
[Patch.kMutablyHidden]: {
|
|
13
|
-
/**
|
|
14
|
-
* Sometimes defining even a short function for the invocation of `find`
|
|
15
|
-
* can be troublesome. This helper function performs that job for you. If
|
|
16
|
-
* the specified element is in the array, `true` will be returned.
|
|
17
|
-
*
|
|
18
|
-
* @param {*} value the value to search for. This value must triple equals
|
|
19
|
-
* the array element in order to return true.
|
|
20
|
-
* @returns true if the exact element exists in the array, false otherwise
|
|
21
|
-
*/
|
|
22
|
-
contains(value) {
|
|
23
|
-
return !!this.find(entry => entry === value)
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The `findEntry` function searches the entries of the object and returns
|
|
28
|
-
* the `[index, value]` entry array for the first matching value found.
|
|
29
|
-
*
|
|
30
|
-
* @param {function} findFn a function that takes the element to be checked
|
|
31
|
-
* and returns a boolean value
|
|
32
|
-
* @returns if `findFn` returns `true`, an array with two elements, the first
|
|
33
|
-
* being the index, the second being the value, is returned.
|
|
34
|
-
*/
|
|
35
|
-
findEntry(findFn) {
|
|
36
|
-
const entries = this.entries()
|
|
37
|
-
const VALUE = 1
|
|
38
|
-
|
|
39
|
-
for (let entry of entries) {
|
|
40
|
-
if (findFn(entry[VALUE])) {
|
|
41
|
-
return entry
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return undefined
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* A getter property that returns the first element of the array. If the
|
|
50
|
-
* array is empty, it returns `undefined`. This property is useful for
|
|
51
|
-
* scenarios where you need to quickly access the first item of an array
|
|
52
|
-
* without the need for additional checks or method calls.
|
|
53
|
-
*
|
|
54
|
-
* @returns {*} The first element of the array or `undefined` if the array
|
|
55
|
-
* is empty.
|
|
56
|
-
*/
|
|
57
|
-
get first() {
|
|
58
|
-
return this[0];
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* A getter property that returns the last element of the array. It
|
|
63
|
-
* calculates the last index based on the array's length. If the array is
|
|
64
|
-
* empty, it returns `undefined`. This property is beneficial when you need
|
|
65
|
-
* to access the last item in an array, improving code readability and
|
|
66
|
-
* avoiding manual index calculation.
|
|
67
|
-
*
|
|
68
|
-
* @returns {*} The last element of the array or `undefined` if the
|
|
69
|
-
* array is empty.
|
|
70
|
-
*/
|
|
71
|
-
get last() {
|
|
72
|
-
return this[this.length - 1];
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
})
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import { Patch } from '@nejs/extension'
|
|
2
|
-
import { ObjectExtensions } from './objectextensions.js'
|
|
3
|
-
|
|
4
|
-
const { getStringTag } = ObjectExtensions.patches
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The `FunctionExtensions` class is a patch applied to the built-in JavaScript
|
|
8
|
-
* `Function` constructor. It extends `Function` with additional utility methods
|
|
9
|
-
* for determining the specific type or nature of function-like objects. These
|
|
10
|
-
* methods allow developers to distinguish between classes, regular functions,
|
|
11
|
-
* async functions, and arrow functions in a more intuitive and straightforward
|
|
12
|
-
* manner. This class is part of the `@nejs/extension` library and enhances the
|
|
13
|
-
* capabilities of function handling and introspection in JavaScript.
|
|
14
|
-
*/
|
|
15
|
-
export const FunctionExtensions = new Patch(Function, {
|
|
16
|
-
/**
|
|
17
|
-
* Determines if a given value is an asynchronous function. It checks if the
|
|
18
|
-
* value is an instance of `Function` and if its string representation
|
|
19
|
-
* includes the keyword 'Async'. This method is particularly useful for
|
|
20
|
-
* identifying async functions.
|
|
21
|
-
*
|
|
22
|
-
* @param {*} value - The value to be checked.
|
|
23
|
-
* @returns {boolean} Returns `true` if the value is an async function,
|
|
24
|
-
* otherwise `false`.
|
|
25
|
-
*/
|
|
26
|
-
isAsync(value) {
|
|
27
|
-
const stringTag = /(\w+)]/g.exec(Object.prototype.toString.call(value))[1]
|
|
28
|
-
return (
|
|
29
|
-
value instanceof Function &&
|
|
30
|
-
stringTag.includes('Async')
|
|
31
|
-
)
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The function checks if a given value is an async generator function
|
|
36
|
-
*
|
|
37
|
-
* @param {any} value - The `value` parameter is the value that we want to
|
|
38
|
-
* check if it is a generator function.
|
|
39
|
-
* @returns {boolean} `true` if the value is an instance of a function and
|
|
40
|
-
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
|
|
41
|
-
*/
|
|
42
|
-
isAsyncGenerator(value) {
|
|
43
|
-
const stringTag = getStringTag(value)
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
value instanceof Function &&
|
|
47
|
-
stringTag == 'AsyncGeneratorFunction'
|
|
48
|
-
)
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Checks if a given value is an arrow function. It verifies if the value is
|
|
53
|
-
* an instance of `Function`, if its string representation includes the '=>'
|
|
54
|
-
* symbol, and if it lacks a prototype, which is a characteristic of arrow
|
|
55
|
-
* functions in JavaScript.
|
|
56
|
-
*
|
|
57
|
-
* @param {*} value - The value to be checked.
|
|
58
|
-
* @returns {boolean} Returns `true` if the value is an arrow function,
|
|
59
|
-
* otherwise `false`.
|
|
60
|
-
*/
|
|
61
|
-
isBigArrow(value) {
|
|
62
|
-
return (
|
|
63
|
-
value instanceof Function &&
|
|
64
|
-
String(value).includes('=>') &&
|
|
65
|
-
!String(value).startsWith('bound') &&
|
|
66
|
-
!Reflect.has(value, 'prototype')
|
|
67
|
-
);
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Determines if a given value is a bound function. Bound functions are
|
|
72
|
-
* created using the `Function.prototype.bind` method, which allows setting
|
|
73
|
-
* the `this` value at the time of binding. This method checks if the value
|
|
74
|
-
* is an instance of `Function`, if its string representation starts with
|
|
75
|
-
* 'bound', and if it lacks a `prototype` property. These characteristics
|
|
76
|
-
* are indicative of bound functions in JavaScript.
|
|
77
|
-
*
|
|
78
|
-
* @param {*} value - The value to be checked, typically a function.
|
|
79
|
-
* @returns {boolean} Returns `true` if the value is a bound function,
|
|
80
|
-
* otherwise `false`. Bound functions have a specific format in their
|
|
81
|
-
* string representation and do not have their own `prototype` property.
|
|
82
|
-
*/
|
|
83
|
-
isBound(value) {
|
|
84
|
-
return (
|
|
85
|
-
value instanceof Function &&
|
|
86
|
-
String(value).startsWith('bound') &&
|
|
87
|
-
!Reflect.has(value, 'prototype')
|
|
88
|
-
)
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Determines if a given value is a class. It checks if the value is an
|
|
93
|
-
* instance of `Function` and if its string representation includes the
|
|
94
|
-
* keyword 'class'. This method is useful for distinguishing classes from
|
|
95
|
-
* other function types in JavaScript.
|
|
96
|
-
*
|
|
97
|
-
* @param {*} value - The value to be checked.
|
|
98
|
-
* @returns {boolean} Returns `true` if the value is a class, otherwise
|
|
99
|
-
* `false`.
|
|
100
|
-
*/
|
|
101
|
-
isClass(value) {
|
|
102
|
-
return value instanceof Function && !!/^class\s/.exec(String(value))
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Checks if a given value is a regular function. This method verifies if
|
|
107
|
-
* the value is an instance of `Function`, which includes regular functions,
|
|
108
|
-
* classes, and async functions but excludes arrow functions.
|
|
109
|
-
*
|
|
110
|
-
* @param {*} value - The value to be checked.
|
|
111
|
-
* @returns {boolean} Returns `true` if the value is a regular function,
|
|
112
|
-
* otherwise `false`.
|
|
113
|
-
*/
|
|
114
|
-
isFunction(value) {
|
|
115
|
-
return value instanceof Function && !Function.isClass(value);
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* The function checks if a given value is a generator function
|
|
120
|
-
*
|
|
121
|
-
* @param {any} value - The `value` parameter is the value that we want to
|
|
122
|
-
* check if it is a generator function.
|
|
123
|
-
* @returns {boolean} `true` if the value is an instance of a function and
|
|
124
|
-
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
|
|
125
|
-
*/
|
|
126
|
-
isGenerator(value) {
|
|
127
|
-
const stringTag = getStringTag(value)
|
|
128
|
-
|
|
129
|
-
return (
|
|
130
|
-
value instanceof Function &&
|
|
131
|
-
stringTag == 'GeneratorFunction'
|
|
132
|
-
)
|
|
133
|
-
},
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
export const FunctionPrototypeExtensions = new Patch(Function.prototype, {
|
|
137
|
-
[Patch.kMutablyHidden]: {
|
|
138
|
-
/**
|
|
139
|
-
* Determines if a given value is an asynchronous function. It checks if the
|
|
140
|
-
* value is an instance of `Function` and if its string representation
|
|
141
|
-
* includes the keyword 'Async'. This method is particularly useful for
|
|
142
|
-
* identifying async functions.
|
|
143
|
-
*
|
|
144
|
-
* @returns {boolean} Returns `true` if the value is an async function,
|
|
145
|
-
* otherwise `false`.
|
|
146
|
-
*/
|
|
147
|
-
get isAsync() {
|
|
148
|
-
return Function.isAsync(this)
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* The function checks if a given value is an async generator function
|
|
153
|
-
*
|
|
154
|
-
* @returns {boolean} `true` if the value is an instance of a function and
|
|
155
|
-
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
|
|
156
|
-
*/
|
|
157
|
-
get isAsyncGenerator() {
|
|
158
|
-
return Function.isAsyncGenerator(this)
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Checks if a given value is an arrow function. It verifies if the value is
|
|
163
|
-
* an instance of `Function`, if its string representation includes the '=>'
|
|
164
|
-
* symbol, and if it lacks a prototype, which is a characteristic of arrow
|
|
165
|
-
* functions in JavaScript.
|
|
166
|
-
*
|
|
167
|
-
* @returns {boolean} Returns `true` if the value is an arrow function,
|
|
168
|
-
* otherwise `false`.
|
|
169
|
-
*/
|
|
170
|
-
get isBigArrow() {
|
|
171
|
-
return Function.isBigArrow(this)
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Determines if a given value is a bound function. Bound functions are
|
|
176
|
-
* created using the `Function.prototype.bind` method, which allows setting
|
|
177
|
-
* the `this` value at the time of binding. This method checks if the value
|
|
178
|
-
* is an instance of `Function`, if its string representation starts with
|
|
179
|
-
* 'bound', and if it lacks a `prototype` property. These characteristics
|
|
180
|
-
* are indicative of bound functions in JavaScript.
|
|
181
|
-
*
|
|
182
|
-
* @returns {boolean} Returns `true` if the value is a bound function,
|
|
183
|
-
* otherwise `false`. Bound functions have a specific format in their
|
|
184
|
-
* string representation and do not have their own `prototype` property.
|
|
185
|
-
*/
|
|
186
|
-
get isBound() {
|
|
187
|
-
return Function.isBound(this)
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Determines if a given value is a class. It checks if the value is an
|
|
192
|
-
* instance of `Function` and if its string representation includes the
|
|
193
|
-
* keyword 'class'. This method is useful for distinguishing classes from
|
|
194
|
-
* other function types in JavaScript.
|
|
195
|
-
*
|
|
196
|
-
* @returns {boolean} Returns `true` if the value is a class, otherwise
|
|
197
|
-
* `false`.
|
|
198
|
-
*/
|
|
199
|
-
get isClass() {
|
|
200
|
-
return Function.isClass(this)
|
|
201
|
-
},
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Checks if a given value is a regular function. This method verifies if
|
|
205
|
-
* the value is an instance of `Function`, which includes regular functions,
|
|
206
|
-
* classes, and async functions but excludes arrow functions.
|
|
207
|
-
*
|
|
208
|
-
* @returns {boolean} Returns `true` if the value is a regular function,
|
|
209
|
-
* otherwise `false`.
|
|
210
|
-
*/
|
|
211
|
-
get isFunction() {
|
|
212
|
-
return Function.isFunction(this)
|
|
213
|
-
},
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* The function checks if a given value is a generator function
|
|
217
|
-
*
|
|
218
|
-
* @returns {boolean} `true` if the value is an instance of a function and
|
|
219
|
-
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
|
|
220
|
-
*/
|
|
221
|
-
get isGenerator() {
|
|
222
|
-
return Function.isGenerator(this)
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
})
|
package/src/globals.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { Patch } from '@nejs/extension'
|
|
2
|
-
import { FunctionExtensions } from './functionextensions.js'
|
|
3
|
-
|
|
4
|
-
const { isClass, isFunction } = FunctionExtensions.patches
|
|
5
|
-
const CustomInspect = Symbol.for('nodejs.util.inspect.custom')
|
|
6
|
-
|
|
7
|
-
export const GlobalFunctionsAndProps = new Patch(globalThis, {
|
|
8
|
-
/**
|
|
9
|
-
* Transforms an object to mimic a specified prototype, altering its type
|
|
10
|
-
* conversion and inspection behaviors. This function is especially useful
|
|
11
|
-
* for creating objects that need to behave like different primitive types
|
|
12
|
-
* under various operations.
|
|
13
|
-
*
|
|
14
|
-
* @param {Object} object - The object to be transformed.
|
|
15
|
-
* @param {Function|Object} [prototype=String.prototype] - The prototype or
|
|
16
|
-
* class to emulate. If a function is provided, its prototype is used.
|
|
17
|
-
* Defaults to String.prototype.
|
|
18
|
-
* @param {Function} [toPrimitive=(hint, val) => String(val)] - A function
|
|
19
|
-
* defining how the object should be converted to a primitive value. It
|
|
20
|
-
* receives a type hint ('number', 'string', or 'default') and the object,
|
|
21
|
-
* returning the primitive value.
|
|
22
|
-
* @returns {Object|null} The transformed object, or null if neither a class
|
|
23
|
-
* nor a prototype could be derived from the provided prototype parameter.
|
|
24
|
-
*/
|
|
25
|
-
maskAs(object, classPrototype, options) {
|
|
26
|
-
const {
|
|
27
|
-
prototype,
|
|
28
|
-
toPrimitive
|
|
29
|
-
} = GenericMask({...options, prototype: classPrototype})
|
|
30
|
-
|
|
31
|
-
const base = { configurable: true, enumerable: false }
|
|
32
|
-
const proto = isFunction(prototype) ? prototype.prototype : prototype
|
|
33
|
-
const klass = isClass(prototype) ? prototype : proto?.constructor
|
|
34
|
-
|
|
35
|
-
if (!klass && !proto) {
|
|
36
|
-
return null
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
Object.setPrototypeOf(object, proto)
|
|
40
|
-
Object.defineProperties(object, {
|
|
41
|
-
valueOf: {
|
|
42
|
-
value() { return String(toPrimitive('default', object)) }, ...base },
|
|
43
|
-
|
|
44
|
-
[Symbol.toPrimitive]: {
|
|
45
|
-
value(hint) { return toPrimitive(hint, object) }, ...base
|
|
46
|
-
},
|
|
47
|
-
[Symbol.toStringTag]: { value: klass.name, ...base },
|
|
48
|
-
[Symbol.species]: { get() { return klass }, ...base },
|
|
49
|
-
[CustomInspect]: { ...base, value(depth, opts, inspect) {
|
|
50
|
-
return inspect(this[Symbol.toPrimitive](), { ...opts, depth })
|
|
51
|
-
}}
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
return object
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Masks an object as a string-like object by setting its prototype to
|
|
59
|
-
* String and defining how it converts to primitive types. This is
|
|
60
|
-
* particularly useful when an object needs to behave like a string in
|
|
61
|
-
* certain contexts, such as type coercion or logging.
|
|
62
|
-
*
|
|
63
|
-
* @param {Object} object - The object to be masked as a string.
|
|
64
|
-
* @param {string} [stringKey='value'] - The object property key used for
|
|
65
|
-
* the string representation. Defaults to 'value'.
|
|
66
|
-
* @param {Function} [toPrimitive] - Optional custom function for primitive
|
|
67
|
-
* conversion. If omitted, a default function handling various conversion
|
|
68
|
-
* hints is used.
|
|
69
|
-
* @returns {Object|null} The string-masked object, or null if the object
|
|
70
|
-
* doesn't have the specified stringKey property.
|
|
71
|
-
*/
|
|
72
|
-
maskAsString(
|
|
73
|
-
object,
|
|
74
|
-
stringKey,
|
|
75
|
-
toPrimitive
|
|
76
|
-
) {
|
|
77
|
-
if (object && Reflect.has(object, stringKey)) {
|
|
78
|
-
return maskAs(object, StringMask(stringKey ?? 'value', toPrimitive))
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return null
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Masks an object as a number-like object. This allows the object to
|
|
86
|
-
* behave like a number in operations like arithmetic and type coercion.
|
|
87
|
-
* It sets the prototype to Number and defines custom conversion behavior.
|
|
88
|
-
*
|
|
89
|
-
* @param {Object} object - The object to be masked as a number
|
|
90
|
-
* representation. Defaults to 'value'.
|
|
91
|
-
* @param {Function} [toPrimitive] - Optional custom function for primitive
|
|
92
|
-
* conversion. If not provided, a default function handling different
|
|
93
|
-
* conversion hints is used.
|
|
94
|
-
* @returns {Object|null} The number-masked object, or null if the object
|
|
95
|
-
* doesn't have the specified numberKey property.
|
|
96
|
-
*/
|
|
97
|
-
maskAsNumber(
|
|
98
|
-
object,
|
|
99
|
-
numberKey,
|
|
100
|
-
toPrimitive
|
|
101
|
-
) {
|
|
102
|
-
if (object && Reflect.has(object, numberKey)) {
|
|
103
|
-
return maskAs(object, NumberMask(numberKey ?? 'value', toPrimitive))
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return null
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Generates options for generic masking of an object, providing defaults for
|
|
111
|
-
* prototype and toPrimitive function if not specified.
|
|
112
|
-
*
|
|
113
|
-
* @param {Object} options - The options object including prototype,
|
|
114
|
-
* targetKey, and toPrimitive function.
|
|
115
|
-
* @returns {Object} The options object with defaults applied as necessary.
|
|
116
|
-
*/
|
|
117
|
-
GenericMask({ prototype, targetKey = 'value', toPrimitive }) {
|
|
118
|
-
const options = { targetKey, toPrimitive, prototype };
|
|
119
|
-
|
|
120
|
-
if (!isFunction(toPrimitive)) {
|
|
121
|
-
options.toPrimitive = (hint, object) => {
|
|
122
|
-
let property = object[targetKey];
|
|
123
|
-
let isNum = (
|
|
124
|
-
(typeof property === 'number' && Number.isFinite(property)) ||
|
|
125
|
-
(typeof property === 'string' &&
|
|
126
|
-
!isNaN(parseFloat(property)) && isFinite(property)
|
|
127
|
-
)
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
switch (hint) {
|
|
131
|
-
case 'string':
|
|
132
|
-
return isNum ? String(property) : (property ?? String(object));
|
|
133
|
-
case 'number':
|
|
134
|
-
return isNum ? Number(property) : NaN;
|
|
135
|
-
case 'default':
|
|
136
|
-
default:
|
|
137
|
-
return isNum ? Number(property) : property;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return options;
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Generates options for string masking of an object, providing a default
|
|
147
|
-
* toPrimitive function if not specified.
|
|
148
|
-
*
|
|
149
|
-
* @param {string} targetKey - The object property key for string
|
|
150
|
-
* representation.
|
|
151
|
-
* @param {Function} toPrimitive - Custom function for primitive conversion.
|
|
152
|
-
* @returns {Object} Options for string masking.
|
|
153
|
-
*/
|
|
154
|
-
StringMask(targetKey, toPrimitive) {
|
|
155
|
-
const options = { targetKey, toPrimitive, prototype: String.prototype }
|
|
156
|
-
|
|
157
|
-
if (!isFunction(toPrimitive)) {
|
|
158
|
-
options.toPrimitive = function toPrimitive(hint, object) {
|
|
159
|
-
switch (hint) {
|
|
160
|
-
case 'default': return object[targetKey]
|
|
161
|
-
case 'number': return parseInt(object[targetKey], 36)
|
|
162
|
-
case 'string': return String(object[targetKey])
|
|
163
|
-
default: return object
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return options
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Generates options for number masking of an object, providing a default
|
|
173
|
-
* toPrimitive function if not specified.
|
|
174
|
-
*
|
|
175
|
-
* @param {string} targetKey - The object property key for number
|
|
176
|
-
* representation.
|
|
177
|
-
* @param {Function} toPrimitive - Custom function for primitive conversion.
|
|
178
|
-
* @returns {Object} Options for number masking.
|
|
179
|
-
*/
|
|
180
|
-
NumberMask(targetKey, toPrimitive) {
|
|
181
|
-
const options = { targetKey, toPrimitive, prototype: Number.prototype }
|
|
182
|
-
|
|
183
|
-
if (!isFunction(toPrimitive)) {
|
|
184
|
-
options.toPrimitive = function toPrimitive(hint, object) {
|
|
185
|
-
switch (hint) {
|
|
186
|
-
case 'default': return object[targetKey]
|
|
187
|
-
case 'number': return Number(object[targetKey])
|
|
188
|
-
case 'string': return String(object[targetKey])
|
|
189
|
-
default: return object
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return options
|
|
195
|
-
},
|
|
196
|
-
})
|
package/src/mapextensions.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Patch } from '@nejs/extension';
|
|
2
|
-
|
|
3
|
-
export const MapPrototypeExtensions = new Patch(Map.prototype, {
|
|
4
|
-
[Patch.kMutablyHidden]: {
|
|
5
|
-
/**
|
|
6
|
-
* The function `getKey` returns the key associated with a given value
|
|
7
|
-
* in a map.
|
|
8
|
-
*
|
|
9
|
-
* @param {any} value - The value parameter is the value that you want to
|
|
10
|
-
* find the corresponding key for in the map.
|
|
11
|
-
* @param [strict=true] - The "strict" parameter is a boolean value that
|
|
12
|
-
* determines whether strict equality (===) or loose equality (==) should
|
|
13
|
-
* be used when comparing the "value" parameter with the values in the
|
|
14
|
-
* entries of the object. If "strict" is set to true, strict equality will
|
|
15
|
-
* be used.
|
|
16
|
-
* @returns the key associated with the given value. If a matching key is
|
|
17
|
-
* found, it is returned. If no matching key is found, null is returned.
|
|
18
|
-
*/
|
|
19
|
-
getKey(value, strict = true) {
|
|
20
|
-
for (const [key, entryValue] of this) {
|
|
21
|
-
if (
|
|
22
|
-
(strict && value === entryValue) &&
|
|
23
|
-
(!strict && value == entryValue)
|
|
24
|
-
) {
|
|
25
|
-
return key
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return null
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
})
|