@nejs/basic-extensions 2.21.0 → 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 (270) hide show
  1. package/.idea/markdown.xml +8 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/ne-basic-extensions.iml +8 -0
  4. package/.idea/vcs.xml +6 -0
  5. package/CODE_STYLE.md +393 -0
  6. package/CODING_PHILOSOPHY.md +36 -0
  7. package/DOCUMENTATION_GUIDELINES.md +221 -0
  8. package/README.md +78 -4
  9. package/dist/@nejs/basic-extensions.bundle.2.22.6.js +25 -0
  10. package/dist/@nejs/basic-extensions.bundle.2.22.6.js.map +7 -0
  11. package/dist/cjs/classes/index.cjs +11129 -0
  12. package/dist/cjs/classes/index.cjs.map +7 -0
  13. package/dist/cjs/index.cjs +15191 -0
  14. package/dist/cjs/index.cjs.map +7 -0
  15. package/dist/cjs/utils/index.cjs +3954 -0
  16. package/dist/cjs/utils/index.cjs.map +7 -0
  17. package/dist/esm/basic-extensions.mjs +25 -0
  18. package/dist/esm/basic-extensions.mjs.map +7 -0
  19. package/package.json +16 -22
  20. package/repl.bootstrap.js +4 -7
  21. package/repl.history +30 -30
  22. package/src/big.int.extension.js +171 -45
  23. package/src/classes/enumeration.js +466 -0
  24. package/src/classes/index.js +5 -1
  25. package/src/index.js +5 -1
  26. package/src/math.extension.js +73 -0
  27. package/src/number.extension.js +18 -0
  28. package/src/regular.expression.extensions.js +0 -35
  29. package/src/utils/toolkit.js +699 -516
  30. package/tests/arrayextensions.test.js +3 -3
  31. package/tests/index.test.js +3 -1
  32. package/tests/newClasses/asyncIterable.test.js +3 -3
  33. package/tests/newClasses/deferred.test.js +3 -3
  34. package/tests/newClasses/descriptor.test.js +3 -3
  35. package/tests/newClasses/iterable.test.js +3 -3
  36. package/tests/newClasses/refmap.test.js +3 -3
  37. package/tests/newClasses/refset.test.js +3 -3
  38. package/tests/objectextensions.test.js +3 -3
  39. package/tests/setextensions.test.js +3 -3
  40. package/tests/stringextensions.test.js +3 -2
  41. package/tests/utils/descriptor.utils.test.js +1 -1
  42. package/tests/utils/toolkit.test.js +429 -163
  43. package/.esdoc.json +0 -9
  44. package/.vscode/settings.json +0 -5
  45. package/bin/build +0 -27
  46. package/bin/clean +0 -14
  47. package/bin/esbuild +0 -91
  48. package/bin/fixup +0 -13
  49. package/bin/repl.basics.js +0 -584
  50. package/bin/repl.signature.js +0 -63
  51. package/bin/version +0 -100
  52. package/dist/@nejs/basic-extensions.bundle.2.21.0.js +0 -25
  53. package/dist/@nejs/basic-extensions.bundle.2.21.0.js.map +0 -7
  54. package/dist/cjs/array.extensions.d.ts +0 -39
  55. package/dist/cjs/array.extensions.js +0 -477
  56. package/dist/cjs/array.extensions.js.map +0 -1
  57. package/dist/cjs/big.int.extension.d.ts +0 -31
  58. package/dist/cjs/big.int.extension.js +0 -165
  59. package/dist/cjs/big.int.extension.js.map +0 -1
  60. package/dist/cjs/classes/asyncIterable.d.ts +0 -126
  61. package/dist/cjs/classes/asyncIterable.js +0 -209
  62. package/dist/cjs/classes/asyncIterable.js.map +0 -1
  63. package/dist/cjs/classes/deferred.d.ts +0 -146
  64. package/dist/cjs/classes/deferred.js +0 -291
  65. package/dist/cjs/classes/deferred.js.map +0 -1
  66. package/dist/cjs/classes/descriptor.d.ts +0 -334
  67. package/dist/cjs/classes/descriptor.js +0 -537
  68. package/dist/cjs/classes/descriptor.js.map +0 -1
  69. package/dist/cjs/classes/enum.d.ts +0 -50
  70. package/dist/cjs/classes/enum.js +0 -405
  71. package/dist/cjs/classes/enum.js.map +0 -1
  72. package/dist/cjs/classes/index.d.ts +0 -15
  73. package/dist/cjs/classes/index.js +0 -63
  74. package/dist/cjs/classes/index.js.map +0 -1
  75. package/dist/cjs/classes/introspector.d.ts +0 -20
  76. package/dist/cjs/classes/introspector.js +0 -130
  77. package/dist/cjs/classes/introspector.js.map +0 -1
  78. package/dist/cjs/classes/iterable.d.ts +0 -169
  79. package/dist/cjs/classes/iterable.js +0 -268
  80. package/dist/cjs/classes/iterable.js.map +0 -1
  81. package/dist/cjs/classes/param.parser.d.ts +0 -221
  82. package/dist/cjs/classes/param.parser.js +0 -242
  83. package/dist/cjs/classes/param.parser.js.map +0 -1
  84. package/dist/cjs/classes/pluggable.proxy.d.ts +0 -153
  85. package/dist/cjs/classes/pluggable.proxy.js +0 -444
  86. package/dist/cjs/classes/pluggable.proxy.js.map +0 -1
  87. package/dist/cjs/classes/property.d.ts +0 -79
  88. package/dist/cjs/classes/property.js +0 -284
  89. package/dist/cjs/classes/property.js.map +0 -1
  90. package/dist/cjs/classes/refmap.d.ts +0 -238
  91. package/dist/cjs/classes/refmap.js +0 -421
  92. package/dist/cjs/classes/refmap.js.map +0 -1
  93. package/dist/cjs/classes/refset.d.ts +0 -186
  94. package/dist/cjs/classes/refset.js +0 -370
  95. package/dist/cjs/classes/refset.js.map +0 -1
  96. package/dist/cjs/classes/symkeys.d.ts +0 -349
  97. package/dist/cjs/classes/symkeys.js +0 -510
  98. package/dist/cjs/classes/symkeys.js.map +0 -1
  99. package/dist/cjs/classes/type.d.ts +0 -56
  100. package/dist/cjs/classes/type.js +0 -405
  101. package/dist/cjs/classes/type.js.map +0 -1
  102. package/dist/cjs/function.extensions.d.ts +0 -12
  103. package/dist/cjs/function.extensions.js +0 -758
  104. package/dist/cjs/function.extensions.js.map +0 -1
  105. package/dist/cjs/global.this.d.ts +0 -2
  106. package/dist/cjs/global.this.js +0 -300
  107. package/dist/cjs/global.this.js.map +0 -1
  108. package/dist/cjs/index.d.ts +0 -31
  109. package/dist/cjs/index.js +0 -226
  110. package/dist/cjs/index.js.map +0 -1
  111. package/dist/cjs/json.extensions.d.ts +0 -2
  112. package/dist/cjs/json.extensions.js +0 -109
  113. package/dist/cjs/json.extensions.js.map +0 -1
  114. package/dist/cjs/map.extensions.d.ts +0 -3
  115. package/dist/cjs/map.extensions.js +0 -143
  116. package/dist/cjs/map.extensions.js.map +0 -1
  117. package/dist/cjs/number.extension.d.ts +0 -44
  118. package/dist/cjs/number.extension.js +0 -261
  119. package/dist/cjs/number.extension.js.map +0 -1
  120. package/dist/cjs/object.extensions.d.ts +0 -33
  121. package/dist/cjs/object.extensions.js +0 -1091
  122. package/dist/cjs/object.extensions.js.map +0 -1
  123. package/dist/cjs/package.json +0 -3
  124. package/dist/cjs/proxy.extensions.d.ts +0 -2
  125. package/dist/cjs/proxy.extensions.js +0 -207
  126. package/dist/cjs/proxy.extensions.js.map +0 -1
  127. package/dist/cjs/reflect.extensions.d.ts +0 -14
  128. package/dist/cjs/reflect.extensions.js +0 -316
  129. package/dist/cjs/reflect.extensions.js.map +0 -1
  130. package/dist/cjs/regular.expression.extensions.d.ts +0 -2
  131. package/dist/cjs/regular.expression.extensions.js +0 -423
  132. package/dist/cjs/regular.expression.extensions.js.map +0 -1
  133. package/dist/cjs/set.extensions.d.ts +0 -40
  134. package/dist/cjs/set.extensions.js +0 -355
  135. package/dist/cjs/set.extensions.js.map +0 -1
  136. package/dist/cjs/string.extensions.d.ts +0 -23
  137. package/dist/cjs/string.extensions.js +0 -704
  138. package/dist/cjs/string.extensions.js.map +0 -1
  139. package/dist/cjs/symbol.extensions.d.ts +0 -11
  140. package/dist/cjs/symbol.extensions.js +0 -735
  141. package/dist/cjs/symbol.extensions.js.map +0 -1
  142. package/dist/cjs/utils/copy.object.d.ts +0 -408
  143. package/dist/cjs/utils/copy.object.js +0 -720
  144. package/dist/cjs/utils/copy.object.js.map +0 -1
  145. package/dist/cjs/utils/descriptor.utils.d.ts +0 -298
  146. package/dist/cjs/utils/descriptor.utils.js +0 -889
  147. package/dist/cjs/utils/descriptor.utils.js.map +0 -1
  148. package/dist/cjs/utils/index.d.ts +0 -75
  149. package/dist/cjs/utils/index.js +0 -61
  150. package/dist/cjs/utils/index.js.map +0 -1
  151. package/dist/cjs/utils/stdout.d.ts +0 -742
  152. package/dist/cjs/utils/stdout.js +0 -1042
  153. package/dist/cjs/utils/stdout.js.map +0 -1
  154. package/dist/cjs/utils/toolkit.d.ts +0 -1898
  155. package/dist/cjs/utils/toolkit.js +0 -1378
  156. package/dist/cjs/utils/toolkit.js.map +0 -1
  157. package/dist/cjs/weakref.extensions.d.ts +0 -2
  158. package/dist/cjs/weakref.extensions.js +0 -19
  159. package/dist/cjs/weakref.extensions.js.map +0 -1
  160. package/dist/mjs/array.extensions.d.ts +0 -39
  161. package/dist/mjs/array.extensions.js +0 -474
  162. package/dist/mjs/array.extensions.js.map +0 -1
  163. package/dist/mjs/big.int.extension.d.ts +0 -31
  164. package/dist/mjs/big.int.extension.js +0 -162
  165. package/dist/mjs/big.int.extension.js.map +0 -1
  166. package/dist/mjs/classes/asyncIterable.d.ts +0 -126
  167. package/dist/mjs/classes/asyncIterable.js +0 -204
  168. package/dist/mjs/classes/asyncIterable.js.map +0 -1
  169. package/dist/mjs/classes/deferred.d.ts +0 -146
  170. package/dist/mjs/classes/deferred.js +0 -287
  171. package/dist/mjs/classes/deferred.js.map +0 -1
  172. package/dist/mjs/classes/descriptor.d.ts +0 -334
  173. package/dist/mjs/classes/descriptor.js +0 -533
  174. package/dist/mjs/classes/descriptor.js.map +0 -1
  175. package/dist/mjs/classes/enum.d.ts +0 -50
  176. package/dist/mjs/classes/enum.js +0 -400
  177. package/dist/mjs/classes/enum.js.map +0 -1
  178. package/dist/mjs/classes/index.d.ts +0 -15
  179. package/dist/mjs/classes/index.js +0 -46
  180. package/dist/mjs/classes/index.js.map +0 -1
  181. package/dist/mjs/classes/introspector.d.ts +0 -20
  182. package/dist/mjs/classes/introspector.js +0 -126
  183. package/dist/mjs/classes/introspector.js.map +0 -1
  184. package/dist/mjs/classes/iterable.d.ts +0 -169
  185. package/dist/mjs/classes/iterable.js +0 -263
  186. package/dist/mjs/classes/iterable.js.map +0 -1
  187. package/dist/mjs/classes/param.parser.d.ts +0 -221
  188. package/dist/mjs/classes/param.parser.js +0 -238
  189. package/dist/mjs/classes/param.parser.js.map +0 -1
  190. package/dist/mjs/classes/pluggable.proxy.d.ts +0 -153
  191. package/dist/mjs/classes/pluggable.proxy.js +0 -438
  192. package/dist/mjs/classes/pluggable.proxy.js.map +0 -1
  193. package/dist/mjs/classes/property.d.ts +0 -79
  194. package/dist/mjs/classes/property.js +0 -280
  195. package/dist/mjs/classes/property.js.map +0 -1
  196. package/dist/mjs/classes/refmap.d.ts +0 -238
  197. package/dist/mjs/classes/refmap.js +0 -417
  198. package/dist/mjs/classes/refmap.js.map +0 -1
  199. package/dist/mjs/classes/refset.d.ts +0 -186
  200. package/dist/mjs/classes/refset.js +0 -366
  201. package/dist/mjs/classes/refset.js.map +0 -1
  202. package/dist/mjs/classes/symkeys.d.ts +0 -349
  203. package/dist/mjs/classes/symkeys.js +0 -506
  204. package/dist/mjs/classes/symkeys.js.map +0 -1
  205. package/dist/mjs/classes/type.d.ts +0 -56
  206. package/dist/mjs/classes/type.js +0 -401
  207. package/dist/mjs/classes/type.js.map +0 -1
  208. package/dist/mjs/function.extensions.d.ts +0 -12
  209. package/dist/mjs/function.extensions.js +0 -755
  210. package/dist/mjs/function.extensions.js.map +0 -1
  211. package/dist/mjs/global.this.d.ts +0 -2
  212. package/dist/mjs/global.this.js +0 -264
  213. package/dist/mjs/global.this.js.map +0 -1
  214. package/dist/mjs/index.d.ts +0 -31
  215. package/dist/mjs/index.js +0 -204
  216. package/dist/mjs/index.js.map +0 -1
  217. package/dist/mjs/json.extensions.d.ts +0 -2
  218. package/dist/mjs/json.extensions.js +0 -106
  219. package/dist/mjs/json.extensions.js.map +0 -1
  220. package/dist/mjs/map.extensions.d.ts +0 -3
  221. package/dist/mjs/map.extensions.js +0 -140
  222. package/dist/mjs/map.extensions.js.map +0 -1
  223. package/dist/mjs/number.extension.d.ts +0 -44
  224. package/dist/mjs/number.extension.js +0 -258
  225. package/dist/mjs/number.extension.js.map +0 -1
  226. package/dist/mjs/object.extensions.d.ts +0 -33
  227. package/dist/mjs/object.extensions.js +0 -1088
  228. package/dist/mjs/object.extensions.js.map +0 -1
  229. package/dist/mjs/package.json +0 -3
  230. package/dist/mjs/proxy.extensions.d.ts +0 -2
  231. package/dist/mjs/proxy.extensions.js +0 -204
  232. package/dist/mjs/proxy.extensions.js.map +0 -1
  233. package/dist/mjs/reflect.extensions.d.ts +0 -14
  234. package/dist/mjs/reflect.extensions.js +0 -313
  235. package/dist/mjs/reflect.extensions.js.map +0 -1
  236. package/dist/mjs/regular.expression.extensions.d.ts +0 -2
  237. package/dist/mjs/regular.expression.extensions.js +0 -420
  238. package/dist/mjs/regular.expression.extensions.js.map +0 -1
  239. package/dist/mjs/set.extensions.d.ts +0 -40
  240. package/dist/mjs/set.extensions.js +0 -352
  241. package/dist/mjs/set.extensions.js.map +0 -1
  242. package/dist/mjs/string.extensions.d.ts +0 -23
  243. package/dist/mjs/string.extensions.js +0 -701
  244. package/dist/mjs/string.extensions.js.map +0 -1
  245. package/dist/mjs/symbol.extensions.d.ts +0 -11
  246. package/dist/mjs/symbol.extensions.js +0 -732
  247. package/dist/mjs/symbol.extensions.js.map +0 -1
  248. package/dist/mjs/utils/copy.object.d.ts +0 -408
  249. package/dist/mjs/utils/copy.object.js +0 -702
  250. package/dist/mjs/utils/copy.object.js.map +0 -1
  251. package/dist/mjs/utils/descriptor.utils.d.ts +0 -298
  252. package/dist/mjs/utils/descriptor.utils.js +0 -875
  253. package/dist/mjs/utils/descriptor.utils.js.map +0 -1
  254. package/dist/mjs/utils/index.d.ts +0 -75
  255. package/dist/mjs/utils/index.js +0 -45
  256. package/dist/mjs/utils/index.js.map +0 -1
  257. package/dist/mjs/utils/stdout.d.ts +0 -742
  258. package/dist/mjs/utils/stdout.js +0 -1037
  259. package/dist/mjs/utils/stdout.js.map +0 -1
  260. package/dist/mjs/utils/toolkit.d.ts +0 -1898
  261. package/dist/mjs/utils/toolkit.js +0 -1373
  262. package/dist/mjs/utils/toolkit.js.map +0 -1
  263. package/dist/mjs/weakref.extensions.d.ts +0 -2
  264. package/dist/mjs/weakref.extensions.js +0 -16
  265. package/dist/mjs/weakref.extensions.js.map +0 -1
  266. package/jsdoc-config.json +0 -31
  267. package/tsconfig.base.json +0 -28
  268. package/tsconfig.cjs.json +0 -8
  269. package/tsconfig.esm.json +0 -8
  270. package/vitest.config.js +0 -7
