@nejs/basic-extensions 2.7.0 → 2.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.
- package/.vscode/settings.json +5 -0
- package/README.md +6250 -1574
- package/bin/version +100 -0
- package/dist/@nejs/basic-extensions.bundle.2.8.0.js +19 -0
- package/dist/@nejs/basic-extensions.bundle.2.8.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 +108 -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 +1128 -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 +661 -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 +380 -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 +105 -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 +1124 -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 +658 -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 +377 -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 +24452 -5692
- package/package.json +7 -5
- 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 +109 -0
- package/src/map.extensions.js +144 -0
- package/src/number.extension.js +273 -0
- package/src/object.extensions.js +1237 -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 +734 -0
- package/src/symbol.extensions.js +389 -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.6.0.js +0 -17
- package/dist/@nejs/basic-extensions.bundle.2.6.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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MapPrototypeExtensions = exports.MapExtensions = void 0;
|
|
4
|
+
const extension_1 = require("@nejs/extension");
|
|
5
|
+
exports.MapExtensions = new extension_1.Patch(Map, {
|
|
6
|
+
[extension_1.Patch.kMutablyHidden]: {
|
|
7
|
+
/**
|
|
8
|
+
* Determines if the supplied `value` is a `Map` object. This check
|
|
9
|
+
* is performed by first looking for the `Symbol.toStringTag` on the
|
|
10
|
+
* `value` and checking to see if it is equal to the string "Map".
|
|
11
|
+
* If that check fails, `instanceof` is used as a fallback to check
|
|
12
|
+
* the prototype chain.
|
|
13
|
+
*
|
|
14
|
+
* @param {any} value the value that needs to be checked to determine
|
|
15
|
+
* if it is a `Map` object or not
|
|
16
|
+
* @returns {boolean} `true` if the supplied `value` is a `Map`
|
|
17
|
+
* object, `false` otherwise
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const map = new Map()
|
|
21
|
+
* isMap(map) // true
|
|
22
|
+
* isMap(new Set()) // false
|
|
23
|
+
* isMap([]) // false
|
|
24
|
+
* isMap({}) // false
|
|
25
|
+
*/
|
|
26
|
+
isMap(value) {
|
|
27
|
+
return value?.[Symbol.toStringTag] === Map.name && value instanceof Map;
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* Conditionally returns a value based on whether the supplied
|
|
31
|
+
* `value` is a `Map` object or not. If the `value` is a `Map`
|
|
32
|
+
* object, the `thenValue` will be returned. If it is not a `Map`
|
|
33
|
+
* object, the `elseValue` will be returned instead.
|
|
34
|
+
*
|
|
35
|
+
* @param {any} value the value to check to determine if it is a
|
|
36
|
+
* `Map` object
|
|
37
|
+
* @param {any} thenValue the value to return if the supplied
|
|
38
|
+
* `value` is a `Map` object
|
|
39
|
+
* @param {any} elseValue the value to return if the supplied
|
|
40
|
+
* `value` is not a `Map` object
|
|
41
|
+
* @returns {any} either the `thenValue` or `elseValue` depending
|
|
42
|
+
* on if the supplied `value` is a `Map` object
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const map = new Map()
|
|
46
|
+
* const set = new Set()
|
|
47
|
+
* ifMap(map, 'is a map', 'not a map') // 'is a map'
|
|
48
|
+
* ifMap(set, 'is a map', 'not a map') // 'not a map'
|
|
49
|
+
*/
|
|
50
|
+
ifMap(value, thenValue, elseValue) {
|
|
51
|
+
return isThenElse(this.isMap(value), thenValue, elseValue);
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const { isMap: pIsMap, ifMap: pIfMap } = exports.MapExtensions.patches;
|
|
56
|
+
exports.MapPrototypeExtensions = new extension_1.Patch(Map.prototype, {
|
|
57
|
+
[extension_1.Patch.kMutablyHidden]: {
|
|
58
|
+
/**
|
|
59
|
+
* Determines if the current object is a `Map` object
|
|
60
|
+
*
|
|
61
|
+
* This is a getter that uses the `isMap` function from the
|
|
62
|
+
* `MapExtensions` patch to check if the current object (`this`) is
|
|
63
|
+
* a `Map` object
|
|
64
|
+
*
|
|
65
|
+
* @type {boolean}
|
|
66
|
+
* @readonly
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const map = new Map()
|
|
70
|
+
* console.log(map.isMap) // Output: true
|
|
71
|
+
*
|
|
72
|
+
* const notMap = {}
|
|
73
|
+
* console.log(notMap.isMap) // Output: false
|
|
74
|
+
*/
|
|
75
|
+
get isMap() {
|
|
76
|
+
return pIsMap(this);
|
|
77
|
+
},
|
|
78
|
+
/**
|
|
79
|
+
* Conditionally returns a value based on whether the current
|
|
80
|
+
* object is a `Map` object or not
|
|
81
|
+
*
|
|
82
|
+
* If the current object is a `Map` object, the `thenValue` will
|
|
83
|
+
* be returned. If it is not a `Map` object, the `elseValue` will
|
|
84
|
+
* be returned instead.
|
|
85
|
+
*
|
|
86
|
+
* @param {any} thenValue the value to return if the current
|
|
87
|
+
* object is a `Map` object
|
|
88
|
+
* @param {any} elseValue the value to return if the current
|
|
89
|
+
* object is not a `Map` object
|
|
90
|
+
* @returns {any} either the `thenValue` or `elseValue` depending
|
|
91
|
+
* on if the current object is a `Map` object
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* const map = new Map()
|
|
95
|
+
* map.ifMap('is a map', 'not a map') // 'is a map'
|
|
96
|
+
*
|
|
97
|
+
* const notMap = {}
|
|
98
|
+
* notMap.ifMap('is a map', 'not a map') // 'not a map'
|
|
99
|
+
*/
|
|
100
|
+
ifMap(thenValue, elseValue) {
|
|
101
|
+
return pIfMap(this, thenValue, elseValue);
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* The function `getKey` returns the key associated with a given value
|
|
105
|
+
* in a map.
|
|
106
|
+
*
|
|
107
|
+
* @param {any} value - The value parameter is the value that you want to
|
|
108
|
+
* find the corresponding key for in the map.
|
|
109
|
+
* @param [strict=true] - The "strict" parameter is a boolean value that
|
|
110
|
+
* determines whether strict equality (===) or loose equality (==) should
|
|
111
|
+
* be used when comparing the "value" parameter with the values in the
|
|
112
|
+
* entries of the object. If "strict" is set to true, strict equality will
|
|
113
|
+
* be used.
|
|
114
|
+
* @returns the key associated with the given value. If a matching key is
|
|
115
|
+
* found, it is returned. If no matching key is found, null is returned.
|
|
116
|
+
*/
|
|
117
|
+
getKey(value, strict = true) {
|
|
118
|
+
for (const [key, entryValue] of this) {
|
|
119
|
+
if ((strict && value === entryValue) &&
|
|
120
|
+
(!strict && value == entryValue)) {
|
|
121
|
+
return key;
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
// NOTE to self; this is repeated here otherwise a circular reference from
|
|
129
|
+
// Object<->Function<->Global occurs. See original source in global.this.js
|
|
130
|
+
// {@see globalThis.isThenElse}
|
|
131
|
+
function isThenElse(bv, tv, ev) {
|
|
132
|
+
if (arguments.length > 1) {
|
|
133
|
+
var _then = isFunction(tv) ? tv(bv) : tv;
|
|
134
|
+
if (arguments.length > 2) {
|
|
135
|
+
var _else = isFunction(ev) ? tv(bv) : ev;
|
|
136
|
+
return bv ? _then : _else;
|
|
137
|
+
}
|
|
138
|
+
return bv || _then;
|
|
139
|
+
}
|
|
140
|
+
return bv;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=map.extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.extensions.js","sourceRoot":"","sources":["../../src/map.extensions.js"],"names":[],"mappings":";;;AAAA,+CAAuC;AAE1B,QAAA,aAAa,GAAG,IAAI,iBAAK,CAAC,GAAG,EAAE;IAC1C,CAAC,iBAAK,CAAC,cAAc,CAAC,EAAE;QACtB;;;;;;;;;;;;;;;;;;WAkBG;QACH,KAAK,CAAC,KAAK;YACT,OAAO,KAAK,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,KAAK,YAAY,GAAG,CAAA;QACzE,CAAC;QAED;;;;;;;;;;;;;;;;;;;;WAoBG;QACH,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS;YAC/B,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAC5D,CAAC;KACF;CACF,CAAC,CAAA;AAEF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,qBAAa,CAAC,OAAO,CAAA;AAEjD,QAAA,sBAAsB,GAAG,IAAI,iBAAK,CAAC,GAAG,CAAC,SAAS,EAAE;IAC7D,CAAC,iBAAK,CAAC,cAAc,CAAC,EAAE;QACtB;;;;;;;;;;;;;;;;WAgBG;QACH,IAAI,KAAK;YACP,OAAO,MAAM,CAAC,IAAI,CAAC,CAAA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that adds utility
|
|
3
|
+
* methods without modifying the global namespace directly
|
|
4
|
+
*
|
|
5
|
+
* This patch includes methods for checking if a value is a number and
|
|
6
|
+
* conditionally returning a value based on whether the supplied value is
|
|
7
|
+
* a number or not.
|
|
8
|
+
*
|
|
9
|
+
* @type {Patch}
|
|
10
|
+
* @property {Object} [Patch.kMutablyHidden] An object containing methods
|
|
11
|
+
* that are hidden from enumeration and mutation
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { NumberExtensions } from 'number.extension.js'
|
|
15
|
+
*
|
|
16
|
+
* NumberExtensions.apply()
|
|
17
|
+
* // Now the `Number` class has additional methods available
|
|
18
|
+
*/
|
|
19
|
+
export const NumberExtensions: Patch;
|
|
20
|
+
/**
|
|
21
|
+
* `NumberPrototypeExtensions` provides a set of utility methods that
|
|
22
|
+
* are added to the `Number` prototype. This allows all number instances
|
|
23
|
+
* to access new functionality directly, enhancing their capabilities
|
|
24
|
+
* beyond the standard `Number` class methods.
|
|
25
|
+
*
|
|
26
|
+
* These extensions are applied using the `Patch` class from
|
|
27
|
+
* '@nejs/extension', ensuring that they do not interfere with the
|
|
28
|
+
* global namespace or existing properties.
|
|
29
|
+
*
|
|
30
|
+
* The extensions include methods for checking if a value is a number,
|
|
31
|
+
* conditionally returning values based on whether a value is a number,
|
|
32
|
+
* and more, making number-related tasks more convenient and expressive.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const num = 42
|
|
36
|
+
* console.log(num.isNumber) // Output: true
|
|
37
|
+
*
|
|
38
|
+
* const notNum = "123"
|
|
39
|
+
* console.log(notNum.isNumber) // Output: false
|
|
40
|
+
*
|
|
41
|
+
* @type {Patch}
|
|
42
|
+
*/
|
|
43
|
+
export const NumberPrototypeExtensions: Patch;
|
|
44
|
+
import { Patch } from '@nejs/extension';
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberPrototypeExtensions = exports.NumberExtensions = void 0;
|
|
4
|
+
const extension_1 = require("@nejs/extension");
|
|
5
|
+
/**
|
|
6
|
+
* A patch for the JavaScript built-in `Number` class that adds utility
|
|
7
|
+
* methods without modifying the global namespace directly
|
|
8
|
+
*
|
|
9
|
+
* This patch includes methods for checking if a value is a number and
|
|
10
|
+
* conditionally returning a value based on whether the supplied value is
|
|
11
|
+
* a number or not.
|
|
12
|
+
*
|
|
13
|
+
* @type {Patch}
|
|
14
|
+
* @property {Object} [Patch.kMutablyHidden] An object containing methods
|
|
15
|
+
* that are hidden from enumeration and mutation
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { NumberExtensions } from 'number.extension.js'
|
|
19
|
+
*
|
|
20
|
+
* NumberExtensions.apply()
|
|
21
|
+
* // Now the `Number` class has additional methods available
|
|
22
|
+
*/
|
|
23
|
+
exports.NumberExtensions = new extension_1.Patch(Number, {
|
|
24
|
+
[extension_1.Patch.kMutablyHidden]: {
|
|
25
|
+
/**
|
|
26
|
+
* Determines if the supplied `value` is a `Number`. This check is
|
|
27
|
+
* performed by first converting the `value` to a `Number` using the
|
|
28
|
+
* `Number()` constructor and checking to see if the result is not
|
|
29
|
+
* `NaN`. If that check passes, `typeof` is used to ensure that the
|
|
30
|
+
* original `value` is of type "number".
|
|
31
|
+
*
|
|
32
|
+
* @param {*} value The value that needs to be checked to determine if it
|
|
33
|
+
* is a `Number` or not
|
|
34
|
+
* @returns {boolean} `true` if the supplied `value` is a `Number`,
|
|
35
|
+
* `false` otherwise
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const num = 42
|
|
39
|
+
* isNumber(num) // true
|
|
40
|
+
* isNumber('42') // false
|
|
41
|
+
* isNumber(NaN) // false
|
|
42
|
+
* isNumber(Infinity) // true
|
|
43
|
+
*/
|
|
44
|
+
isNumber(value) {
|
|
45
|
+
return !isNaN(value) && typeof value === 'number';
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* Checks if all or some of the supplied values are numbers.
|
|
49
|
+
*
|
|
50
|
+
* This method uses the `Array.prototype.every` or `Array.prototype.some`
|
|
51
|
+
* method to check if all or some of the supplied values are numbers,
|
|
52
|
+
* respectively. The method to use is determined by the `which` parameter.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} [which='every'] - Determines the method to use for the
|
|
55
|
+
* check. Can be either 'every' or 'some'. Defaults to 'every'.
|
|
56
|
+
* @param {...*} values - The values to check.
|
|
57
|
+
* @returns {boolean} - Returns `true` if all or some of the values are
|
|
58
|
+
* numbers (based on the `which` parameter), `false` otherwise.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* areNumbers('every', 1, 2, 3) // true
|
|
62
|
+
* areNumbers('some', 1, '2', 3) // true
|
|
63
|
+
* areNumbers('every', 1, '2', 3) // false
|
|
64
|
+
*/
|
|
65
|
+
areNumbers(which = ['every', 'some'][0], ...values) {
|
|
66
|
+
if (which !== 'every' && which !== 'some') {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return values[which](num => this.isNumber(num));
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* Conditionally returns a value based on whether the supplied `value` is
|
|
73
|
+
* a `Number` or not. If the `value` is a `Number`, the `thenValue` will
|
|
74
|
+
* be returned. If it is not a `Number`, the `elseValue` will be
|
|
75
|
+
* returned instead.
|
|
76
|
+
*
|
|
77
|
+
* @param {*} value The value to check to determine if it is a `Number`
|
|
78
|
+
* @param {*} thenValue The value to return if the supplied `value` is
|
|
79
|
+
* a `Number`
|
|
80
|
+
* @param {*} elseValue The value to return if the supplied `value` is
|
|
81
|
+
* not a `Number`
|
|
82
|
+
* @returns {*} Either the `thenValue` or `elseValue` depending on if the
|
|
83
|
+
* supplied `value` is a `Number`
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* const num = 42
|
|
87
|
+
* const str = 'hello'
|
|
88
|
+
* ifNumber(num, 'is a number', 'not a number') // 'is a number'
|
|
89
|
+
* ifNumber(str, 'is a number', 'not a number') // 'not a number'
|
|
90
|
+
*/
|
|
91
|
+
ifNumber(value, thenValue, elseValue) {
|
|
92
|
+
return isThenElse(this.isNumber(value), thenValue, elseValue);
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* Conditionally returns a value based on whether all or some of the
|
|
96
|
+
* supplied values are numbers.
|
|
97
|
+
*
|
|
98
|
+
* This method uses the `areNumbers` method to check if all or some of
|
|
99
|
+
* the supplied values are numbers, based on the `which` parameter.
|
|
100
|
+
* If the condition is met, the `thenValue` is returned, otherwise
|
|
101
|
+
* the `elseValue` is returned.
|
|
102
|
+
*
|
|
103
|
+
* @param {*} thenValue - The value to return if the condition is met.
|
|
104
|
+
* @param {*} elseValue - The value to return if the condition is not met.
|
|
105
|
+
* @param {string} [which='every'] - Determines the method to use for the
|
|
106
|
+
* check. Can be either 'every' or 'some'. Defaults to 'every'.
|
|
107
|
+
* @param {...*} numbers - The values to check.
|
|
108
|
+
* @returns {*} Either the `thenValue` or `elseValue` depending on if all
|
|
109
|
+
* or some of the supplied values are numbers.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ifNumbers('All are numbers', 'Not all are numbers', 'every', 1, 2, 3)
|
|
113
|
+
* // returns 'All are numbers'
|
|
114
|
+
* ifNumbers('At least one is a number', 'None are numbers', 'some', 1, '2', 3)
|
|
115
|
+
* // returns 'At least one is a number'
|
|
116
|
+
* ifNumbers('All are numbers', 'Not all are numbers', 'every', 1, '2', 3)
|
|
117
|
+
* // returns 'Not all are numbers'
|
|
118
|
+
*/
|
|
119
|
+
ifNumbers(thenValue, elseValue, which = ['every', 'some'][0], ...numbers) {
|
|
120
|
+
return isThenElse(this.areNumbers(which, ...numbers), thenValue, elseValue);
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* Clamps a value between a minimum and maximum value.
|
|
124
|
+
*
|
|
125
|
+
* This method checks if the provided value and the min and max bounds are
|
|
126
|
+
* numbers. If they are not, it returns the original value. If they are,
|
|
127
|
+
* it ensures that the value does not go below the minimum value or above
|
|
128
|
+
* the maximum value.
|
|
129
|
+
*
|
|
130
|
+
* @param {*} value - The value to clamp.
|
|
131
|
+
* @param {number} [minValue=-Infinity] - The minimum value. Defaults
|
|
132
|
+
* to -Infinity.
|
|
133
|
+
* @param {number} [maxValue=Infinity] - The maximum value. Defaults
|
|
134
|
+
* to Infinity.
|
|
135
|
+
* @returns {*} - Returns the clamped value if all parameters are numbers,
|
|
136
|
+
* otherwise returns the original value.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* clamp(10, 1, 5) // returns 5
|
|
140
|
+
* clamp(-10, 1, 5) // returns 1
|
|
141
|
+
* clamp(3, 1, 5) // returns 3
|
|
142
|
+
* clamp('10', 1, 5) // returns '10'
|
|
143
|
+
*/
|
|
144
|
+
clamp(value, minValue = -Infinity, maxValue = Infinity) {
|
|
145
|
+
if (!this.areNumbers('every', value, minValue, maxValue)) {
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
return Math.max(minValue, Math.min(maxValue, value));
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const { isNumber: pIsNumber, ifNumber: pIfNumber } = exports.NumberExtensions.patches;
|
|
153
|
+
/**
|
|
154
|
+
* `NumberPrototypeExtensions` provides a set of utility methods that
|
|
155
|
+
* are added to the `Number` prototype. This allows all number instances
|
|
156
|
+
* to access new functionality directly, enhancing their capabilities
|
|
157
|
+
* beyond the standard `Number` class methods.
|
|
158
|
+
*
|
|
159
|
+
* These extensions are applied using the `Patch` class from
|
|
160
|
+
* '@nejs/extension', ensuring that they do not interfere with the
|
|
161
|
+
* global namespace or existing properties.
|
|
162
|
+
*
|
|
163
|
+
* The extensions include methods for checking if a value is a number,
|
|
164
|
+
* conditionally returning values based on whether a value is a number,
|
|
165
|
+
* and more, making number-related tasks more convenient and expressive.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* const num = 42
|
|
169
|
+
* console.log(num.isNumber) // Output: true
|
|
170
|
+
*
|
|
171
|
+
* const notNum = "123"
|
|
172
|
+
* console.log(notNum.isNumber) // Output: false
|
|
173
|
+
*
|
|
174
|
+
* @type {Patch}
|
|
175
|
+
*/
|
|
176
|
+
exports.NumberPrototypeExtensions = new extension_1.Patch(Number.prototype, {
|
|
177
|
+
[extension_1.Patch.kMutablyHidden]: {
|
|
178
|
+
/**
|
|
179
|
+
* Returns an object representation of the number instance.
|
|
180
|
+
*
|
|
181
|
+
* This getter method creates and returns an object that wraps the number
|
|
182
|
+
* instance, allowing it to be treated as an object. The returned object
|
|
183
|
+
* is created using the `Object()` constructor, which takes the number
|
|
184
|
+
* instance as its argument.
|
|
185
|
+
*
|
|
186
|
+
* @type {Object}
|
|
187
|
+
* @readonly
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* const num = 42
|
|
191
|
+
* console.log(typeof num) // 'number'
|
|
192
|
+
* console.log(typeof num.instance) // 'object'
|
|
193
|
+
*/
|
|
194
|
+
get instance() {
|
|
195
|
+
return Object(this);
|
|
196
|
+
},
|
|
197
|
+
/**
|
|
198
|
+
* Determines if the current object is a number
|
|
199
|
+
*
|
|
200
|
+
* This getter uses the `pIsNumber` function from the `NumberExtensions`
|
|
201
|
+
* patch to check if the current object (`this`) is a number.
|
|
202
|
+
*
|
|
203
|
+
* @type {boolean}
|
|
204
|
+
* @readonly
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* const num = 42
|
|
208
|
+
* console.log(num.isNumber) // Output: true
|
|
209
|
+
*
|
|
210
|
+
* const notNum = "123"
|
|
211
|
+
* console.log(notNum.isNumber) // Output: false
|
|
212
|
+
*/
|
|
213
|
+
get isNumber() {
|
|
214
|
+
return pIsNumber(this);
|
|
215
|
+
},
|
|
216
|
+
/**
|
|
217
|
+
* Checks if the current object is a number and returns the corresponding
|
|
218
|
+
* value based on the result.
|
|
219
|
+
*
|
|
220
|
+
* This method uses the `pIfNumber` function from the `NumberExtensions`
|
|
221
|
+
* patch to determine if the current object (`this`) is a number. If it is
|
|
222
|
+
* a number, the `thenValue` is returned. Otherwise, the `elseValue` is
|
|
223
|
+
* returned.
|
|
224
|
+
*
|
|
225
|
+
* @param {any} thenValue The value to return if the current object is
|
|
226
|
+
* a number
|
|
227
|
+
* @param {any} elseValue The value to return if the current object is not
|
|
228
|
+
* a number
|
|
229
|
+
* @returns {any} The `thenValue` if the current object is a number, or
|
|
230
|
+
* the `elseValue` if it is not a number
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* const num = 42
|
|
234
|
+
* console.log(num.ifNumber('Is a number', 'Not a number'))
|
|
235
|
+
* // Output: 'Is a number'
|
|
236
|
+
*
|
|
237
|
+
* const notNum = '123'
|
|
238
|
+
* console.log(notNum.ifNumber('Is a number', 'Not a number'))
|
|
239
|
+
* // Output: 'Not a number'
|
|
240
|
+
*/
|
|
241
|
+
ifNumber(thenValue, elseValue) {
|
|
242
|
+
return pIfNumber(this, thenValue, elseValue);
|
|
243
|
+
},
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
// NOTE to self; this is repeated here otherwise a circular reference from
|
|
247
|
+
// Object<->Function<->Global occurs. See original source in global.this.js
|
|
248
|
+
// {@see globalThis.isThenElse}
|
|
249
|
+
function isThenElse(bv, tv, ev) {
|
|
250
|
+
if (arguments.length > 1) {
|
|
251
|
+
var _then = isFunction(tv) ? tv(bv) : tv;
|
|
252
|
+
if (arguments.length > 2) {
|
|
253
|
+
var _else = isFunction(ev) ? tv(bv) : ev;
|
|
254
|
+
return bv ? _then : _else;
|
|
255
|
+
}
|
|
256
|
+
return bv || _then;
|
|
257
|
+
}
|
|
258
|
+
return bv;
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=number.extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.extension.js","sourceRoot":"","sources":["../../src/number.extension.js"],"names":[],"mappings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AM,GAAG,CAAC,EAAE,CAAC;YACnE,IAAI,KAAK,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;QACrE,CAAC;QAAC,OAAO,EAAE,IAAI,KAAK,CAAC;IACvB,CAAC;IAAC,OAAO,EAAE,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a deep or shallow copy of the provided source objects and merges
|
|
3
|
+
* them into the destination object. The function uses a Set to keep track
|
|
4
|
+
* of visited objects to avoid circular references.
|
|
5
|
+
*
|
|
6
|
+
* @function
|
|
7
|
+
* @name copyObject
|
|
8
|
+
* @param {boolean} deep - If true, performs a deep copy, otherwise performs
|
|
9
|
+
* a shallow copy.
|
|
10
|
+
* @param {object} destination - The object to which properties will be copied.
|
|
11
|
+
* @param {...object} sources - The source object(s) from which properties
|
|
12
|
+
* will be copied.
|
|
13
|
+
* @returns {object} The destination object with the copied properties.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Shallow copy
|
|
17
|
+
* const obj1 = { a: 1, b: { c: 2 } };
|
|
18
|
+
* const obj2 = { b: { d: 3 }, e: 4 };
|
|
19
|
+
* const result = copyObject(false, obj1, obj2);
|
|
20
|
+
* console.log(result); // Output: { a: 1, b: { d: 3 }, e: 4 }
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Deep copy
|
|
24
|
+
* const obj1 = { a: 1, b: { c: 2 } };
|
|
25
|
+
* const obj2 = { b: { d: 3 }, e: 4 };
|
|
26
|
+
* const result = copyObject(true, obj1, obj2);
|
|
27
|
+
* console.log(result); // Output: { a: 1, b: { c: 2, d: 3 }, e: 4 }
|
|
28
|
+
*/
|
|
29
|
+
export function copyObject(deep: boolean, destination: object, ...sources: object[]): object;
|
|
30
|
+
/**
|
|
31
|
+
* `ObjectExtensions` is a constant that applies a patch to the global
|
|
32
|
+
* `Object` constructor. This patch extends the `Object` with additional
|
|
33
|
+
* methods and properties, enhancing its functionality.
|
|
34
|
+
*
|
|
35
|
+
* The `Patch` function takes two arguments: the target object to be patched
|
|
36
|
+
* (in this case, `Object`), and an object containing the methods and
|
|
37
|
+
* properties to be added to the target object.
|
|
38
|
+
*
|
|
39
|
+
* @type {Patch}
|
|
40
|
+
* @memberof module:object.extensions
|
|
41
|
+
*/
|
|
42
|
+
export const ObjectExtensions: Patch;
|
|
43
|
+
/**
|
|
44
|
+
* `ObjectPrototypeExtensions` is a constant that applies a patch to the
|
|
45
|
+
* Object prototype. This patch extends the Object prototype with additional
|
|
46
|
+
* methods and properties, enhancing its functionality.
|
|
47
|
+
*
|
|
48
|
+
* The `Patch` function takes two arguments: the target object to be patched
|
|
49
|
+
* (in this case, `Object.prototype`), and an object containing the methods
|
|
50
|
+
* and properties to be added to the target object.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Using a method added by ObjectPrototypeExtensions
|
|
54
|
+
* const obj = {};
|
|
55
|
+
* console.log(obj.isObject()); // Output: true
|
|
56
|
+
*
|
|
57
|
+
* @const
|
|
58
|
+
* @type {Patch}
|
|
59
|
+
* @memberof module:object.extensions
|
|
60
|
+
*/
|
|
61
|
+
export const ObjectPrototypeExtensions: Patch;
|
|
62
|
+
import { Patch } from '@nejs/extension';
|