@nejs/basic-extensions 2.21.5 → 2.22.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/README.md +78 -4
  2. package/dist/@nejs/basic-extensions.bundle.2.22.6.js +25 -0
  3. package/dist/@nejs/basic-extensions.bundle.2.22.6.js.map +7 -0
  4. package/dist/cjs/classes/index.cjs +11129 -0
  5. package/dist/cjs/classes/index.cjs.map +7 -0
  6. package/dist/cjs/index.cjs +15191 -0
  7. package/dist/cjs/index.cjs.map +7 -0
  8. package/dist/cjs/utils/index.cjs +3954 -0
  9. package/dist/cjs/utils/index.cjs.map +7 -0
  10. package/dist/esm/basic-extensions.mjs +25 -0
  11. package/dist/esm/basic-extensions.mjs.map +7 -0
  12. package/package.json +16 -22
  13. package/repl.bootstrap.js +4 -7
  14. package/repl.history +26 -26
  15. package/src/classes/enumeration.js +466 -0
  16. package/src/classes/index.js +5 -1
  17. package/src/index.js +3 -1
  18. package/src/regular.expression.extensions.js +0 -35
  19. package/src/utils/toolkit.js +699 -516
  20. package/tests/arrayextensions.test.js +3 -3
  21. package/tests/index.test.js +3 -1
  22. package/tests/newClasses/asyncIterable.test.js +3 -3
  23. package/tests/newClasses/deferred.test.js +3 -3
  24. package/tests/newClasses/descriptor.test.js +3 -3
  25. package/tests/newClasses/iterable.test.js +3 -3
  26. package/tests/newClasses/refmap.test.js +3 -3
  27. package/tests/newClasses/refset.test.js +3 -3
  28. package/tests/objectextensions.test.js +3 -3
  29. package/tests/setextensions.test.js +3 -3
  30. package/tests/stringextensions.test.js +3 -2
  31. package/tests/utils/descriptor.utils.test.js +1 -1
  32. package/tests/utils/toolkit.test.js +429 -163
  33. package/.esdoc.json +0 -9
  34. package/.vscode/settings.json +0 -5
  35. package/bin/build +0 -27
  36. package/bin/clean +0 -14
  37. package/bin/esbuild +0 -91
  38. package/bin/fixup +0 -13
  39. package/bin/repl.basics.js +0 -584
  40. package/bin/repl.signature.js +0 -63
  41. package/bin/version +0 -100
  42. package/dist/@nejs/basic-extensions.bundle.2.21.5.js +0 -25
  43. package/dist/@nejs/basic-extensions.bundle.2.21.5.js.map +0 -7
  44. package/dist/cjs/array.extensions.d.ts +0 -39
  45. package/dist/cjs/array.extensions.js +0 -477
  46. package/dist/cjs/array.extensions.js.map +0 -1
  47. package/dist/cjs/big.int.extension.d.ts +0 -31
  48. package/dist/cjs/big.int.extension.js +0 -273
  49. package/dist/cjs/big.int.extension.js.map +0 -1
  50. package/dist/cjs/classes/asyncIterable.d.ts +0 -126
  51. package/dist/cjs/classes/asyncIterable.js +0 -209
  52. package/dist/cjs/classes/asyncIterable.js.map +0 -1
  53. package/dist/cjs/classes/deferred.d.ts +0 -146
  54. package/dist/cjs/classes/deferred.js +0 -291
  55. package/dist/cjs/classes/deferred.js.map +0 -1
  56. package/dist/cjs/classes/descriptor.d.ts +0 -334
  57. package/dist/cjs/classes/descriptor.js +0 -537
  58. package/dist/cjs/classes/descriptor.js.map +0 -1
  59. package/dist/cjs/classes/enum.d.ts +0 -50
  60. package/dist/cjs/classes/enum.js +0 -405
  61. package/dist/cjs/classes/enum.js.map +0 -1
  62. package/dist/cjs/classes/index.d.ts +0 -15
  63. package/dist/cjs/classes/index.js +0 -63
  64. package/dist/cjs/classes/index.js.map +0 -1
  65. package/dist/cjs/classes/introspector.d.ts +0 -20
  66. package/dist/cjs/classes/introspector.js +0 -130
  67. package/dist/cjs/classes/introspector.js.map +0 -1
  68. package/dist/cjs/classes/iterable.d.ts +0 -169
  69. package/dist/cjs/classes/iterable.js +0 -268
  70. package/dist/cjs/classes/iterable.js.map +0 -1
  71. package/dist/cjs/classes/param.parser.d.ts +0 -221
  72. package/dist/cjs/classes/param.parser.js +0 -242
  73. package/dist/cjs/classes/param.parser.js.map +0 -1
  74. package/dist/cjs/classes/pluggable.proxy.d.ts +0 -153
  75. package/dist/cjs/classes/pluggable.proxy.js +0 -444
  76. package/dist/cjs/classes/pluggable.proxy.js.map +0 -1
  77. package/dist/cjs/classes/property.d.ts +0 -79
  78. package/dist/cjs/classes/property.js +0 -284
  79. package/dist/cjs/classes/property.js.map +0 -1
  80. package/dist/cjs/classes/refmap.d.ts +0 -238
  81. package/dist/cjs/classes/refmap.js +0 -421
  82. package/dist/cjs/classes/refmap.js.map +0 -1
  83. package/dist/cjs/classes/refset.d.ts +0 -186
  84. package/dist/cjs/classes/refset.js +0 -370
  85. package/dist/cjs/classes/refset.js.map +0 -1
  86. package/dist/cjs/classes/symkeys.d.ts +0 -349
  87. package/dist/cjs/classes/symkeys.js +0 -510
  88. package/dist/cjs/classes/symkeys.js.map +0 -1
  89. package/dist/cjs/classes/type.d.ts +0 -56
  90. package/dist/cjs/classes/type.js +0 -405
  91. package/dist/cjs/classes/type.js.map +0 -1
  92. package/dist/cjs/function.extensions.d.ts +0 -12
  93. package/dist/cjs/function.extensions.js +0 -758
  94. package/dist/cjs/function.extensions.js.map +0 -1
  95. package/dist/cjs/global.this.d.ts +0 -2
  96. package/dist/cjs/global.this.js +0 -300
  97. package/dist/cjs/global.this.js.map +0 -1
  98. package/dist/cjs/index.d.ts +0 -31
  99. package/dist/cjs/index.js +0 -228
  100. package/dist/cjs/index.js.map +0 -1
  101. package/dist/cjs/json.extensions.d.ts +0 -2
  102. package/dist/cjs/json.extensions.js +0 -109
  103. package/dist/cjs/json.extensions.js.map +0 -1
  104. package/dist/cjs/map.extensions.d.ts +0 -3
  105. package/dist/cjs/map.extensions.js +0 -143
  106. package/dist/cjs/map.extensions.js.map +0 -1
  107. package/dist/cjs/math.extension.d.ts +0 -14
  108. package/dist/cjs/math.extension.js +0 -71
  109. package/dist/cjs/math.extension.js.map +0 -1
  110. package/dist/cjs/number.extension.d.ts +0 -44
  111. package/dist/cjs/number.extension.js +0 -278
  112. package/dist/cjs/number.extension.js.map +0 -1
  113. package/dist/cjs/object.extensions.d.ts +0 -33
  114. package/dist/cjs/object.extensions.js +0 -1091
  115. package/dist/cjs/object.extensions.js.map +0 -1
  116. package/dist/cjs/package.json +0 -3
  117. package/dist/cjs/proxy.extensions.d.ts +0 -2
  118. package/dist/cjs/proxy.extensions.js +0 -207
  119. package/dist/cjs/proxy.extensions.js.map +0 -1
  120. package/dist/cjs/reflect.extensions.d.ts +0 -14
  121. package/dist/cjs/reflect.extensions.js +0 -316
  122. package/dist/cjs/reflect.extensions.js.map +0 -1
  123. package/dist/cjs/regular.expression.extensions.d.ts +0 -2
  124. package/dist/cjs/regular.expression.extensions.js +0 -423
  125. package/dist/cjs/regular.expression.extensions.js.map +0 -1
  126. package/dist/cjs/set.extensions.d.ts +0 -40
  127. package/dist/cjs/set.extensions.js +0 -355
  128. package/dist/cjs/set.extensions.js.map +0 -1
  129. package/dist/cjs/string.extensions.d.ts +0 -23
  130. package/dist/cjs/string.extensions.js +0 -704
  131. package/dist/cjs/string.extensions.js.map +0 -1
  132. package/dist/cjs/symbol.extensions.d.ts +0 -11
  133. package/dist/cjs/symbol.extensions.js +0 -735
  134. package/dist/cjs/symbol.extensions.js.map +0 -1
  135. package/dist/cjs/utils/copy.object.d.ts +0 -408
  136. package/dist/cjs/utils/copy.object.js +0 -720
  137. package/dist/cjs/utils/copy.object.js.map +0 -1
  138. package/dist/cjs/utils/descriptor.utils.d.ts +0 -298
  139. package/dist/cjs/utils/descriptor.utils.js +0 -889
  140. package/dist/cjs/utils/descriptor.utils.js.map +0 -1
  141. package/dist/cjs/utils/index.d.ts +0 -75
  142. package/dist/cjs/utils/index.js +0 -61
  143. package/dist/cjs/utils/index.js.map +0 -1
  144. package/dist/cjs/utils/stdout.d.ts +0 -742
  145. package/dist/cjs/utils/stdout.js +0 -1042
  146. package/dist/cjs/utils/stdout.js.map +0 -1
  147. package/dist/cjs/utils/toolkit.d.ts +0 -1898
  148. package/dist/cjs/utils/toolkit.js +0 -1378
  149. package/dist/cjs/utils/toolkit.js.map +0 -1
  150. package/dist/cjs/weakref.extensions.d.ts +0 -2
  151. package/dist/cjs/weakref.extensions.js +0 -19
  152. package/dist/cjs/weakref.extensions.js.map +0 -1
  153. package/dist/mjs/array.extensions.d.ts +0 -39
  154. package/dist/mjs/array.extensions.js +0 -474
  155. package/dist/mjs/array.extensions.js.map +0 -1
  156. package/dist/mjs/big.int.extension.d.ts +0 -31
  157. package/dist/mjs/big.int.extension.js +0 -270
  158. package/dist/mjs/big.int.extension.js.map +0 -1
  159. package/dist/mjs/classes/asyncIterable.d.ts +0 -126
  160. package/dist/mjs/classes/asyncIterable.js +0 -204
  161. package/dist/mjs/classes/asyncIterable.js.map +0 -1
  162. package/dist/mjs/classes/deferred.d.ts +0 -146
  163. package/dist/mjs/classes/deferred.js +0 -287
  164. package/dist/mjs/classes/deferred.js.map +0 -1
  165. package/dist/mjs/classes/descriptor.d.ts +0 -334
  166. package/dist/mjs/classes/descriptor.js +0 -533
  167. package/dist/mjs/classes/descriptor.js.map +0 -1
  168. package/dist/mjs/classes/enum.d.ts +0 -50
  169. package/dist/mjs/classes/enum.js +0 -400
  170. package/dist/mjs/classes/enum.js.map +0 -1
  171. package/dist/mjs/classes/index.d.ts +0 -15
  172. package/dist/mjs/classes/index.js +0 -46
  173. package/dist/mjs/classes/index.js.map +0 -1
  174. package/dist/mjs/classes/introspector.d.ts +0 -20
  175. package/dist/mjs/classes/introspector.js +0 -126
  176. package/dist/mjs/classes/introspector.js.map +0 -1
  177. package/dist/mjs/classes/iterable.d.ts +0 -169
  178. package/dist/mjs/classes/iterable.js +0 -263
  179. package/dist/mjs/classes/iterable.js.map +0 -1
  180. package/dist/mjs/classes/param.parser.d.ts +0 -221
  181. package/dist/mjs/classes/param.parser.js +0 -238
  182. package/dist/mjs/classes/param.parser.js.map +0 -1
  183. package/dist/mjs/classes/pluggable.proxy.d.ts +0 -153
  184. package/dist/mjs/classes/pluggable.proxy.js +0 -438
  185. package/dist/mjs/classes/pluggable.proxy.js.map +0 -1
  186. package/dist/mjs/classes/property.d.ts +0 -79
  187. package/dist/mjs/classes/property.js +0 -280
  188. package/dist/mjs/classes/property.js.map +0 -1
  189. package/dist/mjs/classes/refmap.d.ts +0 -238
  190. package/dist/mjs/classes/refmap.js +0 -417
  191. package/dist/mjs/classes/refmap.js.map +0 -1
  192. package/dist/mjs/classes/refset.d.ts +0 -186
  193. package/dist/mjs/classes/refset.js +0 -366
  194. package/dist/mjs/classes/refset.js.map +0 -1
  195. package/dist/mjs/classes/symkeys.d.ts +0 -349
  196. package/dist/mjs/classes/symkeys.js +0 -506
  197. package/dist/mjs/classes/symkeys.js.map +0 -1
  198. package/dist/mjs/classes/type.d.ts +0 -56
  199. package/dist/mjs/classes/type.js +0 -401
  200. package/dist/mjs/classes/type.js.map +0 -1
  201. package/dist/mjs/function.extensions.d.ts +0 -12
  202. package/dist/mjs/function.extensions.js +0 -755
  203. package/dist/mjs/function.extensions.js.map +0 -1
  204. package/dist/mjs/global.this.d.ts +0 -2
  205. package/dist/mjs/global.this.js +0 -264
  206. package/dist/mjs/global.this.js.map +0 -1
  207. package/dist/mjs/index.d.ts +0 -31
  208. package/dist/mjs/index.js +0 -206
  209. package/dist/mjs/index.js.map +0 -1
  210. package/dist/mjs/json.extensions.d.ts +0 -2
  211. package/dist/mjs/json.extensions.js +0 -106
  212. package/dist/mjs/json.extensions.js.map +0 -1
  213. package/dist/mjs/map.extensions.d.ts +0 -3
  214. package/dist/mjs/map.extensions.js +0 -140
  215. package/dist/mjs/map.extensions.js.map +0 -1
  216. package/dist/mjs/math.extension.d.ts +0 -14
  217. package/dist/mjs/math.extension.js +0 -68
  218. package/dist/mjs/math.extension.js.map +0 -1
  219. package/dist/mjs/number.extension.d.ts +0 -44
  220. package/dist/mjs/number.extension.js +0 -275
  221. package/dist/mjs/number.extension.js.map +0 -1
  222. package/dist/mjs/object.extensions.d.ts +0 -33
  223. package/dist/mjs/object.extensions.js +0 -1088
  224. package/dist/mjs/object.extensions.js.map +0 -1
  225. package/dist/mjs/package.json +0 -3
  226. package/dist/mjs/proxy.extensions.d.ts +0 -2
  227. package/dist/mjs/proxy.extensions.js +0 -204
  228. package/dist/mjs/proxy.extensions.js.map +0 -1
  229. package/dist/mjs/reflect.extensions.d.ts +0 -14
  230. package/dist/mjs/reflect.extensions.js +0 -313
  231. package/dist/mjs/reflect.extensions.js.map +0 -1
  232. package/dist/mjs/regular.expression.extensions.d.ts +0 -2
  233. package/dist/mjs/regular.expression.extensions.js +0 -420
  234. package/dist/mjs/regular.expression.extensions.js.map +0 -1
  235. package/dist/mjs/set.extensions.d.ts +0 -40
  236. package/dist/mjs/set.extensions.js +0 -352
  237. package/dist/mjs/set.extensions.js.map +0 -1
  238. package/dist/mjs/string.extensions.d.ts +0 -23
  239. package/dist/mjs/string.extensions.js +0 -701
  240. package/dist/mjs/string.extensions.js.map +0 -1
  241. package/dist/mjs/symbol.extensions.d.ts +0 -11
  242. package/dist/mjs/symbol.extensions.js +0 -732
  243. package/dist/mjs/symbol.extensions.js.map +0 -1
  244. package/dist/mjs/utils/copy.object.d.ts +0 -408
  245. package/dist/mjs/utils/copy.object.js +0 -702
  246. package/dist/mjs/utils/copy.object.js.map +0 -1
  247. package/dist/mjs/utils/descriptor.utils.d.ts +0 -298
  248. package/dist/mjs/utils/descriptor.utils.js +0 -875
  249. package/dist/mjs/utils/descriptor.utils.js.map +0 -1
  250. package/dist/mjs/utils/index.d.ts +0 -75
  251. package/dist/mjs/utils/index.js +0 -45
  252. package/dist/mjs/utils/index.js.map +0 -1
  253. package/dist/mjs/utils/stdout.d.ts +0 -742
  254. package/dist/mjs/utils/stdout.js +0 -1037
  255. package/dist/mjs/utils/stdout.js.map +0 -1
  256. package/dist/mjs/utils/toolkit.d.ts +0 -1898
  257. package/dist/mjs/utils/toolkit.js +0 -1373
  258. package/dist/mjs/utils/toolkit.js.map +0 -1
  259. package/dist/mjs/weakref.extensions.d.ts +0 -2
  260. package/dist/mjs/weakref.extensions.js +0 -16
  261. package/dist/mjs/weakref.extensions.js.map +0 -1
  262. package/jsdoc-config.json +0 -31
  263. package/tsconfig.base.json +0 -28
  264. package/tsconfig.cjs.json +0 -8
  265. package/tsconfig.esm.json +0 -8
  266. package/vitest.config.js +0 -7
