@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,417 +0,0 @@
1
- import { Extension } from '@nejs/extension';
2
- import { ObjectExtensions } from '../object.extensions.js';
3
- import { SymbolExtensions } from '../symbol.extensions.js';
4
- import { WeakRefExtensions } from '../weakref.extensions.js';
5
- import { Iterable, Iterator } from './iterable.js';
6
- const { isObject, isNullDefined, isValidKey } = ObjectExtensions.patches;
7
- const { isRegistered } = SymbolExtensions.patches;
8
- const { isValidReference } = WeakRefExtensions.patches;
9
- /**
10
- * RefMap class extends the standard Map object to manage a collection of
11
- * WeakRef values mapped to strong keys. It provides additional functionality
12
- * such as objectification of values and various utility methods.
13
- *
14
- * Unlike standard Maps or Objects, RefMap stores weak references to objects,
15
- * allowing them to be garbage-collected if there are no other references to
16
- * them. This behavior is different from Maps and standard Objects, which
17
- * maintain strong references to their elements.
18
- *
19
- * @extends Map
20
- */
21
- export class RefMap extends Map {
22
- /**
23
- * Private field to track whether the RefMap should objectify primitive
24
- * values.
25
- *
26
- * @private
27
- */
28
- #objectifyValues = false;
29
- constructor(...args) {
30
- super(...args);
31
- }
32
- /**
33
- * Method to control whether the RefMap should objectify its values. When
34
- * objectifying, primitive values (number, string, boolean, bigint) are
35
- * converted to their respective object types, which allows them to be used as
36
- * WeakRef targets.
37
- *
38
- * @param {boolean} setObjectification - Flag to enable or disable
39
- * objectification.
40
- * @returns {RefMap} - The current RefMap instance to allow method chaining.
41
- */
42
- objectifying(setObjectification = true) {
43
- this.objectifyValues = setObjectification;
44
- return this;
45
- }
46
- /**
47
- * The function converts a JavaScript Map object into a regular JavaScript
48
- * object, handling invalid keys by converting them to strings.
49
- *
50
- * @returns {object} an object; keys that are not either a `String` or a
51
- * `Symbol` will be converted to a string.
52
- */
53
- asObject() {
54
- const object = {};
55
- for (const [key, value] of this) {
56
- const useKey = isValidKey(key) ? key : String(key);
57
- const useValue = value?.valueOf() || value;
58
- object[useKey] = useValue;
59
- }
60
- return object;
61
- }
62
- /**
63
- * Returns the state indicating whether or not `RefMap` will attempt to
64
- * convert non-valid primitives into targets that are valid input for
65
- * new `WeakRef` object instances. If this value is `false` then no
66
- * *objectification* will occur.
67
- *
68
- * @returns {boolean} The current state of objectifyValues.
69
- */
70
- get objectifyValues() {
71
- return this.#objectifyValues;
72
- }
73
- /**
74
- * The `get` function retrieves a value from a map and returns it, or returns a
75
- * default value if the value is null or undefined. The actual retrieved value
76
- * is a dereferenced `WeakRef`. If the result is `undefined` and this is not the
77
- * expected response, it is likely the value has been garbage collected.
78
- *
79
- * @param {any} key - The key parameter is the key of the value you want to
80
- * retrieve from the data structure.
81
- * @param {any} defaultValue - The `defaultValue` parameter is the value that
82
- * will be returned if the key does not exist in the map or if the value
83
- * associated with the key has been garbage collected (i.e., it no longer
84
- * exists).
85
- * @returns The method is returning the value associated with the given key.
86
- * If the value is not found or if it has been garbage collected (deref()
87
- * returns null), then the defaultValue is returned.
88
- */
89
- get(key, defaultValue) {
90
- const value = super.get(key);
91
- if (!value || !value?.deref()) {
92
- return defaultValue;
93
- }
94
- return value?.deref();
95
- }
96
- /**
97
- * Setting this value to true, will cause all set values to the Map to
98
- * be analyzed for validity as a candidate to be wrapped in a `WeakRef`
99
- * object. If true, and if possible, the object will be turned into an
100
- * `Object` variant first.
101
- *
102
- * @param {boolean} value - The new state to set for objectifyValues.
103
- */
104
- set objectifyValues(value) {
105
- this.#objectifyValues = !!value;
106
- }
107
- /**
108
- * Overrides the set method of `Map`. Adds a value to the `RefMap`,
109
- * converting it to a `WeakRef`. Throws an error if the value is not a
110
- * valid `WeakRef` target (e.g., `null`, `undefined`, or a registered
111
- * `symbol`). If {@link objectifyValues} is enabled, an attempt to convert
112
- * primitives to their object variants will be made. These are `numbers`,
113
- * `strings`, `boolean` values and `bigint`s.
114
- *
115
- * @param {*} key - The `key` to be set on the `RefMap`
116
- * @param {*} value - The value to be associated with the `key`
117
- * @throws {TypeError} If the value is not a valid WeakRef target.
118
- */
119
- set(key, value) {
120
- let useValue = value;
121
- // Objectify the value if needed
122
- if (this.#objectifyValues && (typeof useValue === 'number' ||
123
- typeof useValue === 'string' ||
124
- typeof useValue === 'boolean' ||
125
- typeof useValue === 'bigint')) {
126
- useValue = Object(useValue);
127
- }
128
- // Check if the value is an object, and if it's a symbol, ensure it's not registered
129
- if (typeof useValue === 'symbol' && Symbol.keyFor(useValue) !== undefined) {
130
- throw new TypeError('RefMap cannot accept registered symbols as values');
131
- }
132
- if (typeof useValue !== 'object' && typeof useValue !== 'symbol') {
133
- throw new TypeError('RefMap values must be objects, non-registered symbols, or objectified primitives');
134
- }
135
- // If the value is null or undefined, throw an error
136
- if (useValue === null || useValue === undefined) {
137
- throw new TypeError('RefMap values cannot be null or undefined');
138
- }
139
- const ref = new WeakRef(useValue);
140
- super.set(key, ref);
141
- }
142
- /**
143
- * Sets multiple values at a single time. The format is an array of array
144
- * or rather an array of {@link Object.entries} (for example,
145
- * `[[key1,value1], [key2,value2]]`). For each entry pair, if the length
146
- * is not 2, either missing a key or value, it will be skipped.
147
- *
148
- * @param {Iterable} values - An iterable of values to add to the RefMap.
149
- * @throws {TypeError} If the supplied values are falsey or non-iterable.
150
- * @returns {RepMap} returns `this` to allow for chaining
151
- */
152
- setAll(entries) {
153
- if (!Iterable.isIterable(entries)) {
154
- throw new TypeError('The supplied list of entries must be an array of arrays in the ' +
155
- 'format [[key1, value1], [key2, value2], ...].');
156
- }
157
- const forEach = entry => {
158
- const [key, value] = entry;
159
- if (!key || !isObject(value) || !isRegistered(value)) {
160
- return;
161
- }
162
- this.set(key, value);
163
- };
164
- for (const entry of entries) {
165
- forEach(entry);
166
- }
167
- return this;
168
- }
169
- /**
170
- * Removes all elements from the RefMap that have been garbage collected
171
- * (i.e., their WeakRef no longer points to an object).
172
- *
173
- * @returns {RefMap} - The current RefMap instance to allow method chaining.
174
- */
175
- clean() {
176
- for (const [key, dereferenced] of this) {
177
- if (!dereferenced) {
178
- this.delete(key);
179
- }
180
- }
181
- return this;
182
- }
183
- /**
184
- * Executes a provided function once for each value in the RefMap. The callback
185
- * function receives the dereferenced value, the value again (as RefMap doesn't
186
- * use keys), and the RefMap itself. This method provides a way to iterate over
187
- * and apply operations to the values stored in the RefMap, taking into account
188
- * that they are weak references and may have been garbage-collected.
189
- *
190
- * @param {Function} forEachFn - Function to execute for each element. It
191
- * takes three arguments: element, element (again, as RefMap has no key), and
192
- * the RefMap itself.
193
- * @param {*} thisArg - Value to use as `this` when executing `forEachFn`.
194
- */
195
- entries() {
196
- const entriesIterator = super.entries();
197
- const refIterator = new Iterator(entriesIterator, (entry) => {
198
- if (entry) {
199
- const [key, ref] = entry;
200
- const value = ref?.deref();
201
- return [key, value];
202
- }
203
- return entry;
204
- });
205
- return refIterator;
206
- }
207
- /**
208
- * Iterate over the items in the map and pass them to the supplied
209
- * function ala `Map.prototype.forEach`. Note however, there are no
210
- * indexes on Maps and as such, the index parameter of the callback
211
- * will always be the value's key. Subsequently the `array` or third
212
- * parameter will receive the map instance rather than an array.
213
- *
214
- * @param {function} forEachFn the function to use for each element in
215
- * the set.
216
- * @param {object} thisArg the `this` argument to be applied to each
217
- * invocation of the `forEachFn` callback. Note, this value is unable
218
- * to be applied if the `forEachFn` is a big arrow function
219
- */
220
- forEach(forEachFn, thisArg) {
221
- for (const [key, ref] of super.entries()) {
222
- const value = ref?.deref();
223
- if (!value) {
224
- continue;
225
- }
226
- forEachFn.call(thisArg, value, key, this);
227
- }
228
- }
229
- /**
230
- * Returns an iterator for the values in the RefMap. Each value is
231
- * dereferenced from its WeakRef before being returned. This method allows
232
- * iterating over he set's values, similar to how one would iterate over
233
- * values in a standard Map or Array, but with the understanding that the
234
- * values are weakly referenced and may no longer exist (in which case
235
- * they are skipped).
236
- *
237
- * @returns {Iterator} An iterator for the values.
238
- */
239
- values() {
240
- return new Iterator(super.values(), function perItem(value) {
241
- const dereferenced = value?.deref();
242
- return dereferenced || value;
243
- });
244
- }
245
- /**
246
- * Determines whether an element with the specified value exists in the
247
- * `RefMap`. For non-objectified sets, this method checks if the dereferenced
248
- * values of the map include the specified value.
249
- *
250
- * For objectified sets, strict is set to false which uses loose
251
- * equality to allow for things like `Object(5)` to equal `5`. This is important
252
- * because otherwise primitives could not be weakly referenced. In the grand
253
- * scheme of things, this is only useful if the objectified value is the
254
- * one being referenced.
255
- *
256
- * @param {*} value - The value to check for presence in the RefMap.
257
- * @param {boolean} strict - if `true`, the default, then the supplied value
258
- * is hard compared to the dereferenced value (`===`). If `false`, then a
259
- * loose comparison is used (`==`)
260
- * @returns {boolean} - True if an element with the specified value exists
261
- * in the RefMap, false otherwise.
262
- */
263
- hasValue(value, strict = true) {
264
- if (isNullDefined(value)) {
265
- return false;
266
- }
267
- if (this.#objectifyValues) {
268
- strict = false;
269
- }
270
- for (const [_, dereferenced] of this) {
271
- if ((strict && value === dereferenced) ||
272
- (!strict && value == dereferenced)) {
273
- return true;
274
- }
275
- }
276
- return false;
277
- }
278
- /**
279
- * The `filter` function filters the entries of a `RefMap` object based on
280
- * a given filter function. The dereferenced entries of the values of the map
281
- * will be passed to the function rather than a `WeakRef` itself.
282
- *
283
- * A new resulting entry set will be generated and a new `RefMap` will be made
284
- * from these entries and returned. Note that this function never returns
285
- * `null`
286
- *
287
- * @param {function} filterFn - The `filterFn` parameter is a function that
288
- * will be used to filter the entries in the `RefMap`. It will be called with
289
- * three arguments: the value of the current entry, the key of the current
290
- * entry, and the `RefMap` itself. The function should return `true`
291
- * @param {object} thisArg - The `thisArg` parameter is an optional argument
292
- * that specifies the value to be used as `this` when executing the
293
- * `filterFn` function. It allows you to explicitly set the context in which
294
- * the `filterFn` function is called. If `thisArg` is not provided, `this
295
- * @returns {array} The `filter` method is returning an array of filtered map
296
- * entries
297
- */
298
- filter(filterFn, thisArg) {
299
- const resultingEntries = [];
300
- for (const [key, dereferenced] of this) {
301
- if (filterFn.call(thisArg, dereferenced, key, this)) {
302
- resultingEntries.push([key, dereferenced]);
303
- }
304
- }
305
- return resultingEntries;
306
- }
307
- /**
308
- * The `find` function iterates over a map and calls a given function on
309
- * each value, returning the first value for which the function returns
310
- * a truthy value.
311
- *
312
- * The function signature of `findFn` is
313
- * ```
314
- * function findFn(value, key, map)
315
- * ```
316
- * 'value' is passed to findFn up to two times; first with the `WeakRef`
317
- * value, second with the result of {@link WeakRef.deref}. If `findFn`
318
- * returns true for either of these the dereferenced value will be
319
- * returned from the call to {@link RefMap.find}.
320
- * `key` represents the key object that the value is mapped to.
321
- * `map` is simply a reference to `this` map.
322
- *
323
- * @param findFn - `findFn` is a function that will be called for each
324
- * element in the map. It takes three arguments: `ref`, `key`, and `map`;
325
- * where `ref` is the value of the current element in the map, `key` is
326
- * the key of the current element, and `map` is a reference to the instance
327
- * being searched.
328
- * @param thisArg - The `thisArg` parameter is the value to be used as
329
- * the `this` value when executing the `findFn` function. It allows you
330
- * to specify the context in which the `findFn` function should be called.
331
- * @returns the first dereferenced value that satisfies the condition
332
- * specified by the `findFn` function. If no value satisfies the condition,
333
- * it returns `null`.
334
- */
335
- find(findFn, thisArg) {
336
- for (const [key, dereferenced] of this) {
337
- const ref = super.get(key);
338
- let result = findFn.call(thisArg, ref, key, map);
339
- if (!result) {
340
- result = findFn.call(thisArg, dereferenced, key, map);
341
- }
342
- if (result) {
343
- return dereferenced;
344
- }
345
- }
346
- return null;
347
- }
348
- /**
349
- * Creates a new array or `RefMap` with the results of calling a provided
350
- * function on every element in the calling `RefMap`. This method dereferences
351
- * each value, applies the `mapFn`, and collects the results. If `toRefMap` is
352
- * `true`, a new `RefMap` is returned; otherwise, an array. This method
353
- * differs from `Array.map` in handling weak references and the potential to
354
- * return a new `RefMap` instead of an array.
355
- *
356
- * @param {Function} mapFn - Function that produces an element of the new
357
- * array or `RefMap`, taking three arguments.
358
- * @param {*} thisArg - Value to use as this when executing mapFn.
359
- * @param {boolean} toRefMap - Determines if the output should be a new
360
- * `RefMap` (`true`) or an array (`false`).
361
- * @param {boolean} mirrorObjectification - If `true` and `toRefMap` is
362
- * `true`, the new `RefMap` mirrors the objectification setting of the
363
- * original.
364
- * @returns {Array|RefMap} - A new array or `RefMap` with each element being
365
- * the result of the `mapFn`.
366
- */
367
- map(mapFn, thisArg, toRefMap, mirrorObjectification) {
368
- if (typeof mapFn !== 'function') {
369
- throw new TypeError('mapFn must be a function! Received', mapFn);
370
- }
371
- const entries = [];
372
- const errors = [];
373
- let needsObjectification = mirrorObjectification && this.objectifyValues;
374
- let detectNeed = mirrorObjectification === undefined;
375
- let objectify = needsObjectification;
376
- for (const [key, dereferenced] of this) {
377
- const [, VALUE] = [0, 1];
378
- const transformed = mapFn.call(thisArg, [key, dereferenced], key, this);
379
- if (!isValidReference(transformed[VALUE])) {
380
- if (isValidReference(Object(transformed[VALUE]))) {
381
- needsObjectification = true;
382
- if (detectNeed && !objectify) {
383
- objectify = true;
384
- transformed[VALUE] = Object(transformed[VALUE]);
385
- }
386
- }
387
- }
388
- entries.push(transformed);
389
- }
390
- if (toRefMap) {
391
- return new RefMap(entries).objectifying(objectify);
392
- }
393
- return entries;
394
- }
395
- /**
396
- * The function returns an iterator that iterates over the entries of an object,
397
- * dereferencing any weak references.
398
- *
399
- * @returns {Iterator} A new iterator object is being returned.
400
- */
401
- *[Symbol.iterator]() {
402
- for (const [key, ref] of this.entries()) {
403
- yield [key, ref];
404
- }
405
- }
406
- /**
407
- * Ensures that the constructor of this object instance's name
408
- * is returned if the string tag for this instance is queried
409
- *
410
- * @returns {string} the name of the class
411
- */
412
- get [Symbol.toStringTag]() {
413
- return this.constructor.name;
414
- }
415
- }
416
- export const RefMapExtensions = new Extension(RefMap);
417
- //# sourceMappingURL=refmap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"refmap.js","sourceRoot":"","sources":["../../../src/classes/refmap.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAA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AC,MAAM,CAAC,QAAQ,CAAC;QAChB,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YACxC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAClB,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAA"}
@@ -1,186 +0,0 @@
1
- /**
2
- * RefSet class extends the standard Set object to manage a collection of
3
- * WeakRef objects. It provides additional functionality such as objectification
4
- * of values and various utility methods.
5
- *
6
- * Unlike standard Sets or Arrays, RefSet stores weak references to objects,
7
- * allowing them to be garbage-collected if there are no other references to
8
- * them. This behavior is different from Arrays and standard Sets, which
9
- * maintain strong references to their elements.
10
- *
11
- * @extends Set
12
- */
13
- export class RefSet extends Set<any> {
14
- constructor(values?: readonly any[] | null | undefined);
15
- constructor(iterable?: Iterable<any> | null | undefined);
16
- /**
17
- * Method to control whether the RefSet should objectify its values. When
18
- * objectifying, primitive values (number, string, boolean, bigint) are
19
- * converted to their respective object types, which allows them to be used as
20
- * WeakRef targets.
21
- *
22
- * @param {boolean} setObjectification - Flag to enable or disable
23
- * objectification.
24
- * @returns {RefSet} - The current RefSet instance to allow method chaining.
25
- */
26
- objectifying(setObjectification?: boolean): RefSet;
27
- /**
28
- * Setting this value to true, will cause all added values to the Set to
29
- * be analyzed for validity as a candidate to be wrapped in a `WeakRef`
30
- * object. If true, and if possible, the object will be turned into an
31
- * `Object` variant first. This will also enable less rigid variable
32
- * comparison in the `.has()` method (i.e. `==` instead of `===`).
33
- *
34
- * @param {boolean} value - The new state to set for objectifyValues.
35
- */
36
- set objectifyValues(value: boolean);
37
- /**
38
- * Returns the state indicating whether or not `RefSet` will attempt to
39
- * convert non-valid primitives into targets that are valid input for
40
- * new `WeakRef` object instances. If this value is `false` then no
41
- * *objectification* will occur.
42
- *
43
- * @returns {boolean} The current state of objectifyValues.
44
- */
45
- get objectifyValues(): boolean;
46
- /**
47
- * Overrides the add method of Set. Adds a value to the RefSet, converting it
48
- * to a WeakRef. Throws an error if the value is not a valid WeakRef target
49
- * (e.g., null, undefined, or a registered symbol). If `objectifyValues` is
50
- * enabled, an attempt to convert primitives to their object variants will be
51
- * made. These are numbers, strings, boolean values and big integers.
52
- *
53
- * @param {*} value - The value to be added to the RefSet.
54
- * @throws {TypeError} If the value is not a valid WeakRef target.
55
- */
56
- add(value: any): void;
57
- /**
58
- * Adds multiple values to the RefSet. The supplied `values` should be
59
- * iterable and truthy. This function defers to `.add()` for its logic so
60
- * each value from the supplied collection of values will also be subject
61
- * to the criteria of that function.
62
- *
63
- * @param {Iterable} values - An iterable of values to add to the RefSet.
64
- * @throws {TypeError} If the supplied values are falsey or non-iterable.
65
- */
66
- addAll(values: Iterable<any>): void;
67
- /**
68
- * Removes all elements from the RefSet that have been garbage collected
69
- * (i.e., their WeakRef no longer points to an object).
70
- *
71
- * @returns {RefSet} - The current RefSet instance to allow method chaining.
72
- */
73
- clean(): RefSet;
74
- /**
75
- * Executes a provided function once for each value in the RefSet. The callback
76
- * function receives the dereferenced value, the value again (as RefSet doesn't
77
- * use keys), and the RefSet itself. This method provides a way to iterate over
78
- * and apply operations to the values stored in the RefSet, taking into account
79
- * that they are weak references and may have been garbage-collected.
80
- *
81
- * @param {Function} forEachFn - Function to execute for each element. It
82
- * takes three arguments: element, element (again, as RefSet has no key), and
83
- * the RefSet itself.
84
- * @param {*} thisArg - Value to use as `this` when executing `forEachFn`.
85
- */
86
- entries(): any[][];
87
- /**
88
- * Iterate over the items in the set and pass them to the supplied
89
- * function ala `Array.prototype.forEach`. Note however, there are no
90
- * indexes on Sets and as such, the index parameter of the callback
91
- * will always be `NaN`. Subsequently the `array` or third parameter
92
- * will receive the set instance rather than an array.
93
- *
94
- * @param {function} forEachFn the function to use for each element in
95
- * the set.
96
- * @param {object} thisArg the `this` argument to be applied to each
97
- * invocation of the `forEachFn` callback. Note, this value is unable
98
- * to be applied if the `forEachFn` is a big arrow function
99
- */
100
- forEach(forEachFn: Function, thisArg: object): void;
101
- /**
102
- * Returns an iterator for the values in the RefSet. Each value is
103
- * dereferenced from its WeakRef before being returned. This method allows
104
- * iterating over he set's values, similar to how one would iterate over
105
- * values in a standard Set or Array, but with the understanding that the
106
- * values are weakly referenced and may no longer exist (in which case
107
- * they are skipped).
108
- *
109
- * @returns {Iterator} An iterator for the values.
110
- */
111
- values(): Iterator<any, any, any>;
112
- /**
113
- * Returns an iterator for the keys of the RefSet. In RefSet, keys and
114
- * values are identical, so this method behaves the same as `values()`. It
115
- * provides compatibility with the standard Set interface and allows use in
116
- * contexts where keys are expected, despite RefSet not differentiating
117
- * between keys and values.
118
- *
119
- * @returns {Iterator} An iterator for the keys.
120
- */
121
- keys(): Iterator<any, any, any>;
122
- /**
123
- * Checks if the RefSet contains a value that is equal to the specified
124
- * value. This method is used primarily in objectified RefSets to determine
125
- * the presence of a value, taking into account objectification. It differs
126
- * from the `has` method in that it's tailored for sets that have
127
- * transformed their primitive values into objects, whereas `has` is more
128
- * general-purpose.
129
- *
130
- * @param {*} value - The value to search for in the RefSet.
131
- * @returns {boolean} - True if the RefSet contains the value, false otherwise.
132
- */
133
- contains(value: any): boolean;
134
- /**
135
- * Creates a new array with all elements that pass the test implemented by
136
- * the provided function. This method iterates over each element,
137
- * dereferences it, and applies the filter function. Unlike Array `filter`,
138
- * the callback receives the dereferenced value and not an index or array,
139
- * reflecting the non-indexed nature of RefSet. Useful for selectively
140
- * creating arrays from the set based on certain conditions, especially when
141
- * dealing with weak references.
142
- *
143
- * @param {Function} filterFn - Function to test each element of the RefSet.
144
- * The function receives the dereferenced value.
145
- * @param {*} thisArg - Value to use as `this` when executing `filterFn`.
146
- * @returns {Array} - A new array with the elements that pass the test.
147
- */
148
- filter(filterFn: Function, thisArg: any): any[];
149
- /**
150
- * Returns the value of the first element in the RefSet that satisfies the
151
- * provided testing function. Similar to Array `find`, this method iterates
152
- * over the RefSet, dereferencing each value and applying the testing
153
- * function. The non-indexed nature of RefSet is considered, as the
154
- * callback does not receive an index. This method is useful for finding a
155
- * specific element based on a condition.
156
- *
157
- * @param {*} thisArg - Value to use as this when executing findFn.
158
- * @returns {*} - The value of the first element in the RefSet that satisfies
159
- * the testing function, or undefined if none found.
160
- * @returns {any} the dereferenced value if found, or undefined otherwise
161
- */
162
- find(findFn: any, thisArg: any): any;
163
- /**
164
- * Creates a new array or `RefSet` with the results of calling a provided
165
- * function on every element in the calling `RefSet`. This method dereferences
166
- * each value, applies the `mapFn`, and collects the results. If `toRefSet` is
167
- * `true`, a new `RefSet` is returned; otherwise, an array. This method
168
- * differs from `Array.map` in handling weak references and the potential to
169
- * return a new `RefSet` instead of an array.
170
- *
171
- * @param {Function} mapFn - Function that produces an element of the new
172
- * array or `RefSet`, taking three arguments.
173
- * @param {*} thisArg - Value to use as this when executing mapFn.
174
- * @param {boolean} toRefSet - Determines if the output should be a new
175
- * `RefSet` (`true`) or an array (`false`).
176
- * @param {boolean} mirrorObjectification - If `true` and `toRefSet` is
177
- * `true`, the new `RefSet` mirrors the objectification setting of the
178
- * original.
179
- * @returns {Array|RefSet} - A new array or `RefSet` with each element being
180
- * the result of the `mapFn`.
181
- */
182
- map(mapFn: Function, thisArg: any, toRefSet: boolean, mirrorObjectification: boolean): any[] | RefSet;
183
- #private;
184
- }
185
- export const RefSetExtensions: Extension;
186
- import { Extension } from '@nejs/extension';