@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,146 +0,0 @@
1
- /**
2
- * Deferreds, which were first introduced by jQuery for browsers in the early
3
- * 2000s, are a way to manage asynchronous operations. They have been widely
4
- * used and replicated by engineers since then. Although the Promise class in
5
- * modern JavaScript provides a static method called `withResolvers` that
6
- * returns an object with similar properties to a Deferred, it is not directly
7
- * supported by Node.js.
8
- *
9
- * ```
10
- * const withResolvers = Promise.withResolvers()
11
- * Reflect.has(withResolvers, 'promise') // true
12
- * Reflect.has(withResolvers, 'resolve') // true
13
- * Reflect.has(withResolvers, 'reject') // true
14
- * ```
15
- *
16
- * This Deferred class extends the Promise class, allowing it to capture the
17
- * value or reason for easy access after resolution, akin to
18
- * {@link Promise.withResolvers}. As it extends {@link Promise}, it is
19
- * 'thenable' and works with `await` as if it were a native Promise. This
20
- * allows seamless integration with code expecting Promise-like objects.
21
- */
22
- export class Deferred extends Promise<any> {
23
- /**
24
- * A getter for the species symbol which returns a custom DeferredPromise
25
- * class. This class extends from Deferred and is used to ensure that the
26
- * constructor signature matches that of a Promise. The executor function
27
- * passed to the constructor of this class is used to initialize the Deferred
28
- * object with resolve and reject functions, similar to how a Promise would
29
- * be initialized.
30
- *
31
- * @returns {DeferredPromise} A DeferredPromise class that extends Deferred.
32
- */
33
- static get [Symbol.species](): DeferredPromise;
34
- /**
35
- * The constructor for Deferred instances. By default, a new Deferred will
36
- * have three important properties: `promise`, `resolve`, and `reject`.
37
- *
38
- * The constructor takes an object called `options`. It can have the
39
- * following properties:
40
- *
41
- * ```
42
- * interface BaseDeferredOptions {
43
- * // Deferreds store the value or reason. To turn this off, pass true
44
- * // to this option.
45
- * doNotTrackAnswers?: boolean;
46
- * }
47
- *
48
- * interface ResolveDeferredOptions {
49
- * // Passing in an option object with a resolve value will auto resolve
50
- * // the Deferred with your value. An error will be raised if both
51
- * // resolve and reject are supplied at the same time.
52
- * resolve?: (value: any) => void;
53
- * }
54
- *
55
- * interface RejectDeferredOptions {
56
- * // Passing in an option object with a reject reason will auto reject
57
- * // the Deferred with your reason. An error will be raised if both
58
- * // resolve and reject are supplied at the same time.
59
- * reject?: (reason: any) => void;
60
- * }
61
- *
62
- * type DeferredOptions = BaseDeferredOptions &
63
- * (ResolveDeferredOptions | RejectDeferredOptions)
64
- * ```
65
- *
66
- * @param {object} options see above for examples on supported options, but
67
- * when supplied, the constructor can take instructions on how to auto
68
- * resolve or reject the deferred created here.
69
- */
70
- constructor(options: object);
71
- /**
72
- * When the Deferred is settled with {@link Deferred.resolve}, the `value`
73
- * passed to that function will be set here as well.
74
- *
75
- * @type {*}
76
- */
77
- value: any;
78
- /**
79
- * When the Deferred is settled with {@link Deferred.reject}, the `reason`
80
- * passed to that rejection will also be stored here.
81
- *
82
- * @type {*}
83
- */
84
- reason: any;
85
- /**
86
- * Returns a boolean value that indicates whether or not this Deferred
87
- * has been settled (either resolve or reject have been invoked).
88
- *
89
- * @returns {boolean} `true` if either {@link Deferred.resolve} or
90
- * {@link Deferred.reject} have been invoked; `false` otherwise
91
- */
92
- get settled(): boolean;
93
- /**
94
- * A getter that returns a boolean indicating whether the Deferred instance
95
- * was rejected. This property can be used to check if the Deferred has been
96
- * settled with a rejection. It is particularly useful in scenarios where
97
- * the resolution status of the Deferred needs to be checked without
98
- * accessing the rejection reason or invoking any additional logic.
99
- *
100
- * @returns {boolean} `true` if the Deferred was rejected, otherwise `false`.
101
- */
102
- get wasRejected(): boolean;
103
- /**
104
- * A getter that returns a boolean indicating whether the Deferred instance
105
- * was resolved. This property is useful for checking if the Deferred has been
106
- * settled with a resolution, allowing for checks on the Deferred's status
107
- * without needing to access the resolved value or trigger any additional
108
- * logic.
109
- *
110
- * @returns {boolean} `true` if the Deferred was resolved, otherwise `false`.
111
- */
112
- get wasResolved(): boolean;
113
- /**
114
- * Accessor for the promise managed by this Deferred instance.
115
- *
116
- * This getter provides access to the internal promise which is controlled
117
- * by the Deferred's resolve and reject methods. It allows external code to
118
- * attach callbacks for the resolution or rejection of the Deferred without
119
- * the ability to directly resolve or reject it.
120
- *
121
- * @returns {Promise} The promise controlled by this Deferred instance.
122
- */
123
- get promise(): Promise<any>;
124
- /**
125
- * Resolves the Deferred with the given value. If the value is a thenable
126
- * (i.e., has a "then" method), the Deferred will "follow" that thenable,
127
- * adopting its eventual state; otherwise, the Deferred will be fulfilled
128
- * with the value. This function behaves the same as Promise.resolve.
129
- *
130
- * @param {*} value - The value to resolve the Deferred with.
131
- * @returns {Promise} A Promise that is resolved with the given value.
132
- */
133
- resolve(value: any): Promise<any>;
134
- /**
135
- * Rejects the Deferred with the given reason. This function behaves the
136
- * same as Promise.reject. The Deferred will be rejected with the provided
137
- * reason.
138
- *
139
- * @param {*} reason - The reason to reject the Deferred with.
140
- * @returns {Promise} A Promise that is rejected with the given reason.
141
- */
142
- reject(reason: any): Promise<any>;
143
- #private;
144
- }
145
- export const DeferredExtension: Extension;
146
- import { Extension } from '@nejs/extension';
@@ -1,287 +0,0 @@
1
- import { Extension } from '@nejs/extension';
2
- /**
3
- * Deferreds, which were first introduced by jQuery for browsers in the early
4
- * 2000s, are a way to manage asynchronous operations. They have been widely
5
- * used and replicated by engineers since then. Although the Promise class in
6
- * modern JavaScript provides a static method called `withResolvers` that
7
- * returns an object with similar properties to a Deferred, it is not directly
8
- * supported by Node.js.
9
- *
10
- * ```
11
- * const withResolvers = Promise.withResolvers()
12
- * Reflect.has(withResolvers, 'promise') // true
13
- * Reflect.has(withResolvers, 'resolve') // true
14
- * Reflect.has(withResolvers, 'reject') // true
15
- * ```
16
- *
17
- * This Deferred class extends the Promise class, allowing it to capture the
18
- * value or reason for easy access after resolution, akin to
19
- * {@link Promise.withResolvers}. As it extends {@link Promise}, it is
20
- * 'thenable' and works with `await` as if it were a native Promise. This
21
- * allows seamless integration with code expecting Promise-like objects.
22
- */
23
- export class Deferred extends Promise {
24
- /**
25
- * The promise backing this deferred object. Created when the constructor
26
- * runs, this promise is what all `Promise.prototype` functions are routed
27
- * to.
28
- *
29
- * @type {Promise}
30
- */
31
- #promise = null;
32
- /**
33
- * The reject() resolver that will be assigned when a new instance is
34
- * created. Invoking this function with or without a `reason` will cause
35
- * the deferred's promise to be settled.
36
- *
37
- * @type {function}
38
- */
39
- #reject = null;
40
- /**
41
- * The resolve() resolver that will be assigned when a new instance is
42
- * created. Invoking this function with or without a `value` will cause
43
- * the deferred's promise to be settled.
44
- *
45
- * @type {function}
46
- */
47
- #resolve = null;
48
- #rejected = false;
49
- #resolved = false;
50
- /**
51
- * When the Deferred is settled with {@link Deferred.resolve}, the `value`
52
- * passed to that function will be set here as well.
53
- *
54
- * @type {*}
55
- */
56
- value = null;
57
- /**
58
- * When the Deferred is settled with {@link Deferred.reject}, the `reason`
59
- * passed to that rejection will also be stored here.
60
- *
61
- * @type {*}
62
- */
63
- reason = null;
64
- /**
65
- * When either {@link Deferred.resolve} or {@link Deferred.reject} are called,
66
- * this property is set to `true`. Its current status at any time can be
67
- * queried using the {@link Deferred.settled} getter.
68
- *
69
- * @type {boolean}
70
- */
71
- #settled = false;
72
- /**
73
- * The constructor for Deferred instances. By default, a new Deferred will
74
- * have three important properties: `promise`, `resolve`, and `reject`.
75
- *
76
- * The constructor takes an object called `options`. It can have the
77
- * following properties:
78
- *
79
- * ```
80
- * interface BaseDeferredOptions {
81
- * // Deferreds store the value or reason. To turn this off, pass true
82
- * // to this option.
83
- * doNotTrackAnswers?: boolean;
84
- * }
85
- *
86
- * interface ResolveDeferredOptions {
87
- * // Passing in an option object with a resolve value will auto resolve
88
- * // the Deferred with your value. An error will be raised if both
89
- * // resolve and reject are supplied at the same time.
90
- * resolve?: (value: any) => void;
91
- * }
92
- *
93
- * interface RejectDeferredOptions {
94
- * // Passing in an option object with a reject reason will auto reject
95
- * // the Deferred with your reason. An error will be raised if both
96
- * // resolve and reject are supplied at the same time.
97
- * reject?: (reason: any) => void;
98
- * }
99
- *
100
- * type DeferredOptions = BaseDeferredOptions &
101
- * (ResolveDeferredOptions | RejectDeferredOptions)
102
- * ```
103
- *
104
- * @param {object} options see above for examples on supported options, but
105
- * when supplied, the constructor can take instructions on how to auto
106
- * resolve or reject the deferred created here.
107
- */
108
- constructor(options) {
109
- // Check if options is an object, if not, assign an empty object to config
110
- const config = (options && typeof (options) === 'object'
111
- ? options
112
- : {});
113
- // Throw an error if both resolve and reject options are provided
114
- if (config?.resolve && config?.reject) {
115
- throw new TypeError('resolve and reject options cannot be simultaneously provided');
116
- }
117
- // Create an empty object to store the resolve and reject functions
118
- let _resolve, _reject;
119
- // Create a new promise and assign its resolve and reject functions to resolvers
120
- super((resolve, reject) => {
121
- _resolve = resolve;
122
- _reject = reject;
123
- if (config?.executor && typeof (config?.executor) === 'function') {
124
- config?.executor(resolve, reject);
125
- }
126
- });
127
- // Define the resolve function for the Deferred instance
128
- this.#resolve = (value) => {
129
- // If doNotTrackAnswers is not set to true, store the value
130
- if (config?.doNotTrackAnswers !== true) {
131
- this.value = value;
132
- }
133
- // Mark the Deferred instance as settled
134
- this.#settled = true;
135
- // Mark the Deferred instance as resolved
136
- this.#resolved = true;
137
- // Resolve the promise with the provided value
138
- return _resolve(value);
139
- };
140
- // Define the reject function for the Deferred instance
141
- this.#reject = async (reason) => {
142
- // If doNotTrackAnswers is not set to true, store the reason
143
- if (config?.doNotTrackAnswers !== true) {
144
- this.reason = reason;
145
- }
146
- // Mark the Deferred instance as settled
147
- this.#settled = true;
148
- // Mark the Deferred as being rejected.
149
- this.#rejected = true;
150
- // Reject the promise with the provided reason
151
- return _reject(reason);
152
- };
153
- this.#promise = this;
154
- // If a resolve option is provided, resolve the Deferred instance with it
155
- if (config?.resolve) {
156
- this.#resolve(config?.resolve);
157
- }
158
- // If a reject option is provided, reject the Deferred instance with it
159
- else if (config?.reject) {
160
- this.#reject(config?.reject);
161
- }
162
- }
163
- /**
164
- * Returns a boolean value that indicates whether or not this Deferred
165
- * has been settled (either resolve or reject have been invoked).
166
- *
167
- * @returns {boolean} `true` if either {@link Deferred.resolve} or
168
- * {@link Deferred.reject} have been invoked; `false` otherwise
169
- */
170
- get settled() {
171
- return this.#settled;
172
- }
173
- /**
174
- * A getter that returns a boolean indicating whether the Deferred instance
175
- * was rejected. This property can be used to check if the Deferred has been
176
- * settled with a rejection. It is particularly useful in scenarios where
177
- * the resolution status of the Deferred needs to be checked without
178
- * accessing the rejection reason or invoking any additional logic.
179
- *
180
- * @returns {boolean} `true` if the Deferred was rejected, otherwise `false`.
181
- */
182
- get wasRejected() {
183
- return this.#rejected;
184
- }
185
- /**
186
- * A getter that returns a boolean indicating whether the Deferred instance
187
- * was resolved. This property is useful for checking if the Deferred has been
188
- * settled with a resolution, allowing for checks on the Deferred's status
189
- * without needing to access the resolved value or trigger any additional
190
- * logic.
191
- *
192
- * @returns {boolean} `true` if the Deferred was resolved, otherwise `false`.
193
- */
194
- get wasResolved() {
195
- return this.#resolved;
196
- }
197
- /**
198
- * Accessor for the promise managed by this Deferred instance.
199
- *
200
- * This getter provides access to the internal promise which is controlled
201
- * by the Deferred's resolve and reject methods. It allows external code to
202
- * attach callbacks for the resolution or rejection of the Deferred without
203
- * the ability to directly resolve or reject it.
204
- *
205
- * @returns {Promise} The promise controlled by this Deferred instance.
206
- */
207
- get promise() {
208
- return this.#promise;
209
- }
210
- /**
211
- * Resolves the Deferred with the given value. If the value is a thenable
212
- * (i.e., has a "then" method), the Deferred will "follow" that thenable,
213
- * adopting its eventual state; otherwise, the Deferred will be fulfilled
214
- * with the value. This function behaves the same as Promise.resolve.
215
- *
216
- * @param {*} value - The value to resolve the Deferred with.
217
- * @returns {Promise} A Promise that is resolved with the given value.
218
- */
219
- resolve(value) {
220
- return this.#resolve(value);
221
- }
222
- /**
223
- * Rejects the Deferred with the given reason. This function behaves the
224
- * same as Promise.reject. The Deferred will be rejected with the provided
225
- * reason.
226
- *
227
- * @param {*} reason - The reason to reject the Deferred with.
228
- * @returns {Promise} A Promise that is rejected with the given reason.
229
- */
230
- reject(reason) {
231
- return this.#reject(reason);
232
- }
233
- /**
234
- * Customizes the output of `util.inspect` on instances of Deferred when
235
- * used in Node.js. This method is invoked by Node.js's `util.inspect`
236
- * utility to format the inspection output of a Deferred instance.
237
- *
238
- * The output includes the state of the Deferred (resolved, rejected, or
239
- * unsettled) along with the resolved value or rejection reason, if
240
- * applicable. This provides a quick, readable status of the Deferred
241
- * instance directly in the console or debugging tools.
242
- *
243
- * @param {number} depth The depth to which `util.inspect` will recurse.
244
- * @param {object} options Formatting options provided by `util.inspect`.
245
- * @param {function} inspect Reference to the `util.inspect` function.
246
- * @returns {string} A formatted string representing the Deferred instance.
247
- */
248
- [Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {
249
- return [
250
- '\x1b[1mDeferred [\x1b[22;3mPromise\x1b[23;1m]\x1b[22m ',
251
- '{ ',
252
- (this.settled
253
- ? (this.wasResolved
254
- ? `resolved with \x1b[32m${this.value}\x1b[39m`
255
- : `rejected with \x1b[31m${this.reason?.message ?? this.reason}\x1b[39m`)
256
- : '\x1b[33munsettled valued or reason\x1b[39m'),
257
- ' }'
258
- ].join('');
259
- }
260
- /**
261
- * A getter for the species symbol which returns a custom DeferredPromise
262
- * class. This class extends from Deferred and is used to ensure that the
263
- * constructor signature matches that of a Promise. The executor function
264
- * passed to the constructor of this class is used to initialize the Deferred
265
- * object with resolve and reject functions, similar to how a Promise would
266
- * be initialized.
267
- *
268
- * @returns {DeferredPromise} A DeferredPromise class that extends Deferred.
269
- */
270
- static get [Symbol.species]() {
271
- return class DeferredPromise extends Deferred {
272
- /**
273
- * The constructor for the DeferredPromise class.
274
- * It takes an executor function which is used to initialize the Deferred.
275
- *
276
- * @param {Function} executor - A function that is passed with the resolve
277
- * and reject functions. The executor is expected to initialize the
278
- * Deferred by calling resolve or reject at some point.
279
- */
280
- constructor(executor) {
281
- super({ executor });
282
- }
283
- };
284
- }
285
- }
286
- export const DeferredExtension = new Extension(Deferred);
287
- //# sourceMappingURL=deferred.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"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