@@ -1,889 +0,0 @@
1
- "use strict";
2
- /** @typedef {string|symbol|number} PropertyKey */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.kSharedDescriptorKeys = exports.kDescriptorKeys = exports.kDataDescriptorKeys = exports.kAccessorDescriptorKeys = exports.redescribe = exports.isDescriptor = exports.isData = exports.isAccessor = exports.extract = exports.describeMany = exports.describe = exports.data = exports.accessor = exports.DescriptorUtils = void 0;
5
- /**
6
- * The `IsDescriptorStats` block contains all the information used to make
7
- * a determination as to whether a given value is a an instance of the type
8
- * {@link PropertyDescriptor} or at least compatible to used as one.
9
- *
10
- * @typedef {Object} IsDescriptorStats
11
- * @property {number} confidence this is going to be a number from 0.0-1.0
12
- * indicating the confidence ratio that the object supplied to `isDescriptor`
13
- * is actually a valid `PropertyDescriptor` object. If the number is greater
14
- * than 0 but less than 1.0, it likely indicates that the object can be used
15
- * as a `PropertyDescriptor` but one or more factors gives it less than 100%
16
- * confidence that being such is the objects intended purpose (e.g. it could
17
- * be that there are more properties than a descriptor might have or that
18
- * it is missing crucial properties such as `value`, `get` or `set`)
19
- * @property {boolean} isAccessor true if the object is functional as an
20
- * accessor descriptor; false otherwise
21
- * @property {boolean} isData true if the object is functional as a data
22
- * descriptor; false otherwise
23
- * @property {boolean} isValid true if the object is technically a valid
24
- * `PropertyDescriptor` object or compatible as one.
25
- * @property {boolean} hasBaseDescriptorKeys true if the object has either
26
- * `configurable` or `enumerable` property keys and both are `undefined` or
27
- * of type `boolean`.
28
- * @property {boolean} hasAccessorKeys true if the object has either `get`
29
- * or `set` property keys and both are either `undefined` or of type
30
- * `function`
31
- * @property {boolean} hasDataKeys true if the object has either `value` or
32
- * `writable` property keys and if `writable` is present, then it is of type
33
- * `boolean`
34
- */
35
- /**
36
- * The response from a call to {@link DescriptorUtils.isDescriptor} can
37
- * be either a {@link boolean} or a {@link IsDescriptorStats} object.
38
- *
39
- * @typedef {IsDescriptorStats | boolean} IsDescriptorResponse
40
- */
41
- /**
42
- * A set of utility functions work with {@link PropertyDescriptor} objects.
43
- * The creation of property descriptors can be large in boiler plate so
44
- * these tools can reduce the boiler plate and increase readability.
45
- *
46
- * @name DescriptorUtils
47
- * @typedef {DescriptorUtils}
48
- */
49
- exports.DescriptorUtils = {
50
- /**
51
- * Creates an accessor descriptor object
52
- *
53
- * This function has multiple possible overloads
54
- *
55
- * ```markdown
56
- * _**zeroFn** is a function that takes no parameters_
57
- * _**oneFn** is a function that takes a single parameter_
58
- * _**oneOrNone** is a either a function that takes a single parameter or nullish_
59
- * _**nonFn** is any value that is not a function_
60
- * _**nullish** is either null or undefined_
61
- * _**...** means configurable?, enumerable?, storage?, key? liaison? as
62
- * subsequent following parameters in that order_
63
- *
64
- * **accessor()**
65
- * creates a storage backed accessor that is both read and write.
66
- * The storage object will be a provided empty object with the key
67
- * being 'value'. Configurable and enumerable flags will be set to
68
- * `true`.
69
- *
70
- * **accessor(options)**
71
- * this single argument variant of accessor() consists of a single
72
- * options object. If neither `get` nor `set` are provided, a
73
- * storage backed read-write accessor with undefined as the initial
74
- * value will be constructed.
75
- *
76
- * **accessor(nonFn)**
77
- * **accessor(any, true, options?)**
78
- * **accessor(any, true, ...)**
79
- * supplying only a non-function only parameter or any value and the
80
- * value `true` as the second parameter, you will get a read-write
81
- * accessor stored in the default or specified storage. The resultant
82
- * initial value will be whatever is provided as the first parameter.
83
- * See options to customize `configurable`, `enumerable`, `storage`,
84
- * `key` and the `liaison` factory function.
85
- *
86
- * **accessor(any, false, options?)**
87
- * **accessor(any, false, ...)**
88
- * supplying only a non-function only parameter or any value and the
89
- * value `false` as the second parameter, you will get a read-only
90
- * getter stored in the default or specified storage. The resultant
91
- * value will be whatever is provided as the first parameter.
92
- * See options to customize `configurable`, `enumerable`, `storage`,
93
- * `key` and the `liaison` factory function.
94
- *
95
- * **accessor(zeroFn)**
96
- * **accessor(zeroFn, nullish, options?)**
97
- * **accessor(zeroFn, nullish, ...)**
98
- * creates a generic read-only accessor with the first no-argument
99
- * function parameter being the getter and either null or undefined
100
- * for the setter. Either an options object or the manually ordered
101
- * parameters can optionally follow if a nullish value for setter
102
- * is provided.
103
- *
104
- * **accessor(zeroFn, oneOrNone, options?)**
105
- * **accessor(zeroFn, oneOrNone, ...)**
106
- * creates a generic read-write accessor with the first no-argument
107
- * function parameter being the getter and the second single-argument
108
- * function parameter being the setter. Either an options object or
109
- * the manually ordered parameters can optionally follow.
110
- *
111
- * **accessor(oneFn, oneFn, options?)**
112
- * **accessor(oneFn, oneFn, ...)**
113
- * this special variant of the accessor() invocation, allows a single
114
- * argument getter and setter factory to be supplied. These will
115
- * automatically be invoked with the specified or default storage
116
- * object. The result of the getter factory should be a no argument
117
- * function. And the result of the setter factory should be a single
118
- * argument function. The options for `liaison` and `key` will be
119
- * ignored and should be handled specifically in the factory
120
- * functions to suit your own use case.
121
- * ```
122
- *
123
- * Options are an object oriented way of supplying the alternate
124
- * flags to the data descriptor. They are
125
- *
126
- * • `get` - only referenced when an options object is the only parameter
127
- * • `set` - only referenced when an options object is the only parameter
128
- * • `configurable` - if true, the descriptor of the object that this
129
- * accessor descriptor represents can be redefined at later time by
130
- * subsequent calls to {@link Object.defineProperty} or
131
- * {@link Object.defineProperties}
132
- * • `enumerable` - if true, enumeration over the object this
133
- * descriptor is applied to, will show the property
134
- * represented by this descriptor. See the associated MDN
135
- * page regarding this {@link PropertyDescriptor} if you
136
- * want to know more.
137
- * • `storage` - an object, usually {@link Object} or {@link Map} or
138
- * nullish if unused
139
- * • `key` - a {@link PropertyKey} of your choosing or the default
140
- * string `"value"`
141
- * • `bind` - true if you wish to have the `storage` object bound as
142
- * the `thisObj` for both the `get` and `set` functions when
143
- * storage is used. **note* this will not work if you supply a
144
- * big arrow function for the accessor function in question. This
145
- * defaults to `false`.
146
- * • `liaison` - an optional factory function that must return an
147
- * object with two properties. The first is a `get()` function that
148
- * returns a value and the second is a `set(value)` function that
149
- * stores a value. The factory function receives `storage` and
150
- * `key`, in that order. The default uses {@link Map.get} and
151
- * {@link Map.set} if the storage is an instance of {@link Map}.
152
- * Otherwise, the typical `object[key]` format is used if the
153
- * storage object is an instanceof {@link Object}
154
- *
155
- * @param {(object|any)?} value the JavaScript value representing
156
- * this descriptor's value or an options object if it is the
157
- * only parameter.
158
- * @param {(object|boolean)?} optionsOrConfigurable true or false if
159
- * you wish the `configurable` flag to be set. Optionally supply an
160
- * object with one of the supported options to configure the run
161
- * of the function.
162
- * @param {boolean?} enumerable true or false if you wish to
163
- * configure the `.enumerable` property of the descriptor
164
- * @param {object?} storage an object upon which data storage should
165
- * be written to and read from. Defaults to an empty {@link Object}
166
- * when storage is needed and not supplied via this parameter or
167
- * an options object.
168
- * @param {PropertyKey?} key the key used to store content on the
169
- * storage object.
170
- * @param {(object, PropertyKey) => { get: ()=>any, set: (v)=>void}} liaison
171
- * an optional function that, given a storage object and property key,
172
- * returns an object with a no argument `get()` function that returns
173
- * the value on the storage object with a given key and a single argument
174
- * `set(value)` function that stores a new value using the property key
175
- * on the supplied storage object. This exists because access to a
176
- * {@link Map} and {@link Object} values are handled differently. If you
177
- * need support for some other class than `Map` or `Object` then you
178
- * should provide a liaison function to define access.
179
- *
180
- * @returns {PropertyDescriptor}
181
- *
182
- * @see {@link PropertyDescriptor}
183
- * @note More info on this can be found at the
184
- * [MDN Object.defineProperty/ies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
185
- * page
186
- *
187
- * @type {Function & { keys: string[] }}
188
- */
189
- get accessor() {
190
- function accessor(get, set, optionsOrConfigurable = true, enumerable = true, storage, key = 'value', liaison) {
191
- const count = arguments.length;
192
- const storageKeys = ['storage', 'key', 'liaison', 'initial', 'bind'];
193
- const optionKeys = [
194
- // accessor functions
195
- 'get', 'set',
196
- // descriptor flags
197
- 'configurable', 'enumerable',
198
- // storage configuration keys
199
- ...storageKeys
200
- ];
201
- const has = (object, key) => isObject(object) && Reflect.has(object, key);
202
- const isOpts = object => optionKeys.some(key => has(object, key));
203
- let configurable = !!optionsOrConfigurable;
204
- let initial = undefined;
205
- let bind = false;
206
- let options = {};
207
- if (count === 1 && isObject(get) && hasSome(get, ...optionKeys)) {
208
- options = { ...get };
209
- ({ get, set } = get);
210
- }
211
- if (isObject(optionsOrConfigurable) || isObject(set)) {
212
- options = isObject(set) && count === 2
213
- ? { ...set }
214
- : { ...optionsOrConfigurable };
215
- ({ configurable, enumerable, storage, key, bind, initial } = options);
216
- }
217
- liaison = options?.liaison ?? liaison ?? ((storage, key) => ({
218
- get() {
219
- if (storage instanceof Map)
220
- return storage.get(key);
221
- else if (isObject(storage))
222
- return storage[key];
223
- },
224
- set(value) {
225
- if (storage instanceof Map)
226
- storage.set(key, value);
227
- else if (isObject(storage))
228
- storage[key] = value;
229
- }
230
- }));
231
- configurable = configurable ?? true;
232
- enumerable = enumerable ?? true;
233
- key = key ?? 'value';
234
- bind = bind ?? false;
235
- const nullish = (value) => value === null || value === undefined;
236
- const nonFn = (value) => !nullish(value) && typeof value !== 'function';
237
- const yesFn = (value) => typeof value === 'function';
238
- const zeroFn = (value) => (yesFn(value) && value.length === 0);
239
- const oneFn = (value) => (yesFn(value) && value.length === 1);
240
- const isTrue = (value) => value === true;
241
- const isFalse = (value) => value === false;
242
- const addRefs = (fn, value) => Object.defineProperties(fn, {
243
- storage: { value, configurable: true, enumerable: false },
244
- key: { value: key, configurable: true, enumerable: false },
245
- });
246
- if (count === 0 || (!get && !set)) {
247
- storage = { [key]: initial };
248
- const _ = liaison(storage, key);
249
- get = addRefs(function () { return _.get(); }, storage);
250
- set = addRefs(function (value) { _.set(value); }, storage);
251
- return { get, set, configurable, enumerable };
252
- }
253
- if (count === 1 && oneFn(get)) {
254
- set = false;
255
- }
256
- if ((count === 1 && nonFn(get)) || (isTrue(set) || isFalse(set))) {
257
- const skipSet = isFalse(set);
258
- if (!storage || !(storage instanceof Map) || !isObject(storage)) {
259
- storage = {};
260
- }
261
- const _ = liaison(storage, key);
262
- _.set(get);
263
- let _get = function () { return _.get(); };
264
- let _set = function (value) { _.set(value); };
265
- if (bind) {
266
- _get = _get.bind(storage);
267
- _set = _set.bind(storage);
268
- }
269
- get = addRefs(_get, storage);
270
- set = addRefs(_set, storage);
271
- if (skipSet) {
272
- set = undefined;
273
- }
274
- return { get, set, configurable, enumerable };
275
- }
276
- if ((zeroFn(get) && !set) || (zeroFn(get) && oneFn(set))) {
277
- const descriptor = { get, set, configurable, enumerable };
278
- if (isObject(options) && Reflect.has(options, 'initial'))
279
- descriptor.set(initial);
280
- return descriptor;
281
- }
282
- if (oneFn(get) && oneFn(set)) {
283
- storage = storage || {};
284
- let _get = get(storage);
285
- let _set = set(storage);
286
- if (bind) {
287
- _get = _get.bind(storage);
288
- _set = _set.bind(storage);
289
- }
290
- return {
291
- get: addRefs(_get, storage),
292
- set: addRefs(_set, storage),
293
- configurable,
294
- enumerable,
295
- };
296
- }
297
- return { get, set, configurable, enumerable };
298
- }
299
- Object.defineProperty(accessor, 'keys', {
300
- get() {
301
- return Object.defineProperties(['get', 'set', 'configurable', 'enumerable'], {
302
- from: {
303
- value: function extractKeysFrom(object) {
304
- const response = {
305
- get: undefined,
306
- set: undefined,
307
- configurable: undefined,
308
- enumerable: undefined,
309
- };
310
- if (!object || !(object instanceof Object))
311
- return response;
312
- for (const key of exports.DescriptorUtils.accessor.keys) {
313
- if (Reflect.has(object, key))
314
- response[key] = object[key];
315
- }
316
- },
317
- writable: false,
318
- configurable: false,
319
- enumerable: false
320
- }
321
- });
322
- },
323
- configurable: true,
324
- enumerable: false,
325
- });
326
- return accessor;
327
- },
328
- /**
329
- * Creates a data descriptor object
330
- *
331
- * This function has multiple possible overloads
332
- *
333
- * ```markdown
334
- * **data()**
335
- * creates a data descriptor with a value of `undefined` that
336
- * is writable, configurable and enumerable.
337
- *
338
- * **data(options)**
339
- * if the only parameter is an object and that object contains
340
- * at least a `.value` property, this funtion will return a
341
- * data descriptor with the associated values. This variant
342
- * is useful if you want to extract the normal data descriptor
343
- * properties: value, writable, configurable and/or enumerable
344
- * from an object that has properties with these names, in
345
- * addition to other properties or functions. Note that if you
346
- * wish for the value of the descriptor to be an object that
347
- * also contains a `.value` property, use `data({value: obj})`
348
- * instead.
349
- *
350
- * **data(value)**
351
- * **data(value, options?)**
352
- * creates a data descriptor from the supplied `value`,
353
- * optionally augmented by additional `options`. The defaults
354
- * for this writable, configurable and enumerable values set
355
- * to `true`
356
- *
357
- * **data(value, writable?, configurable?, enumerable?)**
358
- * if writable, configurable or enumerable or true or false
359
- * then this function creates a data descriptor with those
360
- * flags and the supplied value (there's no real reason to
361
- * invoke this function if you're supplying all four values)
362
- * ```
363
- *
364
- * Options are an object oriented way of supplying the alternate
365
- * flags to the data descriptor. They are
366
- *
367
- * • `value` - only referenced when an options object is the
368
- * only parameter
369
- * • `writable` - true if the value represented by this data
370
- * descriptor can be reassigned a new value.
371
- * • `configurable` - if true, the descriptor of the object
372
- * that this data descriptor represents can be redefined at
373
- * later time by subsequent calls to `Object.defineProperty`
374
- * or `Object.defineProperties`. If `.configurable` is true
375
- * this can be done even if `.writable` is set to false
376
- * • `enumerable` - if true, enumeration over the object this
377
- * descriptor is applied to, will show the property
378
- * represented by this descriptor. See the associated MDN
379
- * page regarding this `PropertyDescriptor` if you want to
380
- * know more.
381
- *
382
- * @param {(object|any)?} value the JavaScript value representing
383
- * this descriptor's value or an options object if it is the
384
- * only parameter.
385
- * @param {(object|boolean)?} optionsOrWritable true or false if
386
- * you wish the writable flag to be set. Optionally supply an
387
- * object with one of the supported options to configure the run
388
- * of the function.
389
- * @param {boolean?} configurable true or false if you wish to
390
- * configure the `.configurable` property of the descriptor
391
- * @param {boolean?} enumerable true or false if you wish to
392
- * configure the `.enumerable` property of the descriptor
393
- * @returns {PropertyDescriptor}
394
- *
395
- * @note More info on this can be found at the
396
- * [MDN Object.defineProperty/ies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
397
- * page
398
- *
399
- * @type {Function & { keys: string[] }}
400
- */
401
- get data() {
402
- function data(value, optionsOrWritable, configurable, enumerable) {
403
- const count = arguments.length;
404
- let valueIsDescriptor = false;
405
- if (count === 0) {
406
- return {
407
- value: undefined,
408
- writable: true,
409
- configurable: true,
410
- enumerable: true
411
- };
412
- }
413
- if (count === 1) {
414
- const stats = exports.DescriptorUtils.isDescriptor(value, true);
415
- if (stats.isValid && stats.isData) {
416
- valueIsDescriptor = true;
417
- }
418
- }
419
- let writable = optionsOrWritable === undefined
420
- ? true
421
- : !!optionsOrWritable;
422
- let options = typeof optionsOrWritable === 'boolean'
423
- ? {}
424
- : Object(optionsOrWritable);
425
- configurable = configurable === undefined ? true : !!configurable;
426
- enumerable = enumerable === undefined ? true : !!enumerable;
427
- if (valueIsDescriptor && !(options?.allowDescriptorValue)) {
428
- options = {
429
- writable: value?.writable ?? true,
430
- configurable: value?.configurable ?? true,
431
- enumerable: value?.enumerable ?? true,
432
- };
433
- value = value?.value;
434
- }
435
- if (options) {
436
- ({ writable, configurable, enumerable } = {
437
- ...{ writable, configurable, enumerable },
438
- ...options
439
- });
440
- }
441
- return { value, writable, configurable, enumerable };
442
- }
443
- Object.defineProperty(data, 'keys', {
444
- value: Object.defineProperties(['value', 'writable', 'configurable', 'enumerable'], {
445
- from: {
446
- value: function extractKeysFrom(object) {
447
- const response = {
448
- value: undefined,
449
- writable: undefined,
450
- configurable: undefined,
451
- enumerable: undefined,
452
- };
453
- if (!object || !(object instanceof Object))
454
- return response;
455
- for (const key of exports.DescriptorUtils.data.keys) {
456
- if (Reflect.has(object, key))
457
- response[key] = object[key];
458
- }
459
- },
460
- writable: false,
461
- configurable: false,
462
- enumerable: false,
463
- }
464
- }),
465
- writable: false,
466
- configurable: true,
467
- enumerable: false
468
- });
469
- return data;
470
- },
471
- describe(object, key, value, detectDescriptorValues = true) {
472
- const { isAccessor, isData, data } = exports.DescriptorUtils;
473
- if (!(object && object instanceof Object))
474
- return undefined;
475
- if (!(['string', 'number', 'symbol'].includes(typeof key)))
476
- return undefined;
477
- if (detectDescriptorValues && isAccessor(value) || isData(value)) {
478
- return Object.defineProperty(object, key, value);
479
- }
480
- else {
481
- return Object.defineProperty(object, key, data(value));
482
- }
483
- },
484
- describeMany(object, keyValues, detectDescriptorValues = true) {
485
- const { isAccessor, isData, isDescriptor, data, describe } = exports.DescriptorUtils;
486
- const isKey = k => ['string', 'number', 'symbol'].includes(typeof k);
487
- let map = undefined;
488
- if (Array.isArray(keyValues)) {
489
- map = new Map(keyValues.filter(keyValue => {
490
- return typeof keyValue === 'function' && keyValue.length === 2;
491
- }));
492
- }
493
- else if (keyValues instanceof Map) {
494
- map = keyValues;
495
- }
496
- else if (keyValues instanceof Object) {
497
- const descriptors = Object.getOwnPropertyDescriptors(keyValues);
498
- map = new Object.entries(descriptors);
499
- }
500
- else {
501
- return [];
502
- }
503
- for (const [key, value] of map) {
504
- if (detectDescriptorValues) {
505
- if (isDescriptor(key)) {
506
- }
507
- }
508
- }
509
- const accessorBase = { enumerable: true, configurable: true };
510
- const dataBase = { writable: true, ...accessorBase };
511
- const extractBase = descriptor => {
512
- if (isAccessor(descriptor)) {
513
- const { configurable, enumerable } = descriptor;
514
- return { configurable, enumerable };
515
- }
516
- else if (isData(descriptor)) {
517
- const { writable, configurable, enumerable } = descriptor;
518
- return { writable, configurable, enumerable };
519
- }
520
- return undefined;
521
- };
522
- // convert all map entries to
523
- // [baseDescriptor, {key: value, key: value, ...}]
524
- // unless detectDescriptorValues == false in which case
525
- // [dataBase, { key: value, key: value, etc... }]
526
- // ... dropping all non-isKey(key) values
527
- for (const [key, value] of map.entries()) {
528
- const descriptor = (detectDescriptorValues && isDescriptor(value)
529
- ? value
530
- : data(value, dataBase));
531
- }
532
- },
533
- extract(fromObject, keysToExtract, defaultIfMissing = undefined, extractDescriptors = false) {
534
- const { data } = exports.DescriptorUtils;
535
- const output = {};
536
- if (!fromObject || typeof fromObject !== 'object')
537
- return output;
538
- if (!Array.isArray(keysToExtract))
539
- keysToExtract = [keysToExtract];
540
- for (const key of keysToExtract) {
541
- let descriptor = Object.getOwnPropertyDescriptor(fromObject, key);
542
- if (!descriptor)
543
- descriptor = data(defaultIfMissing);
544
- if (extractDescriptors)
545
- descriptor.value = data(descriptor, { allowDescriptorValue: true });
546
- Object.defineProperty(output, key, descriptor);
547
- }
548
- return output;
549
- },
550
- /**
551
- * Determines if a given value is an accessor descriptor.
552
- *
553
- * An accessor descriptor is a property descriptor that defines
554
- * getter and/or setter functions for a property. This function
555
- * checks the validity of the descriptor and whether it qualifies
556
- * as an accessor.
557
- *
558
- * @param {Object} value - The descriptor object to evaluate.
559
- * @param {boolean} [strict=true] - If true, performs a strict
560
- * validation of the descriptor.
561
- * @returns {boolean} Returns true if the descriptor is valid and
562
- * is an accessor descriptor, otherwise false.
563
- *
564
- * @example
565
- * // Example usage:
566
- * const descriptor = { get: () => 42, set: (val) => {} }
567
- * const result = DescriptorUtils.isAccessor(descriptor)
568
- * console.log(result) // Outputs: true
569
- */
570
- isAccessor(value, strict = true) {
571
- const stats = exports.DescriptorUtils.isDescriptor(value, true, strict);
572
- return stats.isValid && stats.isAccessor;
573
- },
574
- /**
575
- * Checks if a given value is a data descriptor.
576
- *
577
- * A data descriptor is a property descriptor that defines a value
578
- * and optionally a writable attribute for a property. This function
579
- * evaluates the descriptor's validity and whether it qualifies as
580
- * a data descriptor.
581
- *
582
- * @param {Object} value - The descriptor object to evaluate.
583
- * @param {boolean} [strict=true] - If true, performs a strict
584
- * validation of the descriptor.
585
- * @returns {boolean} Returns true if the descriptor is valid and
586
- * is a data descriptor, otherwise false.
587
- *
588
- * @example
589
- * // Example usage:
590
- * const descriptor = { value: 42, writable: true }
591
- * const result = DescriptorUtils.isData(descriptor)
592
- * console.log(result) // Outputs: true
593
- */
594
- isData(value, strict = true) {
595
- const stats = exports.DescriptorUtils.isDescriptor(value, true, strict);
596
- return stats.isValid && stats.isData;
597
- },
598
- /**
599
- * A function that, given a value that might be a `PropertyDescriptor`,
600
- * calculates a deterministic probability that the supplied value is
601
- * an object that either is a `PropertyDescriptor` or that can function
602
- * as one.
603
- *
604
- * @param {unknown} value a JavaScript value that might be a
605
- * `PropertyDescriptor` type.
606
- * @param {boolean?} returnStats if this value is true, instead of returning
607
- * a determined boolean value indicating the supplied value might be a
608
- * `PropertyDescriptor`, an object containing the determined flags and score
609
- * the led to the determination instead is returned.
610
- * @param {boolean?} strict if this value is `true`, which is the default,
611
- * then the function will not allow descriptor compatible objects, rather it
612
- * will only return true if the object has keys that belong in a descriptor
613
- * and do not form an invalid combination.
614
- * @returns {IsDescriptorResponse} if `returnStats` is `true`
615
- * an object of type {@link IsDescriptorStats} is returned. This object
616
- * will have a lot of {@link Boolean} flags pertaining to the `true`/`false`
617
- * evaluation. If `returnStats` is `false`, then a boolean value denoting
618
- * whether or not the value is a {@link PropertyDescriptor} is returned
619
- * instead. This is effectively the same as the `isValid` parameter from the
620
- * stats block.
621
- */
622
- isDescriptor(value, returnStats = false, strict = true) {
623
- const areBools = (...props) => props.flat().every(prop => boolTypes.includes(typeof value[prop]));
624
- const areFuncs = (...props) => props.flat().every(prop => funcTypes.includes(typeof value[prop]));
625
- const hasKeyFn = (property) => Reflect.has(value, property);
626
- const isOfType = (type) => (element) => typeof element === type;
627
- const baseProps = ['configurable', 'enumerable'];
628
- const dataProps = ['value', 'writable'];
629
- const accessorProps = ['get', 'set'];
630
- const anyDescProps = [...baseProps, ...dataProps, ...accessorProps];
631
- const boolTypes = ['undefined', 'boolean'];
632
- const funcTypes = ['undefined', 'function'];
633
- const stats = {
634
- confidence: 0,
635
- hasAccessorKeys: false,
636
- hasBaseDescriptorKeys: false,
637
- hasDataKeys: false,
638
- isAccessor: false,
639
- isData: false,
640
- isValid: false,
641
- isBase: false,
642
- };
643
- if (!value || typeof value !== 'object' || !(value instanceof Object))
644
- return returnStats ? stats : false;
645
- let score = 0;
646
- if (value && typeof value === 'object') {
647
- const objKeys = Reflect.ownKeys(value);
648
- const nonDescKeys = objKeys.filter(k => !(anyDescProps.includes(k)));
649
- if (strict && nonDescKeys.length)
650
- return false;
651
- if (objKeys.length <= 4)
652
- score++;
653
- stats.hasAccessorKeys =
654
- accessorProps.some(hasKeyFn) && areFuncs(accessorProps);
655
- stats.hasDataKeys =
656
- dataProps.some(hasKeyFn) && areBools('writable');
657
- stats.hasBaseDescriptorKeys =
658
- baseProps.some(hasKeyFn) && areBools(baseProps);
659
- if (stats.hasBaseDescriptorKeys)
660
- score++;
661
- if (stats.hasAccessorKeys || stats.hasDataKeys)
662
- score++;
663
- if (score > 0)
664
- stats.isValid = true;
665
- if (score > 0 && stats.hasAccessorKeys)
666
- stats.isAccessor = true;
667
- if (score > 0 && stats.hasDataKeys)
668
- stats.isData = true;
669
- if (stats.isValid && !(['get', 'set', 'value'].some(hasKeyFn)))
670
- stats.isBase = true;
671
- if (stats.isValid && stats.isData && Reflect.has(value, 'value'))
672
- score++;
673
- else if (stats.isValid && stats.isAccessor) {
674
- if ([value?.get, value?.set].some(isOfType('function')))
675
- score++;
676
- }
677
- if (stats.hasAccessorKeys && stats.hasDataKeys) {
678
- score = 0;
679
- stats.isValid = false;
680
- }
681
- stats.confidence = parseFloat(score / 4.0);
682
- }
683
- if (returnStats)
684
- return stats;
685
- return score >= 0.0
686
- ? true
687
- : false;
688
- },
689
- /**
690
- * Redefines a property on an object with new descriptors and options.
691
- * This function allows renaming, aliasing, and redefining property
692
- * descriptors such as configurable, enumerable, writable, get, and set.
693
- *
694
- * @param {Object} object - The target object whose property is to be
695
- * redefined.
696
- * @param {string|symbol} key - The key of the property to redefine.
697
- * @param {Object} as - An object containing new property descriptors.
698
- * @param {Object} [options] - Optional settings for renaming and aliasing.
699
- * @param {string|symbol} [options.rename] - New key name for the property.
700
- * @param {Array<string|symbol>} [options.alsoAs] - Additional aliases for
701
- * the property.
702
- * @param {Object} [options.moveTo] optionally move the descriptor from this
703
- * object to another.
704
- * @returns {any} the result of `object[key]` in its final state
705
- *
706
- * @example
707
- * const obj = { a: 1 }
708
- * redescribe(obj, 'a', { writable: false }, { rename: 'b', alsoAs: ['c'] })
709
- * console.log(obj.b) // Outputs: 1
710
- * console.log(obj.c) // Outputs: 1
711
- */
712
- redescribe(object, key, as, options) {
713
- const { isAccessor, isData } = exports.DescriptorUtils;
714
- const ifThen = (condition, fn, ...args) => condition && fn(...args);
715
- const isBool = value => typeof value === 'boolean' || value instanceof Boolean;
716
- const isFunction = value => typeof value === 'function';
717
- const isObject = value => value && value instanceof Object;
718
- const isDefined = (value, key) => isObject(value) && Reflect.has(value, key);
719
- const isObjectKey = v => ['string', 'number', 'symbol'].includes(typeof v);
720
- const define = (key, values) => Object.defineProperty(object, key, values);
721
- const assign = (object, ...values) => Object.assign(object, ...values);
722
- const isAnObject = isObject(object);
723
- let asIsObject = isObject(as);
724
- const descriptor = isAnObject && Object.getOwnPropertyDescriptor(object, key);
725
- const aliases = [];
726
- if (descriptor && !asIsObject) {
727
- asIsObject = true;
728
- as = {};
729
- }
730
- if (isObject(options)) {
731
- if (isDefined(options, 'rename')) {
732
- const successfulDelete = delete object[key];
733
- if (successfulDelete)
734
- key = options.rename;
735
- }
736
- if (isDefined(options, 'alsoAs')) {
737
- if (Array.isArray(options.alsoAs)) {
738
- for (const value of options.alsoAs.filter(v => isObjectKey(v)))
739
- aliases.push(value);
740
- }
741
- else if (isObjectKey(options.alsoAs)) {
742
- aliases.push(options.alsoAs);
743
- }
744
- }
745
- if (isDefined(options, 'moveTo')) {
746
- ifThen(isObject(options.moveTo), () => (object = options.moveTo));
747
- }
748
- }
749
- if (isAnObject && asIsObject) {
750
- let { configurable, enumerable, writable, get, set, value } = as;
751
- if (isAccessor(descriptor)) {
752
- ifThen(isFunction(get), () => assign(descriptor, { get }));
753
- ifThen(isFunction(set), () => assign(descriptor, { set }));
754
- }
755
- ifThen(isBool(writable) && isData(descriptor), () => {
756
- assign(descriptor, {
757
- writable,
758
- value: isDefined(as, 'value')
759
- ? value
760
- : descriptor.value,
761
- });
762
- });
763
- ifThen(isBool(configurable), () => assign(descriptor, { configurable }));
764
- ifThen(isBool(enumerable), () => assign(descriptor, { enumerable }));
765
- define(key, descriptor);
766
- for (const alias of aliases) {
767
- define(alias, descriptor);
768
- }
769
- return object[key];
770
- }
771
- },
772
- /**
773
- * Retrieves the keys associated with accessor descriptors.
774
- *
775
- * Accessor descriptors are property descriptors that define
776
- * getter and/or setter functions for a property.
777
- *
778
- * @type {string[]}
779
- *
780
- * @example
781
- * // Example usage:
782
- * const keys = DescriptorUtils.kAccessorDescriptorKeys
783
- * console.log(keys) // Output: ['get', 'set']
784
- */
785
- get kAccessorDescriptorKeys() {
786
- return ['get', 'set'];
787
- },
788
- /**
789
- * Retrieves the keys associated with data descriptors.
790
- *
791
- * Data descriptors are property descriptors that define a value
792
- * and optionally a writable attribute for a property.
793
- *
794
- * @type {string[]}
795
- *
796
- * @example
797
- * // Example usage:
798
- * const keys = DescriptorUtils.kDataDescriptorKeys
799
- * console.log(keys) // Output: ['value', 'writable']
800
- */
801
- get kDataDescriptorKeys() {
802
- return ['value', 'writable'];
803
- },
804
- /**
805
- * Retrieves the keys associated with shared descriptors.
806
- *
807
- * Shared descriptors are property descriptors that define
808
- * common attributes for a property, such as whether the
809
- * property is configurable or enumerable.
810
- *
811
- * @type {string[]}
812
- *
813
- * @example
814
- * // Example usage:
815
- * const keys = DescriptorUtils.kSharedDescriptorKeys
816
- * console.log(keys) // Output: ['configurable', 'enumerable']
817
- */
818
- get kSharedDescriptorKeys() {
819
- return ['configurable', 'enumerable'];
820
- },
821
- /**
822
- * Retrieves all descriptor keys, combining accessor, data, and shared
823
- * descriptor keys.
824
- *
825
- * This getter method aggregates keys from accessor descriptors,
826
- * data descriptors, and shared descriptors into a single array.
827
- * This can be useful when you need to validate or inspect all
828
- * possible descriptor keys.
829
- *
830
- * @type {string[]}
831
- *
832
- * @example
833
- * // Example usage:
834
- * const allKeys = DescriptorUtils.kDescriptorKeys
835
- * console.log(allKeys)
836
- * // Output: [
837
- * // 'get', 'set', 'value', 'writable', 'configurable', 'enumerable'
838
- * // ]
839
- */
840
- get kDescriptorKeys() {
841
- return [
842
- ...(this.kAccessorDescriptorKeys),
843
- ...(this.kDataDescriptorKeys),
844
- ...(this.kSharedDescriptorKeys),
845
- ];
846
- }
847
- };
848
- // Destructure the functions individually...
849
- const { accessor, data, describe, describeMany, extract, isDescriptor, isAccessor, isData, redescribe, } = exports.DescriptorUtils;
850
- exports.accessor = accessor;
851
- exports.data = data;
852
- exports.describe = describe;
853
- exports.describeMany = describeMany;
854
- exports.extract = extract;
855
- exports.isDescriptor = isDescriptor;
856
- exports.isAccessor = isAccessor;
857
- exports.isData = isData;
858
- exports.redescribe = redescribe;
859
- // ...also destructure the constants individually....
860
- const { kAccessorDescriptorKeys, kDataDescriptorKeys, kDescriptorKeys, kSharedDescriptorKeys } = exports.DescriptorUtils;
861
- exports.kAccessorDescriptorKeys = kAccessorDescriptorKeys;
862
- exports.kDataDescriptorKeys = kDataDescriptorKeys;
863
- exports.kDescriptorKeys = kDescriptorKeys;
864
- exports.kSharedDescriptorKeys = kSharedDescriptorKeys;
865
- // Provide default exports as well
866
- exports.default = {
867
- DescriptorUtils: exports.DescriptorUtils,
868
- accessor,
869
- data,
870
- describe,
871
- describeMany,
872
- extract,
873
- isAccessor,
874
- isData,
875
- isDescriptor,
876
- redescribe,
877
- kAccessorDescriptorKeys,
878
- kDataDescriptorKeys,
879
- kDescriptorKeys,
880
- kSharedDescriptorKeys
881
- };
882
- // ---- non-exported helper functions ----
883
- function isObject(o) { return o && typeof o === 'object'; }
884
- function hasSome(object, ...keys) { return hasQuantity('some', object, keys); }
885
- function hasQuantity(quantityFn, object, keys) {
886
- return isObject(object) && (keys.flat(Infinity)
887
- .map(key => Reflect.has(object, key))[quantityFn](has => has));
888
- }
889
- //# sourceMappingURL=descriptor.utils.js.map