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