@@ -1,106 +0,0 @@
1
- import { Patch } from '@nejs/extension';
2
- export const JSONExtensions = new Patch(JSON, {
3
- [Patch.kMutablyHidden]: {
4
- extractAllFrom(string) {
5
- const pattern = this.JSONStartPattern;
6
- const notJSON = Symbol("Value is not valid JSON");
7
- const decoder = part => {
8
- try {
9
- return JSON.parse(part);
10
- }
11
- catch (_) {
12
- return notJSON;
13
- }
14
- };
15
- const parts = [];
16
- let part = undefined;
17
- while ((part = pattern.exec(string))) {
18
- parts.push(decoder(part?.[0]));
19
- }
20
- return parts.filter(isJSON => isJSON !== notJSON);
21
- },
22
- /**
23
- * The `extractFrom` method attempts to extract a JSON object from a string.
24
- * It uses a regular expression to identify potential JSON objects in the
25
- * string and attempts to parse them. If a valid JSON object is found, it is
26
- * returned. If no valid JSON object is found, the method returns undefined.
27
- *
28
- * NOTE: This method will only find JSON from an iterated upon start spot
29
- * until the end of the string. So `'JSON follows {"count": 0}'` will
30
- * return `{count: 0}` but `'JSON follows {"count": 0} and more'` will
31
- * fail to locate any JSON in the String. You've been warned.
32
- *
33
- * @param {string} string - The string from which to extract a JSON object.
34
- * @returns {Object|undefined} - The first valid JSON object found in the
35
- * string, or undefined if no valid JSON object is found.
36
- *
37
- * @example
38
- * // Suppose we have a string with embedded JSON
39
- * const str1 = 'Hello {"name":"John", "age":30} World'
40
- * const str2 = 'Hello {"name": "John", "age": 30}'
41
- *
42
- * // Using `extractFrom`
43
- * console.log(JSON.extractFrom(str1)) // Output: undefined
44
- * console.log(JSON.extractFrom(str2)) // Output: {name: 'John', age: 30}
45
- */
46
- extractFrom(string) {
47
- this.extractAllFrom(string)?.[0];
48
- },
49
- /**
50
- * The `mightContain` method checks if a string might contain a JSON object.
51
- * It uses the `JSONStartPattern` regular expression to search for potential
52
- * JSON objects in the string. If a potential JSON object is found, the method
53
- * returns true. If no potential JSON object is found, the method returns false.
54
- *
55
- * @param {string} string - The string to check for potential JSON objects.
56
- * @returns {boolean} - Returns true if the string might contain a JSON object,
57
- * false otherwise.
58
- *
59
- * @example
60
- * // Suppose we have a string with embedded JSON
61
- * const str = 'Hello {"name":"John", "age":30} World'
62
- *
63
- * // Using `mightContain`
64
- * console.log(JSON.mightContain(str)) // Output: true
65
- */
66
- mightContain(string, detail = false) {
67
- const results = this.JSONStartPattern.exec(string);
68
- return detail ? [!!results, results?.index ?? -1, results] : !!results;
69
- },
70
- /**
71
- * Getter method for the JSONStartPattern.
72
- *
73
- * This method constructs a regular expression pattern that is used to
74
- * identify potential JSON objects in a string. The pattern is designed
75
- * to match various JSON data types including null, boolean, number,
76
- * string, object, and array.
77
- *
78
- * The pattern is constructed using an array of strings, each representing
79
- * a part of the pattern. The array is then joined into a single string
80
- * and passed to the RegExp constructor to create the pattern.
81
- *
82
- * @returns {RegExp} - The constructed regular expression pattern.
83
- *
84
- * @example
85
- * // Using `JSONStartPattern`
86
- * const pattern = JSONStartPattern;
87
- * const str = 'Hello {"name":"John", "age":30} World';
88
- * const match = pattern.exec(str);
89
- * console.log(match[0]); // Output: '{"name":"John", "age":30}'
90
- */
91
- get JSONStartPattern() {
92
- const pattern = new RegExp([
93
- '(?:', // Start with a non-capturing group and match
94
- '(null)|', // ...a null
95
- '(true|false)|', // ...a bool
96
- '(\\d+\\.?\\d*)|', // ...a number (including floats)
97
- '("[^\\"]*(?:[^:])")|', // ...a double quote (start of string)
98
- '((?:\\{.*\\})+)|', // ...an open curly brace (object)
99
- '((?:\\[.*\\]+))', // ...an open square bracket (array)
100
- ')+', // End of the groups
101
- ].join(''), 'gm');
102
- return pattern;
103
- },
104
- }
105
- });
106
- //# sourceMappingURL=json.extensions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json.extensions.js","sourceRoot":"","sources":["../../src/json.extensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAEvC,MAAM,CAAC,MAAM,cAAc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,CAAC,CAAC,OAAO,CAAA;QACxE,CAAC;QAED;;;;;;;;;;;;;;;;;;;;WAoBG;QACH,IAAI,gBAAgB;YAClB,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC;gBACzB,KAAK,EAAqB,6CAA6C;gBACrE,SAAS,EAAe,YAAY;gBACpC,eAAe,EAAS,YAAY;gBACpC,iBAAiB,EAAO,iCAAiC;gBACzD,sBAAsB,EAAE,sCAAsC;gBAC9D,kBAAkB,EAAM,kCAAkC;gBAC1D,iBAAiB,EAAO,oCAAoC;gBAC9D,IAAI,EAAsB,oBAAoB;aAC/C,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;YAEjB,OAAO,OAAO,CAAA;QAChB,CAAC;KACF;CACF,CAAC,CAAA"}
@@ -1,3 +0,0 @@
1
- export const MapExtensions: Patch;
2
- export const MapPrototypeExtensions: Patch;
3
- import { Patch } from '@nejs/extension';
@@ -1,140 +0,0 @@
1
- import { Patch } from '@nejs/extension';
2
- export const MapExtensions = new Patch(Map, {
3
- [Patch.kMutablyHidden]: {
4
- /**
5
- * Determines if the supplied `value` is a `Map` object. This check
6
- * is performed by first looking for the `Symbol.toStringTag` on the
7
- * `value` and checking to see if it is equal to the string "Map".
8
- * If that check fails, `instanceof` is used as a fallback to check
9
- * the prototype chain.
10
- *
11
- * @param {any} value the value that needs to be checked to determine
12
- * if it is a `Map` object or not
13
- * @returns {boolean} `true` if the supplied `value` is a `Map`
14
- * object, `false` otherwise
15
- *
16
- * @example
17
- * const map = new Map()
18
- * isMap(map) // true
19
- * isMap(new Set()) // false
20
- * isMap([]) // false
21
- * isMap({}) // false
22
- */
23
- isMap(value) {
24
- return value?.[Symbol.toStringTag] === Map.name && value instanceof Map;
25
- },
26
- /**
27
- * Conditionally returns a value based on whether the supplied
28
- * `value` is a `Map` object or not. If the `value` is a `Map`
29
- * object, the `thenValue` will be returned. If it is not a `Map`
30
- * object, the `elseValue` will be returned instead.
31
- *
32
- * @param {any} value the value to check to determine if it is a
33
- * `Map` object
34
- * @param {any} thenValue the value to return if the supplied
35
- * `value` is a `Map` object
36
- * @param {any} elseValue the value to return if the supplied
37
- * `value` is not a `Map` object
38
- * @returns {any} either the `thenValue` or `elseValue` depending
39
- * on if the supplied `value` is a `Map` object
40
- *
41
- * @example
42
- * const map = new Map()
43
- * const set = new Set()
44
- * ifMap(map, 'is a map', 'not a map') // 'is a map'
45
- * ifMap(set, 'is a map', 'not a map') // 'not a map'
46
- */
47
- ifMap(value, thenValue, elseValue) {
48
- return isThenElse(this.isMap(value), thenValue, elseValue);
49
- },
50
- }
51
- });
52
- const { isMap: pIsMap, ifMap: pIfMap } = MapExtensions.patches;
53
- export const MapPrototypeExtensions = new Patch(Map.prototype, {
54
- [Patch.kMutablyHidden]: {
55
- /**
56
- * Determines if the current object is a `Map` object
57
- *
58
- * This is a getter that uses the `isMap` function from the
59
- * `MapExtensions` patch to check if the current object (`this`) is
60
- * a `Map` object
61
- *
62
- * @type {boolean}
63
- * @readonly
64
- *
65
- * @example
66
- * const map = new Map()
67
- * console.log(map.isMap) // Output: true
68
- *
69
- * const notMap = {}
70
- * console.log(notMap.isMap) // Output: false
71
- */
72
- get isMap() {
73
- return pIsMap(this);
74
- },
75
- /**
76
- * Conditionally returns a value based on whether the current
77
- * object is a `Map` object or not
78
- *
79
- * If the current object is a `Map` object, the `thenValue` will
80
- * be returned. If it is not a `Map` object, the `elseValue` will
81
- * be returned instead.
82
- *
83
- * @param {any} thenValue the value to return if the current
84
- * object is a `Map` object
85
- * @param {any} elseValue the value to return if the current
86
- * object is not a `Map` object
87
- * @returns {any} either the `thenValue` or `elseValue` depending
88
- * on if the current object is a `Map` object
89
- *
90
- * @example
91
- * const map = new Map()
92
- * map.ifMap('is a map', 'not a map') // 'is a map'
93
- *
94
- * const notMap = {}
95
- * notMap.ifMap('is a map', 'not a map') // 'not a map'
96
- */
97
- ifMap(thenValue, elseValue) {
98
- return pIfMap(this, thenValue, elseValue);
99
- },
100
- /**
101
- * The function `getKey` returns the key associated with a given value
102
- * in a map.
103
- *
104
- * @param {any} value - The value parameter is the value that you want to
105
- * find the corresponding key for in the map.
106
- * @param [strict=true] - The "strict" parameter is a boolean value that
107
- * determines whether strict equality (===) or loose equality (==) should
108
- * be used when comparing the "value" parameter with the values in the
109
- * entries of the object. If "strict" is set to true, strict equality will
110
- * be used.
111
- * @returns the key associated with the given value. If a matching key is
112
- * found, it is returned. If no matching key is found, null is returned.
113
- */
114
- getKey(value, strict = true) {
115
- for (const [key, entryValue] of this) {
116
- if ((strict && value === entryValue) &&
117
- (!strict && value == entryValue)) {
118
- return key;
119
- }
120
- return null;
121
- }
122
- },
123
- },
124
- });
125
- // NOTE to self; this is repeated here otherwise a circular reference from
126
- // Object<->Function<->Global occurs. See original source in global.this.js
127
- // {@see globalThis.isThenElse}
128
- function isThenElse(bv, tv, ev) {
129
- function isFunction(value) { typeof value === 'function'; }
130
- if (arguments.length > 1) {
131
- var _then = isFunction(tv) ? tv(bv) : tv;
132
- if (arguments.length > 2) {
133
- var _else = isFunction(ev) ? tv(bv) : ev;
134
- return bv ? _then : _else;
135
- }
136
- return bv || _then;
137
- }
138
- return bv;
139
- }
140
- //# sourceMappingURL=map.extensions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"map.extensions.js","sourceRoot":"","sources":["../../src/map.extensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAEvC,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,GAAG,EAAE;IAC1C,CAAC,KAAK,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,KA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,CAAC,EAAE,CAAC;QACzB,IAAI,KAAK,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAAC,IAAI,SAAS,CAAC,MAAM,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"}
@@ -1,14 +0,0 @@
1
- /**
2
- * `Math` extensions. Building better worlds...actually just
3
- * providing some parity between Number and BigInt types for
4
- * now, but later, better worlds.
5
- *
6
- * @type {Patch}
7
- * @example
8
- * import { MathExtensions } from 'math.extension.js'
9
- *
10
- * MathExtensions.apply()
11
- * // Now the `Math` class has additional methods available
12
- */
13
- export const MathExtensions: Patch;
14
- import { Patch } from '@nejs/extension';
@@ -1,68 +0,0 @@
1
- import { Patch } from '@nejs/extension';
2
- /**
3
- * `Math` extensions. Building better worlds...actually just
4
- * providing some parity between Number and BigInt types for
5
- * now, but later, better worlds.
6
- *
7
- * @type {Patch}
8
- * @example
9
- * import { MathExtensions } from 'math.extension.js'
10
- *
11
- * MathExtensions.apply()
12
- * // Now the `Math` class has additional methods available
13
- */
14
- export const MathExtensions = new Patch(Math, {
15
- [Patch.kMutablyHidden]: {
16
- /**
17
- * The Math.min() static method returns the smallest of the numbers given
18
- * as input parameters, or Infinity if there are no parameters.
19
- *
20
- * @param {bigint|number} values value1, …, valueN – Zero or more numbers
21
- * among which the lowest value will be selected and returned.
22
- * @returns {bigint|number|NaN|Infinity} The smallest of the given numbers.
23
- * Returns NaN if any of the parameters is or is converted into NaN or if
24
- * the types of numbers are mismatched (i.e., bigint vs. number types).
25
- * Returns Infinity if no parameters are provided.
26
- */
27
- min(...values) {
28
- const sorter = (l, r) => l < r ? -1 : l > r ? 1 : 0;
29
- if (!values.length)
30
- return Infinity;
31
- if (values.every(n => typeof n === 'bigint')) {
32
- return values.toSorted(sorter).at(0);
33
- }
34
- else if (values.every(n => typeof n === 'number')) {
35
- return values.toSorted(sorter).at(0);
36
- }
37
- else {
38
- return NaN;
39
- }
40
- },
41
- /**
42
- * The Math.max() static method returns the largest of the numbers given
43
- * as input parameters, or Infinity if there are no parameters.
44
- *
45
- * @param {bigint|number} values value1, …, valueN – Zero or more numbers
46
- * among which the largest value will be selected and returned.
47
- * @returns {bigint|number|NaN|Infinity} The largest of the given numbers.
48
- * Returns NaN if any of the parameters is or is converted into NaN or if
49
- * the types of numbers are mismatched (i.e., bigint vs. number types).
50
- * Returns Infinity if no parameters are provided.
51
- */
52
- max(...values) {
53
- const sorter = (l, r) => l < r ? -1 : l > r ? 1 : 0;
54
- if (!values.length)
55
- return Infinity;
56
- if (values.every(n => typeof n === 'bigint')) {
57
- return values.toSorted(sorter).at(-1);
58
- }
59
- else if (values.every(n => typeof n === 'number')) {
60
- return values.toSorted(sorter).at(-1);
61
- }
62
- else {
63
- return NaN;
64
- }
65
- },
66
- },
67
- });
68
- //# sourceMappingURL=math.extension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"math.extension.js","sourceRoot":"","sources":["../../src/math.extension.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAEvC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE;IAC5C,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;QACtB;;;;;;;;;;WAUG;QACH,GAAG,CAAC,GAAG,MAAM;YACX,MAAM,MAAM,GAAG,CAAC,CAAC,EAAC,CAAC,EAAE,EAAE,CAAC,CAA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,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE,CAAC;gBAClD,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;YACvC,CAAC;iBACI,CAAC;gBACJ,OAAO,GAAG,CAAA;YACZ,CAAC;QACH,CAAC;KACF;CACF,CAAC,CAAA"}
@@ -1,44 +0,0 @@
1
- /**
2
- * A patch for the JavaScript built-in `Number` class 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';
@@ -1,275 +0,0 @@
1
- import { Patch } from '@nejs/extension';
2
- /**
3
- * A patch for the JavaScript built-in `Number` class that adds utility
4
- * methods without modifying the global namespace directly
5
- *
6
- * This patch includes methods for checking if a value is a number and
7
- * conditionally returning a value based on whether the supplied value is
8
- * a number or not.
9
- *
10
- * @type {Patch}
11
- * @property {Object} [Patch.kMutablyHidden] An object containing methods
12
- * that are hidden from enumeration and mutation
13
- *
14
- * @example
15
- * import { NumberExtensions } from 'number.extension.js'
16
- *
17
- * NumberExtensions.apply()
18
- * // Now the `Number` class has additional methods available
19
- */
20
- export const NumberExtensions = new Patch(Number, {
21
- [Patch.kMutablyHidden]: {
22
- /**
23
- * Determines if the supplied `value` is a `Number`. This check is
24
- * performed by first converting the `value` to a `Number` using the
25
- * `Number()` constructor and checking to see if the result is not
26
- * `NaN`. If that check passes, `typeof` is used to ensure that the
27
- * original `value` is of type "number".
28
- *
29
- * @param {*} value The value that needs to be checked to determine if it
30
- * is a `Number` or not
31
- * @returns {boolean} `true` if the supplied `value` is a `Number`,
32
- * `false` otherwise
33
- *
34
- * @example
35
- * const num = 42
36
- * isNumber(num) // true
37
- * isNumber('42') // false
38
- * isNumber(NaN) // false
39
- * isNumber(Infinity) // true
40
- */
41
- isNumber(value) {
42
- return !isNaN(value) && typeof value === 'number';
43
- },
44
- /**
45
- * Checks if all or some of the supplied values are numbers.
46
- *
47
- * This method uses the `Array.prototype.every` or `Array.prototype.some`
48
- * method to check if all or some of the supplied values are numbers,
49
- * respectively. The method to use is determined by the `which` parameter.
50
- *
51
- * @param {string} [which='every'] - Determines the method to use for the
52
- * check. Can be either 'every' or 'some'. Defaults to 'every'.
53
- * @param {...*} values - The values to check.
54
- * @returns {boolean} - Returns `true` if all or some of the values are
55
- * numbers (based on the `which` parameter), `false` otherwise.
56
- *
57
- * @example
58
- * areNumbers('every', 1, 2, 3) // true
59
- * areNumbers('some', 1, '2', 3) // true
60
- * areNumbers('every', 1, '2', 3) // false
61
- */
62
- areNumbers(which = ['every', 'some'][0], ...values) {
63
- if (which !== 'every' && which !== 'some') {
64
- return false;
65
- }
66
- return values[which](num => this.isNumber(num));
67
- },
68
- /**
69
- * Conditionally returns a value based on whether the supplied `value` is
70
- * a `Number` or not. If the `value` is a `Number`, the `thenValue` will
71
- * be returned. If it is not a `Number`, the `elseValue` will be
72
- * returned instead.
73
- *
74
- * @param {*} value The value to check to determine if it is a `Number`
75
- * @param {*} thenValue The value to return if the supplied `value` is
76
- * a `Number`
77
- * @param {*} elseValue The value to return if the supplied `value` is
78
- * not a `Number`
79
- * @returns {*} Either the `thenValue` or `elseValue` depending on if the
80
- * supplied `value` is a `Number`
81
- *
82
- * @example
83
- * const num = 42
84
- * const str = 'hello'
85
- * ifNumber(num, 'is a number', 'not a number') // 'is a number'
86
- * ifNumber(str, 'is a number', 'not a number') // 'not a number'
87
- */
88
- ifNumber(value, thenValue, elseValue) {
89
- return isThenElse(this.isNumber(value), thenValue, elseValue);
90
- },
91
- /**
92
- * Conditionally returns a value based on whether all or some of the
93
- * supplied values are numbers.
94
- *
95
- * This method uses the `areNumbers` method to check if all or some of
96
- * the supplied values are numbers, based on the `which` parameter.
97
- * If the condition is met, the `thenValue` is returned, otherwise
98
- * the `elseValue` is returned.
99
- *
100
- * @param {*} thenValue - The value to return if the condition is met.
101
- * @param {*} elseValue - The value to return if the condition is not met.
102
- * @param {string} [which='every'] - Determines the method to use for the
103
- * check. Can be either 'every' or 'some'. Defaults to 'every'.
104
- * @param {...*} numbers - The values to check.
105
- * @returns {*} Either the `thenValue` or `elseValue` depending on if all
106
- * or some of the supplied values are numbers.
107
- *
108
- * @example
109
- * ifNumbers('All are numbers', 'Not all are numbers', 'every', 1, 2, 3)
110
- * // returns 'All are numbers'
111
- * ifNumbers('At least one is a number', 'None are numbers', 'some', 1, '2', 3)
112
- * // returns 'At least one is a number'
113
- * ifNumbers('All are numbers', 'Not all are numbers', 'every', 1, '2', 3)
114
- * // returns 'Not all are numbers'
115
- */
116
- ifNumbers(thenValue, elseValue, which = ['every', 'some'][0], ...numbers) {
117
- return isThenElse(this.areNumbers(which, ...numbers), thenValue, elseValue);
118
- },
119
- /**
120
- * Clamps a value between a minimum and maximum value.
121
- *
122
- * This method checks if the provided value and the min and max bounds are
123
- * numbers. If they are not, it returns the original value. If they are,
124
- * it ensures that the value does not go below the minimum value or above
125
- * the maximum value.
126
- *
127
- * @param {*} value - The value to clamp.
128
- * @param {number} [minValue=-Infinity] - The minimum value. Defaults
129
- * to -Infinity.
130
- * @param {number} [maxValue=Infinity] - The maximum value. Defaults
131
- * to Infinity.
132
- * @returns {*} - Returns the clamped value if all parameters are numbers,
133
- * otherwise returns the original value.
134
- *
135
- * @example
136
- * clamp(10, 1, 5) // returns 5
137
- * clamp(-10, 1, 5) // returns 1
138
- * clamp(3, 1, 5) // returns 3
139
- * clamp('10', 1, 5) // returns '10'
140
- */
141
- clamp(value, minValue = -Infinity, maxValue = Infinity) {
142
- if (!this.areNumbers('every', value, minValue, maxValue)) {
143
- return value;
144
- }
145
- return Math.max(minValue, Math.min(maxValue, value));
146
- },
147
- }
148
- });
149
- const { isNumber: pIsNumber, ifNumber: pIfNumber } = NumberExtensions.patches;
150
- /**
151
- * `NumberPrototypeExtensions` provides a set of utility methods that
152
- * are added to the `Number` prototype. This allows all number instances
153
- * to access new functionality directly, enhancing their capabilities
154
- * beyond the standard `Number` class methods.
155
- *
156
- * These extensions are applied using the `Patch` class from
157
- * '@nejs/extension', ensuring that they do not interfere with the
158
- * global namespace or existing properties.
159
- *
160
- * The extensions include methods for checking if a value is a number,
161
- * conditionally returning values based on whether a value is a number,
162
- * and more, making number-related tasks more convenient and expressive.
163
- *
164
- * @example
165
- * const num = 42
166
- * console.log(num.isNumber) // Output: true
167
- *
168
- * const notNum = "123"
169
- * console.log(notNum.isNumber) // Output: false
170
- *
171
- * @type {Patch}
172
- */
173
- export const NumberPrototypeExtensions = new Patch(Number.prototype, {
174
- [Patch.kMutablyHidden]: {
175
- /**
176
- * Returns an object representation of the number instance.
177
- *
178
- * This getter method creates and returns an object that wraps the number
179
- * instance, allowing it to be treated as an object. The returned object
180
- * is created using the `Object()` constructor, which takes the number
181
- * instance as its argument.
182
- *
183
- * @type {Object}
184
- * @readonly
185
- *
186
- * @example
187
- * const num = 42
188
- * console.log(typeof num) // 'number'
189
- * console.log(typeof num.instance) // 'object'
190
- */
191
- get instance() {
192
- return Object(this);
193
- },
194
- /**
195
- * Determines if the current object is a number
196
- *
197
- * This getter uses the `pIsNumber` function from the `NumberExtensions`
198
- * patch to check if the current object (`this`) is a number.
199
- *
200
- * @type {boolean}
201
- * @readonly
202
- *
203
- * @example
204
- * const num = 42
205
- * console.log(num.isNumber) // Output: true
206
- *
207
- * const notNum = "123"
208
- * console.log(notNum.isNumber) // Output: false
209
- */
210
- get isNumber() {
211
- return pIsNumber(this);
212
- },
213
- /**
214
- * Checks if the current object is a number and returns the corresponding
215
- * value based on the result.
216
- *
217
- * This method uses the `pIfNumber` function from the `NumberExtensions`
218
- * patch to determine if the current object (`this`) is a number. If it is
219
- * a number, the `thenValue` is returned. Otherwise, the `elseValue` is
220
- * returned.
221
- *
222
- * @param {any} thenValue The value to return if the current object is
223
- * a number
224
- * @param {any} elseValue The value to return if the current object is not
225
- * a number
226
- * @returns {any} The `thenValue` if the current object is a number, or
227
- * the `elseValue` if it is not a number
228
- *
229
- * @example
230
- * const num = 42
231
- * console.log(num.ifNumber('Is a number', 'Not a number'))
232
- * // Output: 'Is a number'
233
- *
234
- * const notNum = '123'
235
- * console.log(notNum.ifNumber('Is a number', 'Not a number'))
236
- * // Output: 'Not a number'
237
- */
238
- ifNumber(thenValue, elseValue) {
239
- return pIfNumber(this, thenValue, elseValue);
240
- },
241
- /**
242
- * Provides a way when dealing with numbers to determine if
243
- * a given number is within a range of values. By default, if
244
- * no parameters are supplied, it always returns true since
245
- * the default range is -Infinity to +Infinity. Additionally,
246
- * by default, the number will always be less than the supplied
247
- * max unless inclusive is set to true.
248
- *
249
- * @param min the lower range value, defaults to -Infinity
250
- * @param max the upper range value, defaults to +Infinity
251
- * @param inclusive defaults to false, set to true if you
252
- * want the max value to less than and equals to
253
- * @returns {boolean} true if within the range, false otherwise
254
- */
255
- within(min = -Infinity, max = Infinity, inclusive = false) {
256
- return this >= min && (inclusive ? this <= max : this < max);
257
- }
258
- }
259
- });
260
- // NOTE to self; this is repeated here otherwise a circular reference from
261
- // Object<->Function<->Global occurs. See original source in global.this.js
262
- // {@see globalThis.isThenElse}
263
- function isThenElse(bv, tv, ev) {
264
- function isFunction(value) { typeof value === 'function'; }
265
- if (arguments.length > 1) {
266
- var _then = isFunction(tv) ? tv(bv) : tv;
267
- if (arguments.length > 2) {
268
- var _else = isFunction(ev) ? tv(bv) : ev;
269
- return bv ? _then : _else;
270
- }
271
- return bv || _then;
272
- }
273
- return bv;
274
- }
275
- //# sourceMappingURL=number.extension.js.map