@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,280 +0,0 @@
1
- import { Extension } from '@nejs/extension';
2
- export class Property {
3
- constructor(key, descriptor) {
4
- if (key.startsWith(':'))
5
- key = Symbol.for(key.slice(1));
6
- if (typeof key !== 'string' && typeof key !== 'symbol') {
7
- throw new TypeError('Key or symbol or :symbol must be supplied!');
8
- }
9
- this.key = key;
10
- if (!Property.is.descriptor(descriptor)) {
11
- this.descriptor = {
12
- value: descriptor,
13
- writable: true,
14
- configurable: true,
15
- enumerable: true,
16
- };
17
- }
18
- else {
19
- this.descriptor = descriptor;
20
- }
21
- }
22
- apply(toObject, asKey) {
23
- if (!toObject || !['object', 'function'].some(k => k == typeof toObject))
24
- return;
25
- return Object.defineProperty(toObject, asKey ?? this.key, this.descriptor);
26
- }
27
- get descriptor() {
28
- const baseline = { configurable: true, enumerable: false };
29
- const result = {
30
- enumerable: this.meta.enumerable,
31
- configurable: this.meta.configurable,
32
- };
33
- if (this.is.accessor) {
34
- result.get = this.meta.accessor.get;
35
- result.set = this.meta.accessor.set;
36
- }
37
- else {
38
- result.value = this.meta.data.value;
39
- result.writable = this.meta.data.writable;
40
- }
41
- return Object.defineProperties(result, {
42
- make: {
43
- ...baseline,
44
- get() {
45
- const self = this;
46
- return {
47
- get enumerable() { self.enumerable = true; return self; },
48
- get hidden() { self.enumerable = false; return self; },
49
- get writable() { self.writable = true; return self; },
50
- get readonly() { self.writable = false; return self; },
51
- get configurable() { self.configurable = true; return self; },
52
- get immutable() { self.configurable = false; return self; },
53
- };
54
- }
55
- },
56
- is: {
57
- ...baseline,
58
- get() {
59
- const self = this;
60
- return {
61
- get accessor() { return self.is.accssor; },
62
- get data() { return self.is.data; }
63
- };
64
- }
65
- },
66
- });
67
- }
68
- set descriptor(descriptor) {
69
- const { is } = this.constructor;
70
- if (!is.descriptor(descriptor))
71
- return;
72
- this.meta.configurable = descriptor.configurable ?? true;
73
- this.meta.enumerable = descriptor.enumerable ?? true;
74
- if (Reflect.has(descriptor, 'get') || Reflect.has(descriptor, 'set')) {
75
- const { get, set } = descriptor;
76
- if (get !== undefined)
77
- this.meta.accessor.get = get;
78
- if (set !== undefined)
79
- this.meta.accessor.set = set;
80
- }
81
- else {
82
- const { value, writable } = descriptor;
83
- this.meta.data.value = value;
84
- this.meta.data.writable = writable ?? true;
85
- }
86
- }
87
- get is() {
88
- const self = this;
89
- return {
90
- get accessor() {
91
- return !!(self.meta.accessor.get ||
92
- self.meta.accessor.set);
93
- },
94
- get data() {
95
- return !!!this.accessor;
96
- },
97
- };
98
- }
99
- toString(colors = false, { key, descriptor } = {}) {
100
- const bold = s => colors ? `\x1b[1m${s}\x1b[22m` : s;
101
- const dim = s => colors ? `\x1b[2m${s}\x1b[22m` : s;
102
- const red = s => colors ? `\x1b[31m${s}\x1b[39m` : s;
103
- const green = s => colors ? `\x1b[32m${s}\x1b[39m` : s;
104
- const blue = s => colors ? `\x1b[34m${s}\x1b[39m` : s;
105
- if (!key)
106
- ({ key } = this);
107
- if (!descriptor || !Property.is.descriptor(descriptor))
108
- ({ descriptor } = this);
109
- const buffer = [`${bold(key)} { `];
110
- const keyPresent = (object) => (key) => Reflect.has(object, key);
111
- const eqeq = (value, compare = (a, b) => a === b) => (element) => compare(element, value);
112
- if (['get', 'set'].some(keyPresent(descriptor))) {
113
- if (descriptor.get) {
114
- buffer.push(blue('getter'));
115
- if (descriptor.set) {
116
- buffer.push(bold('|'));
117
- }
118
- }
119
- if (descriptor.set) {
120
- buffer.push(blue('setter'));
121
- }
122
- }
123
- else {
124
- buffer.push(green('value'));
125
- buffer.push(bold('|'));
126
- buffer.push(descriptor.writable ? green('writable') : red('readonly'));
127
- }
128
- buffer.push(' ');
129
- buffer.push(descriptor.configurable ? green('mutable') : red('immuatable'));
130
- buffer.push(' ');
131
- buffer.push(descriptor.enumerable ? green('visible') : red('hidden'));
132
- buffer.push(' }');
133
- return buffer.join('');
134
- }
135
- [Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {
136
- return this.toString(true);
137
- }
138
- /**
139
- * Creates an accessor property with customizable getter and setter functions.
140
- *
141
- * This method offers flexible ways to define accessor properties, including
142
- * support for storage-based getters and setters. It can handle various input
143
- * formats, making it versatile for different use cases.
144
- *
145
- * @param {string} name - The name of the accessor property.
146
- * @param {Object} accessors - Object containing getter and/or setter functions.
147
- * @param {Function} [accessors.get] - Getter function for the property.
148
- * @param {Function} [accessors.set] - Setter function for the property.
149
- * @param {Object} [accessors.prototype] - Prototype object for getter/setter.
150
- * @param {Object} [options] - Additional options for the accessor property.
151
- * @param {boolean} [options.configurable=true] - Whether property is configurable.
152
- * @param {boolean} [options.enumerable=true] - Whether property is enumerable.
153
- * @param {Object} [options.storage] - Storage object for getter/setter closures.
154
- * @returns {Property} A new Property instance representing the accessor.
155
- * @throws {TypeError} If no name, getter, or setter is provided.
156
- *
157
- * @example
158
- * // Basic usage
159
- * Property.accessor('color', {
160
- * get() { return this._color; },
161
- * set(value) { this._color = value; }
162
- * });
163
- *
164
- * @example
165
- * // Using storage
166
- * Property.accessor('keyword', {
167
- * get(storage) { return () => storage.keyword; },
168
- * set(storage) { return (value) => { storage.keyword = value; } }
169
- * }, { storage: { keyword: 'initial' } });
170
- *
171
- * @example
172
- * // Using named getter function
173
- * Property.accessor('color', function get() { return 'red' })
174
- *
175
- * @example
176
- * // Using prototype
177
- * const ColorAccessors = {
178
- * red: { get() { return this._red; } }
179
- * };
180
- * Property.accessor('red', ColorAccessors.red);
181
- */
182
- static accessor(name, { get, set, prototype }, { configurable, enumerable, storage } = {}) {
183
- if (!get && !set && prototype) {
184
- const constructor = prototype?.constructor;
185
- if (constructor?.name === 'get') {
186
- get = constructor;
187
- }
188
- else if (constructor?.name === 'set') {
189
- set = constructor;
190
- }
191
- }
192
- if (get && storage && get.length == 1) {
193
- get = get(storage);
194
- }
195
- if (set && storage && set.length == 1) {
196
- set = set(storage);
197
- }
198
- if (!name && !get && !set)
199
- throw new TypeError('Cannot create accessor');
200
- configurable ??= true;
201
- enumerable ??= true;
202
- return new Property(name, { get, set, configurable, enumerable });
203
- }
204
- static data(name, value, { writable, configurable, enumerable } = {}) {
205
- if (!name)
206
- throw new TypeError('Cannot create data property without name');
207
- writable ??= true;
208
- configurable ??= true;
209
- enumerable ??= true;
210
- return new Property(name, { value, writable, configurable, enumerable });
211
- }
212
- static from(object, name) {
213
- const descriptor = Object.getOwnPropertyDescriptor(object, name);
214
- return new Property(name, descriptor);
215
- }
216
- static get is() {
217
- return {
218
- object(value) {
219
- return value && ['object', 'function'].some(k => k == typeof value);
220
- },
221
- descriptor(object) {
222
- if (!Property.is.object(object)) {
223
- return false;
224
- }
225
- const present = element => Reflect.has(object, element);
226
- const props = {
227
- base: ['configurable', 'enumerable'],
228
- data: ['writable', 'value'],
229
- accessor: ['get', 'set'],
230
- };
231
- if (Object.getOwnPropertyNames(object).length > 4)
232
- return false;
233
- if (props.data.some(present) && props.accessor.some(present))
234
- return false;
235
- if (props.base.some(present))
236
- return true;
237
- if (props.data.some(present))
238
- return true;
239
- if (props.accessor.some(present))
240
- return true;
241
- return false;
242
- }
243
- };
244
- }
245
- static {
246
- const storage = Object.assign(Object.create(null), {
247
- key: undefined,
248
- meta: {
249
- enumerable: true,
250
- configurable: true,
251
- accessor: {
252
- get: undefined,
253
- set: undefined
254
- },
255
- data: {
256
- value: undefined,
257
- writable: true
258
- },
259
- },
260
- });
261
- basic_accessor(this.prototype, 'key', storage.key, storage);
262
- basic_accessor(this.prototype, 'meta', storage.meta, storage);
263
- }
264
- }
265
- export const PropertyExtensions = new Extension(Property);
266
- function basic_accessor(prototype, key, initialValue, storage = {}) {
267
- storage[key] = initialValue;
268
- Object.defineProperty(prototype, key, {
269
- get() {
270
- return storage[key];
271
- },
272
- set(value) {
273
- storage[key] = value;
274
- },
275
- enumerable: true,
276
- configurable: true,
277
- });
278
- return Object.getOwnPropertyDescriptor(prototype, key);
279
- }
280
- //# sourceMappingURL=property.js.map
@@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AG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YACjD,GAAG,EAAE,SAAS;YACd,IAAI,EAAE;gBACJ,UAAU,EAAE,IAAI;gBAChB,YAAY,EAAE,IAAI;gBAClB,QAAQ,EAAE;oBACR,GAAG,EAAE,SAAS;oBACd,GAAG,EAAE,SAAS;iBACf;gBACD,IAAI,EAAE;oBACJ,KAAK,EAAE,SAAS;oBAChB,QAAQ,EAAE,IAAI;iBACf;aACF;SACF,CAAC,CAAC;QAEH,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAC3D,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;CACF;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1D,SAAS,cAAc,CAAC,SAAS,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,GAAG,EAAE;IAChE,OAAO,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;IAE5B,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,EAAE;QACpC,GAAG;YACD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAA;QACrB,CAAC;QACD,GAAG,CAAC,KAAK;YACP,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACtB,CAAC;QACD,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,wBAAwB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AACzD,CAAC"}
@@ -1,238 +0,0 @@
1
- /**
2
- * RefMap class extends the standard Map object to manage a collection of
3
- * WeakRef values mapped to strong keys. It provides additional functionality
4
- * such as objectification of values and various utility methods.
5
- *
6
- * Unlike standard Maps or Objects, RefMap 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 Maps and standard Objects, which
9
- * maintain strong references to their elements.
10
- *
11
- * @extends Map
12
- */
13
- export class RefMap extends Map<any, any> {
14
- constructor(...args: any[]);
15
- /**
16
- * Method to control whether the RefMap should objectify its values. When
17
- * objectifying, primitive values (number, string, boolean, bigint) are
18
- * converted to their respective object types, which allows them to be used as
19
- * WeakRef targets.
20
- *
21
- * @param {boolean} setObjectification - Flag to enable or disable
22
- * objectification.
23
- * @returns {RefMap} - The current RefMap instance to allow method chaining.
24
- */
25
- objectifying(setObjectification?: boolean): RefMap;
26
- /**
27
- * Setting this value to true, will cause all set values to the Map to
28
- * be analyzed for validity as a candidate to be wrapped in a `WeakRef`
29
- * object. If true, and if possible, the object will be turned into an
30
- * `Object` variant first.
31
- *
32
- * @param {boolean} value - The new state to set for objectifyValues.
33
- */
34
- set objectifyValues(value: boolean);
35
- /**
36
- * Returns the state indicating whether or not `RefMap` will attempt to
37
- * convert non-valid primitives into targets that are valid input for
38
- * new `WeakRef` object instances. If this value is `false` then no
39
- * *objectification* will occur.
40
- *
41
- * @returns {boolean} The current state of objectifyValues.
42
- */
43
- get objectifyValues(): boolean;
44
- /**
45
- * The function converts a JavaScript Map object into a regular JavaScript
46
- * object, handling invalid keys by converting them to strings.
47
- *
48
- * @returns {object} an object; keys that are not either a `String` or a
49
- * `Symbol` will be converted to a string.
50
- */
51
- asObject(): object;
52
- /**
53
- * The `get` function retrieves a value from a map and returns it, or returns a
54
- * default value if the value is null or undefined. The actual retrieved value
55
- * is a dereferenced `WeakRef`. If the result is `undefined` and this is not the
56
- * expected response, it is likely the value has been garbage collected.
57
- *
58
- * @param {any} key - The key parameter is the key of the value you want to
59
- * retrieve from the data structure.
60
- * @param {any} defaultValue - The `defaultValue` parameter is the value that
61
- * will be returned if the key does not exist in the map or if the value
62
- * associated with the key has been garbage collected (i.e., it no longer
63
- * exists).
64
- * @returns The method is returning the value associated with the given key.
65
- * If the value is not found or if it has been garbage collected (deref()
66
- * returns null), then the defaultValue is returned.
67
- */
68
- get(key: any, defaultValue: any): any;
69
- /**
70
- * Overrides the set method of `Map`. Adds a value to the `RefMap`,
71
- * converting it to a `WeakRef`. Throws an error if the value is not a
72
- * valid `WeakRef` target (e.g., `null`, `undefined`, or a registered
73
- * `symbol`). If {@link objectifyValues} is enabled, an attempt to convert
74
- * primitives to their object variants will be made. These are `numbers`,
75
- * `strings`, `boolean` values and `bigint`s.
76
- *
77
- * @param {*} key - The `key` to be set on the `RefMap`
78
- * @param {*} value - The value to be associated with the `key`
79
- * @throws {TypeError} If the value is not a valid WeakRef target.
80
- */
81
- set(key: any, value: any): void;
82
- /**
83
- * Sets multiple values at a single time. The format is an array of array
84
- * or rather an array of {@link Object.entries} (for example,
85
- * `[[key1,value1], [key2,value2]]`). For each entry pair, if the length
86
- * is not 2, either missing a key or value, it will be skipped.
87
- *
88
- * @param {Iterable} values - An iterable of values to add to the RefMap.
89
- * @throws {TypeError} If the supplied values are falsey or non-iterable.
90
- * @returns {RepMap} returns `this` to allow for chaining
91
- */
92
- setAll(entries: any): RepMap;
93
- /**
94
- * Removes all elements from the RefMap that have been garbage collected
95
- * (i.e., their WeakRef no longer points to an object).
96
- *
97
- * @returns {RefMap} - The current RefMap instance to allow method chaining.
98
- */
99
- clean(): RefMap;
100
- /**
101
- * Executes a provided function once for each value in the RefMap. The callback
102
- * function receives the dereferenced value, the value again (as RefMap doesn't
103
- * use keys), and the RefMap itself. This method provides a way to iterate over
104
- * and apply operations to the values stored in the RefMap, taking into account
105
- * that they are weak references and may have been garbage-collected.
106
- *
107
- * @param {Function} forEachFn - Function to execute for each element. It
108
- * takes three arguments: element, element (again, as RefMap has no key), and
109
- * the RefMap itself.
110
- * @param {*} thisArg - Value to use as `this` when executing `forEachFn`.
111
- */
112
- entries(): Iterator;
113
- /**
114
- * Iterate over the items in the map and pass them to the supplied
115
- * function ala `Map.prototype.forEach`. Note however, there are no
116
- * indexes on Maps and as such, the index parameter of the callback
117
- * will always be the value's key. Subsequently the `array` or third
118
- * parameter will receive the map instance rather than an array.
119
- *
120
- * @param {function} forEachFn the function to use for each element in
121
- * the set.
122
- * @param {object} thisArg the `this` argument to be applied to each
123
- * invocation of the `forEachFn` callback. Note, this value is unable
124
- * to be applied if the `forEachFn` is a big arrow function
125
- */
126
- forEach(forEachFn: Function, thisArg: object): void;
127
- /**
128
- * Returns an iterator for the values in the RefMap. Each value is
129
- * dereferenced from its WeakRef before being returned. This method allows
130
- * iterating over he set's values, similar to how one would iterate over
131
- * values in a standard Map or Array, but with the understanding that the
132
- * values are weakly referenced and may no longer exist (in which case
133
- * they are skipped).
134
- *
135
- * @returns {Iterator} An iterator for the values.
136
- */
137
- values(): Iterator;
138
- /**
139
- * Determines whether an element with the specified value exists in the
140
- * `RefMap`. For non-objectified sets, this method checks if the dereferenced
141
- * values of the map include the specified value.
142
- *
143
- * For objectified sets, strict is set to false which uses loose
144
- * equality to allow for things like `Object(5)` to equal `5`. This is important
145
- * because otherwise primitives could not be weakly referenced. In the grand
146
- * scheme of things, this is only useful if the objectified value is the
147
- * one being referenced.
148
- *
149
- * @param {*} value - The value to check for presence in the RefMap.
150
- * @param {boolean} strict - if `true`, the default, then the supplied value
151
- * is hard compared to the dereferenced value (`===`). If `false`, then a
152
- * loose comparison is used (`==`)
153
- * @returns {boolean} - True if an element with the specified value exists
154
- * in the RefMap, false otherwise.
155
- */
156
- hasValue(value: any, strict?: boolean): boolean;
157
- /**
158
- * The `filter` function filters the entries of a `RefMap` object based on
159
- * a given filter function. The dereferenced entries of the values of the map
160
- * will be passed to the function rather than a `WeakRef` itself.
161
- *
162
- * A new resulting entry set will be generated and a new `RefMap` will be made
163
- * from these entries and returned. Note that this function never returns
164
- * `null`
165
- *
166
- * @param {function} filterFn - The `filterFn` parameter is a function that
167
- * will be used to filter the entries in the `RefMap`. It will be called with
168
- * three arguments: the value of the current entry, the key of the current
169
- * entry, and the `RefMap` itself. The function should return `true`
170
- * @param {object} thisArg - The `thisArg` parameter is an optional argument
171
- * that specifies the value to be used as `this` when executing the
172
- * `filterFn` function. It allows you to explicitly set the context in which
173
- * the `filterFn` function is called. If `thisArg` is not provided, `this
174
- * @returns {array} The `filter` method is returning an array of filtered map
175
- * entries
176
- */
177
- filter(filterFn: Function, thisArg: object): array;
178
- /**
179
- * The `find` function iterates over a map and calls a given function on
180
- * each value, returning the first value for which the function returns
181
- * a truthy value.
182
- *
183
- * The function signature of `findFn` is
184
- * ```
185
- * function findFn(value, key, map)
186
- * ```
187
- * 'value' is passed to findFn up to two times; first with the `WeakRef`
188
- * value, second with the result of {@link WeakRef.deref}. If `findFn`
189
- * returns true for either of these the dereferenced value will be
190
- * returned from the call to {@link RefMap.find}.
191
- * `key` represents the key object that the value is mapped to.
192
- * `map` is simply a reference to `this` map.
193
- *
194
- * @param findFn - `findFn` is a function that will be called for each
195
- * element in the map. It takes three arguments: `ref`, `key`, and `map`;
196
- * where `ref` is the value of the current element in the map, `key` is
197
- * the key of the current element, and `map` is a reference to the instance
198
- * being searched.
199
- * @param thisArg - The `thisArg` parameter is the value to be used as
200
- * the `this` value when executing the `findFn` function. It allows you
201
- * to specify the context in which the `findFn` function should be called.
202
- * @returns the first dereferenced value that satisfies the condition
203
- * specified by the `findFn` function. If no value satisfies the condition,
204
- * it returns `null`.
205
- */
206
- find(findFn: any, thisArg: any): any;
207
- /**
208
- * Creates a new array or `RefMap` with the results of calling a provided
209
- * function on every element in the calling `RefMap`. This method dereferences
210
- * each value, applies the `mapFn`, and collects the results. If `toRefMap` is
211
- * `true`, a new `RefMap` is returned; otherwise, an array. This method
212
- * differs from `Array.map` in handling weak references and the potential to
213
- * return a new `RefMap` instead of an array.
214
- *
215
- * @param {Function} mapFn - Function that produces an element of the new
216
- * array or `RefMap`, taking three arguments.
217
- * @param {*} thisArg - Value to use as this when executing mapFn.
218
- * @param {boolean} toRefMap - Determines if the output should be a new
219
- * `RefMap` (`true`) or an array (`false`).
220
- * @param {boolean} mirrorObjectification - If `true` and `toRefMap` is
221
- * `true`, the new `RefMap` mirrors the objectification setting of the
222
- * original.
223
- * @returns {Array|RefMap} - A new array or `RefMap` with each element being
224
- * the result of the `mapFn`.
225
- */
226
- map(mapFn: Function, thisArg: any, toRefMap: boolean, mirrorObjectification: boolean): any[] | RefMap;
227
- /**
228
- * The function returns an iterator that iterates over the entries of an object,
229
- * dereferencing any weak references.
230
- *
231
- * @returns {Iterator} A new iterator object is being returned.
232
- */
233
- [Symbol.iterator](): Iterator;
234
- #private;
235
- }
236
- export const RefMapExtensions: Extension;
237
- import { Iterator } from './iterable.js';
238
- import { Extension } from '@nejs/extension';