@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,352 +0,0 @@
1
- import { Patch } from '@nejs/extension';
2
- /**
3
- * `SetExtensions` is a constant that applies a patch to the global
4
- * `Set` constructor. This patch extends the `Set` with additional
5
- * methods and properties, enhancing its functionality.
6
- *
7
- * The `Patch` function takes two arguments: the target object to be patched
8
- * (in this case, `Set`), and an object containing the methods and
9
- * properties to be added to the target object.
10
- *
11
- * @example
12
- * // Using a method added by SetExtensions
13
- * const set = new Set();
14
- * console.log(Set.isSet(set)); // Output: true
15
- *
16
- * @const
17
- * @type {Patch}
18
- * @memberof module:set.extensions
19
- */
20
- export const SetExtensions = new Patch(Set, {
21
- [Patch.kMutablyHidden]: {
22
- /**
23
- * Determines if the supplied `value` is a `Set` object. This check
24
- * is performed by first looking for the `Symbol.toStringTag` on the
25
- * `value` and checking to see if it is equal to the string "Set".
26
- * If that check fails, `instanceof` is used as a fallback to check
27
- * the prototype chain.
28
- *
29
- * @param {any} value the value that needs to be checked to determine
30
- * if it is a `Set` object or not
31
- * @returns {boolean} `true` if the supplied `value` is a `Set`
32
- * object, `false` otherwise
33
- *
34
- * @example
35
- * const set = new Set()
36
- * isSet(set) // true
37
- * isSet(new Map()) // false
38
- * isSet([]) // false
39
- * isSet({}) // false
40
- */
41
- isSet(value) {
42
- return value?.[Symbol.toStringTag] === Set.name || value instanceof Set;
43
- },
44
- /**
45
- * Conditionally returns a value based on whether the supplied
46
- * `value` is a `Set` object or not. If the `value` is a `Set`
47
- * object, the `thenValue` will be returned. If it is not a `Set`
48
- * object, the `elseValue` will be returned instead.
49
- *
50
- * @param {any} value the value to check to determine if it is a
51
- * `Set` object
52
- * @param {any} thenValue the value to return if the supplied
53
- * `value` is a `Set` object
54
- * @param {any} elseValue the value to return if the supplied
55
- * `value` is not a `Set` object
56
- * @returns {any} either the `thenValue` or `elseValue` depending
57
- * on if the supplied `value` is a `Set` object
58
- *
59
- * @example
60
- * const set = new Set()
61
- * const map = new Map()
62
- * ifSet(set, 'is a set', 'not a set') // 'is a set'
63
- * ifSet(map, 'is a set', 'not a set') // 'not a set'
64
- */
65
- ifSet(value, thenValue, elseValue) {
66
- return isThenElse(this.isSet(value), thenValue, elseValue);
67
- },
68
- }
69
- });
70
- const { isSet: pIsSet } = SetExtensions.patches;
71
- /**
72
- * `SetPrototypeExtensions` is a constant that applies a patch to the
73
- * prototype of the built-in JavaScript `Set` object. This patch extends the
74
- * `Set` prototype with additional methods and properties, enhancing its
75
- * functionality.
76
- *
77
- * The `Patch` function takes two arguments: the target object to be patched
78
- * (in this case, `Set.prototype`), and an object containing the methods and
79
- * properties to be added to the target object.
80
- *
81
- * @example
82
- * // Using a method added by SetPrototypeExtensions
83
- * const mySet = new Set();
84
- * mySet.myNewMethod(); // Calls the new method added by the patch
85
- *
86
- * @const
87
- * @type {Patch}
88
- * @memberof module:set.extensions
89
- */
90
- export const SetPrototypeExtensions = new Patch(Set.prototype, {
91
- [Patch.kMutablyHidden]: {
92
- /**
93
- * Merges multiple iterables into the set. Each element from the iterables
94
- * is added to the set, ensuring uniqueness of all elements. This method
95
- * mutates the original set.
96
- *
97
- * @param {...Iterable} iterables - One or more iterable objects (like Set
98
- * or Array) whose elements will be added to the set.
99
- */
100
- concat(...iterables) {
101
- for (const iterable of iterables) {
102
- if (typeof iterable === 'string' ||
103
- !Reflect.has(iterable, Symbol.iterator)) {
104
- this.add(iterable);
105
- continue;
106
- }
107
- for (const element of iterable) {
108
- this.add(element);
109
- }
110
- }
111
- },
112
- /**
113
- * Checks to see if any value within the `Set` loosely equals the supplied
114
- * value.
115
- *
116
- * @param {*} value any value that might be loosely equal to an item in the
117
- * set, as opposed to {@link Set.has} which is the equivalent of a strict or
118
- * triple equals (`===`) check
119
- * @returns {boolean} `true` if any value within the set is loosely equal to
120
- * the supplied value, `false` otherwise
121
- */
122
- contains(value) {
123
- for (const element of this) {
124
- if (value == element) {
125
- return true;
126
- }
127
- }
128
- return false;
129
- },
130
- /**
131
- * Checks if every element in the set passes the test implemented by the
132
- * provided function. The function is called with each element of the set.
133
- * Note: Since sets do not have indices, the index parameter is always NaN.
134
- *
135
- * @param {Function} everyFn - The function to test each element. Receives
136
- * the element, index (always NaN), and the set itself.
137
- * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
138
- * `everyFn`.
139
- * @throws {TypeError} If `everyFn` is not a function.
140
- * @returns {boolean} True if every element passes the test, false otherwise.
141
- */
142
- every(everyFn, thisArg) {
143
- if (typeof everyFn !== 'function') {
144
- throw new TypeError(`everyFn must be a function! Received ${String(everyFn)}`);
145
- }
146
- let found = 0;
147
- for (const element of this) {
148
- if (everyFn.call(thisArg, element, NaN, this)) {
149
- found++;
150
- }
151
- }
152
- return (found === this.size);
153
- },
154
- /**
155
- * Finds the first element in the set satisfying the provided testing
156
- * function. If no elements satisfy the testing function, undefined is
157
- * returned. The function is called with each element of the set.
158
- * Note: Since sets do not have indices, the index parameter is always NaN.
159
- *
160
- * @param {Function} findFn - The function to execute on each element. It
161
- * receives the element, index (always NaN), and the set itself.
162
- * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
163
- * `findFn`.
164
- * @throws {TypeError} If `findFn` is not a function.
165
- * @returns {*} The first element that satisfies `findFn`, or undefined.
166
- */
167
- find(findFn, thisArg) {
168
- if (typeof findFn !== 'function') {
169
- throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
170
- }
171
- for (const element of this) {
172
- const match = findFn.call(thisArg, element, NaN, this);
173
- if (match) {
174
- return element;
175
- }
176
- }
177
- return undefined;
178
- },
179
- /**
180
- * Finds the last element in the set satisfying the provided testing function.
181
- * If no elements satisfy the testing function, undefined is returned. The
182
- * function is called with each element of the set in reverse order.
183
- * Note: Since sets do not have indices, the index parameter is always NaN.
184
- *
185
- * @param {Function} findFn - The function to execute on each element. It
186
- * receives the element, index (always NaN), and the set itself.
187
- * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
188
- * `findFn`.
189
- * @throws {TypeError} If `findFn` is not a function.
190
- * @returns {*} The last element that satisfies `findFn`, or undefined.
191
- */
192
- findLast(findFn, thisArg) {
193
- if (typeof findFn !== 'function') {
194
- throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
195
- }
196
- const found = [];
197
- for (const element of this) {
198
- const match = findFn.call(thisArg, element, NaN, this);
199
- if (match) {
200
- found.push(element);
201
- }
202
- }
203
- if (found.length) {
204
- return found[found.length - 1];
205
- }
206
- return undefined;
207
- },
208
- /**
209
- * Determines if the current object is a `Set` object.
210
- *
211
- * This is a getter that uses the `isSet` function from the
212
- * `SetExtensions` patch to check if the current object (`this`) is
213
- * a `Set` object.
214
- *
215
- * @type {boolean}
216
- * @readonly
217
- *
218
- * @example
219
- * const set = new Set()
220
- * console.log(set.isSet) // Output: true
221
- *
222
- * const notSet = {}
223
- * console.log(notSet.isSet) // Output: false
224
- */
225
- get isSet() {
226
- return pIsSet(this);
227
- },
228
- /**
229
- * Checks if the current object is a Set and returns the
230
- * corresponding value based on the result.
231
- *
232
- * This method uses the `isThenElse` function from the
233
- * `SetExtensions` patch to determine if the current object
234
- * (`this`) is a Set. If it is a Set, the `thenValue` is returned.
235
- * Otherwise, the `elseValue` is returned.
236
- *
237
- * @param {any} thenValue - The value to return if the current object
238
- * is a Set.
239
- * @param {any} elseValue - The value to return if the current object
240
- * is not a Set.
241
- * @returns {any} The `thenValue` if the current object is a Set, or
242
- * the `elseValue` if it is not a Set.
243
- *
244
- * @example
245
- * const set = new Set([1, 2, 3])
246
- * console.log(set.ifSet('Is a Set', 'Not a Set')) // 'Is a Set'
247
- *
248
- * const notSet = {}
249
- * console.log(notSet.ifSet('Is a Set', 'Not a Set')) // 'Not a Set'
250
- */
251
- ifSet(thenValue, elseValue) {
252
- return isThenElse(pIsSet(this), thenValue, elseValue);
253
- },
254
- /**
255
- * A getter property that returns the number of elements in the set.
256
- * This is an alias for the `size` property of the set.
257
- *
258
- * @returns {number} The number of elements in the set.
259
- */
260
- get length() {
261
- return this.size;
262
- },
263
- /**
264
- * Creates a new array populated with the results of calling the provided
265
- * function on every element in the set. The function is called with each
266
- * element of the set. Note: Since sets do not have indices, the index
267
- * parameter is always NaN.
268
- *
269
- * @param {Function} mapFn - The function to execute on each element. It
270
- * receives the element, index (always NaN), and the set itself.
271
- * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
272
- * `mapFn`.
273
- * @throws {TypeError} If `mapFn` is not a function.
274
- * @returns {Array} A new array with each element being the result of the
275
- * `mapFn`.
276
- */
277
- map(mapFn, thisArg) {
278
- if (typeof mapFn !== 'function') {
279
- throw new TypeError(`mapFn must be a function! Received ${String(mapFn)}`);
280
- }
281
- const transformed = [];
282
- for (const element of this) {
283
- transformed.push(mapFn.call(thisArg, element, NaN, this));
284
- }
285
- return transformed;
286
- },
287
- /**
288
- * Applies a function against an accumulator and each element in the set to
289
- * reduce it to a single value. The function is called with each element of
290
- * the set. Note: Since sets do not have indices, the index parameter is
291
- * always NaN.
292
- *
293
- * @param {Function} reduceFn - The function to execute on each element. It
294
- * receives the accumulator, element, index (always NaN), and the set itself.
295
- * @param {*} initialValue - The initial value to start reducing from.
296
- * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
297
- * `reduceFn`.
298
- * @throws {TypeError} If `reduceFn` is not a function.
299
- * @returns {*} The reduced value.
300
- */
301
- reduce(reduceFn, initialValue, thisArg) {
302
- if (typeof reduceFn !== 'function') {
303
- throw new TypeError(`reduceFn must be a Function! Received ${String(reduceFn)}`);
304
- }
305
- let accumulator = initialValue;
306
- for (const element of this) {
307
- accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this);
308
- }
309
- return accumulator;
310
- },
311
- /**
312
- * Tests whether at least one element in the set passes the test implemented
313
- * by the provided function. The function is called with each element of the
314
- * set. Note: Since sets do not have indices, the index parameter is always NaN.
315
- *
316
- * @param {Function} someFn - The function to test each element. It receives
317
- * the element, index (always NaN), and the set itself.
318
- * @param {Object} [thisArg] - Optional. Value to use as `this` when executing
319
- * `someFn`.
320
- * @throws {TypeError} If `someFn` is not a function.
321
- * @returns {boolean} True if at least one element passes the test, false
322
- * otherwise.
323
- */
324
- some(someFn, thisArg) {
325
- if (typeof someFn !== 'function') {
326
- throw new TypeError(`someFn must be a function! Received ${String(someFn)}`);
327
- }
328
- for (const element of this) {
329
- if (someFn.call(thisArg, element, NaN, this)) {
330
- return true;
331
- }
332
- }
333
- return false;
334
- },
335
- },
336
- });
337
- // NOTE to self; this is repeated here otherwise a circular reference from
338
- // Object<->Function<->Global occurs. See original source in global.this.js
339
- // {@see globalThis.isThenElse}
340
- function isThenElse(bv, tv, ev) {
341
- function isFunction(value) { typeof value === 'function'; }
342
- if (arguments.length > 1) {
343
- var _then = isFunction(tv) ? tv(bv) : tv;
344
- if (arguments.length > 2) {
345
- var _else = isFunction(ev) ? tv(bv) : ev;
346
- return bv ? _then : _else;
347
- }
348
- return bv || _then;
349
- }
350
- return bv;
351
- }
352
- //# sourceMappingURL=set.extensions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"set.extensions.js","sourceRoot":"","sources":["../../src/set.extensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,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,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS;YAC/B,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;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AA;AACb,CAAC"}
@@ -1,23 +0,0 @@
1
- /**
2
- * `StringExtensions` is a patch for the JavaScript built-in `String` class. It
3
- * adds utility methods to the `String` class without modifying the global namespace
4
- * directly. This patch includes methods for key validation, object type checking,
5
- * and retrieving the string tag of an object. These methods are useful for
6
- * enhancing the capabilities of the standard `String` class with additional
7
- * utility functions.
8
- */
9
- export const StringExtensions: Patch;
10
- /**
11
- * `StringPrototypeExtensions` provides a set of utility methods that are
12
- * added to the `String` prototype. This allows all string instances to
13
- * access new functionality directly, enhancing their capabilities beyond
14
- * the standard `String` class methods. These extensions are applied using
15
- * the `Patch` class from '@nejs/extension', ensuring that they do not
16
- * interfere with the global namespace or existing properties.
17
- *
18
- * The extensions include methods for extracting substrings based on
19
- * specific tokens, checking the presence of certain patterns, and more,
20
- * making string manipulation tasks more convenient and expressive.
21
- */
22
- export const StringPrototypeExtensions: Patch;
23
- import { Patch } from '@nejs/extension';