@nejs/basic-extensions 2.7.0 → 2.8.0

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/.vscode/settings.json +5 -0
  2. package/README.md +6129 -1574
  3. package/dist/@nejs/basic-extensions.bundle.2.7.0.js +19 -0
  4. package/dist/@nejs/basic-extensions.bundle.2.7.0.js.map +7 -0
  5. package/dist/cjs/array.extensions.d.ts +39 -0
  6. package/dist/cjs/array.extensions.js +303 -0
  7. package/dist/cjs/array.extensions.js.map +1 -0
  8. package/dist/cjs/big.int.extension.d.ts +31 -0
  9. package/dist/cjs/big.int.extension.js +164 -0
  10. package/dist/cjs/big.int.extension.js.map +1 -0
  11. package/dist/cjs/{newClasses → classes}/asyncIterable.js +32 -44
  12. package/dist/cjs/classes/asyncIterable.js.map +1 -0
  13. package/dist/cjs/{newClasses → classes}/deferred.js +66 -138
  14. package/dist/cjs/classes/deferred.js.map +1 -0
  15. package/dist/cjs/{newClasses → classes}/descriptor.js +56 -90
  16. package/dist/cjs/classes/descriptor.js.map +1 -0
  17. package/dist/cjs/classes/index.d.ts +13 -0
  18. package/dist/cjs/classes/index.js +57 -0
  19. package/dist/cjs/classes/index.js.map +1 -0
  20. package/dist/cjs/classes/introspector.d.ts +20 -0
  21. package/dist/cjs/classes/introspector.js +130 -0
  22. package/dist/cjs/classes/introspector.js.map +1 -0
  23. package/dist/cjs/{newClasses → classes}/iterable.js +42 -63
  24. package/dist/cjs/classes/iterable.js.map +1 -0
  25. package/dist/cjs/classes/param.parser.d.ts +227 -0
  26. package/dist/cjs/classes/param.parser.js +242 -0
  27. package/dist/cjs/classes/param.parser.js.map +1 -0
  28. package/dist/cjs/classes/pluggable.proxy.d.ts +152 -0
  29. package/dist/cjs/classes/pluggable.proxy.js +444 -0
  30. package/dist/cjs/classes/pluggable.proxy.js.map +1 -0
  31. package/dist/cjs/{newClasses → classes}/refmap.js +18 -30
  32. package/dist/cjs/classes/refmap.js.map +1 -0
  33. package/dist/cjs/{newClasses → classes}/refset.js +28 -47
  34. package/dist/cjs/classes/refset.js.map +1 -0
  35. package/dist/cjs/classes/symkeys.d.ts +292 -0
  36. package/dist/cjs/classes/symkeys.js +424 -0
  37. package/dist/cjs/classes/symkeys.js.map +1 -0
  38. package/dist/cjs/classes/type.d.ts +56 -0
  39. package/dist/cjs/classes/type.js +405 -0
  40. package/dist/cjs/classes/type.js.map +1 -0
  41. package/dist/cjs/function.extensions.js +757 -0
  42. package/dist/cjs/function.extensions.js.map +1 -0
  43. package/dist/cjs/global.this.js +261 -0
  44. package/dist/cjs/global.this.js.map +1 -0
  45. package/dist/cjs/index.d.ts +4 -3
  46. package/dist/cjs/index.js +62 -32
  47. package/dist/cjs/index.js.map +1 -1
  48. package/dist/cjs/json.extensions.d.ts +2 -0
  49. package/dist/cjs/json.extensions.js +107 -0
  50. package/dist/cjs/json.extensions.js.map +1 -0
  51. package/dist/{mjs/mapextensions.d.ts → cjs/map.extensions.d.ts} +1 -0
  52. package/dist/cjs/map.extensions.js +142 -0
  53. package/dist/cjs/map.extensions.js.map +1 -0
  54. package/dist/cjs/number.extension.d.ts +44 -0
  55. package/dist/cjs/number.extension.js +260 -0
  56. package/dist/cjs/number.extension.js.map +1 -0
  57. package/dist/cjs/object.extensions.d.ts +62 -0
  58. package/dist/cjs/object.extensions.js +1116 -0
  59. package/dist/cjs/object.extensions.js.map +1 -0
  60. package/dist/cjs/proxy.extensions.d.ts +2 -0
  61. package/dist/cjs/proxy.extensions.js +207 -0
  62. package/dist/cjs/proxy.extensions.js.map +1 -0
  63. package/dist/cjs/reflect.extensions.js +316 -0
  64. package/dist/cjs/reflect.extensions.js.map +1 -0
  65. package/dist/cjs/regular.expression.extensions.d.ts +2 -0
  66. package/dist/cjs/regular.expression.extensions.js +423 -0
  67. package/dist/cjs/regular.expression.extensions.js.map +1 -0
  68. package/dist/cjs/set.extensions.d.ts +40 -0
  69. package/dist/cjs/{setextensions.js → set.extensions.js} +150 -2
  70. package/dist/cjs/set.extensions.js.map +1 -0
  71. package/dist/cjs/string.extensions.js +471 -0
  72. package/dist/cjs/string.extensions.js.map +1 -0
  73. package/dist/{mjs/symbolextensions.d.ts → cjs/symbol.extensions.d.ts} +1 -0
  74. package/dist/cjs/symbol.extensions.js +259 -0
  75. package/dist/cjs/symbol.extensions.js.map +1 -0
  76. package/dist/cjs/{weakrefextensions.js → weakref.extensions.js} +1 -1
  77. package/dist/cjs/weakref.extensions.js.map +1 -0
  78. package/dist/mjs/array.extensions.d.ts +39 -0
  79. package/dist/mjs/array.extensions.js +300 -0
  80. package/dist/mjs/array.extensions.js.map +1 -0
  81. package/dist/mjs/big.int.extension.d.ts +31 -0
  82. package/dist/mjs/big.int.extension.js +161 -0
  83. package/dist/mjs/big.int.extension.js.map +1 -0
  84. package/dist/mjs/classes/asyncIterable.js.map +1 -0
  85. package/dist/mjs/classes/deferred.js.map +1 -0
  86. package/dist/mjs/{newClasses → classes}/descriptor.js +7 -4
  87. package/dist/mjs/classes/descriptor.js.map +1 -0
  88. package/dist/mjs/classes/index.d.ts +13 -0
  89. package/dist/mjs/classes/index.js +40 -0
  90. package/dist/mjs/classes/index.js.map +1 -0
  91. package/dist/mjs/classes/introspector.d.ts +20 -0
  92. package/dist/mjs/classes/introspector.js +126 -0
  93. package/dist/mjs/classes/introspector.js.map +1 -0
  94. package/dist/mjs/classes/iterable.js.map +1 -0
  95. package/dist/mjs/classes/param.parser.d.ts +227 -0
  96. package/dist/mjs/classes/param.parser.js +238 -0
  97. package/dist/mjs/classes/param.parser.js.map +1 -0
  98. package/dist/mjs/classes/pluggable.proxy.d.ts +152 -0
  99. package/dist/mjs/classes/pluggable.proxy.js +438 -0
  100. package/dist/mjs/classes/pluggable.proxy.js.map +1 -0
  101. package/dist/mjs/{newClasses → classes}/refmap.js +3 -3
  102. package/dist/mjs/classes/refmap.js.map +1 -0
  103. package/dist/mjs/classes/refset.js.map +1 -0
  104. package/dist/mjs/classes/symkeys.d.ts +292 -0
  105. package/dist/mjs/classes/symkeys.js +420 -0
  106. package/dist/mjs/classes/symkeys.js.map +1 -0
  107. package/dist/mjs/classes/type.d.ts +56 -0
  108. package/dist/mjs/classes/type.js +401 -0
  109. package/dist/mjs/classes/type.js.map +1 -0
  110. package/dist/mjs/function.extensions.js +754 -0
  111. package/dist/mjs/function.extensions.js.map +1 -0
  112. package/dist/mjs/global.this.js +258 -0
  113. package/dist/mjs/global.this.js.map +1 -0
  114. package/dist/mjs/index.d.ts +4 -3
  115. package/dist/mjs/index.js +49 -19
  116. package/dist/mjs/index.js.map +1 -1
  117. package/dist/mjs/json.extensions.d.ts +2 -0
  118. package/dist/mjs/json.extensions.js +104 -0
  119. package/dist/mjs/json.extensions.js.map +1 -0
  120. package/dist/{cjs/mapextensions.d.ts → mjs/map.extensions.d.ts} +1 -0
  121. package/dist/mjs/map.extensions.js +139 -0
  122. package/dist/mjs/map.extensions.js.map +1 -0
  123. package/dist/mjs/number.extension.d.ts +44 -0
  124. package/dist/mjs/number.extension.js +257 -0
  125. package/dist/mjs/number.extension.js.map +1 -0
  126. package/dist/mjs/object.extensions.d.ts +62 -0
  127. package/dist/mjs/object.extensions.js +1112 -0
  128. package/dist/mjs/object.extensions.js.map +1 -0
  129. package/dist/mjs/proxy.extensions.d.ts +2 -0
  130. package/dist/mjs/proxy.extensions.js +204 -0
  131. package/dist/mjs/proxy.extensions.js.map +1 -0
  132. package/dist/mjs/reflect.extensions.js +313 -0
  133. package/dist/mjs/reflect.extensions.js.map +1 -0
  134. package/dist/mjs/regular.expression.extensions.d.ts +2 -0
  135. package/dist/mjs/regular.expression.extensions.js +420 -0
  136. package/dist/mjs/regular.expression.extensions.js.map +1 -0
  137. package/dist/mjs/set.extensions.d.ts +40 -0
  138. package/dist/mjs/{setextensions.js → set.extensions.js} +149 -1
  139. package/dist/mjs/set.extensions.js.map +1 -0
  140. package/dist/mjs/string.extensions.js +468 -0
  141. package/dist/mjs/string.extensions.js.map +1 -0
  142. package/dist/{cjs/symbolextensions.d.ts → mjs/symbol.extensions.d.ts} +1 -0
  143. package/dist/mjs/symbol.extensions.js +256 -0
  144. package/dist/mjs/symbol.extensions.js.map +1 -0
  145. package/dist/mjs/{weakrefextensions.js → weakref.extensions.js} +1 -1
  146. package/dist/mjs/weakref.extensions.js.map +1 -0
  147. package/docs/index.html +24045 -5805
  148. package/package.json +6 -4
  149. package/src/array.extensions.js +322 -0
  150. package/src/big.int.extension.js +163 -0
  151. package/src/{newClasses → classes}/descriptor.js +16 -12
  152. package/src/classes/index.js +51 -0
  153. package/src/classes/introspector.js +167 -0
  154. package/src/classes/param.parser.js +253 -0
  155. package/src/classes/pluggable.proxy.js +485 -0
  156. package/src/{newClasses → classes}/refmap.js +5 -3
  157. package/src/classes/symkeys.js +464 -0
  158. package/src/classes/type.js +427 -0
  159. package/src/function.extensions.js +818 -0
  160. package/src/global.this.js +304 -0
  161. package/src/index.js +56 -23
  162. package/src/json.extensions.js +108 -0
  163. package/src/map.extensions.js +144 -0
  164. package/src/number.extension.js +273 -0
  165. package/src/object.extensions.js +1222 -0
  166. package/src/proxy.extensions.js +229 -0
  167. package/src/reflect.extensions.js +346 -0
  168. package/src/regular.expression.extensions.js +451 -0
  169. package/src/{setextensions.js → set.extensions.js} +151 -2
  170. package/src/string.extensions.js +515 -0
  171. package/src/symbol.extensions.js +268 -0
  172. package/tests/newClasses/refmap.test.js +3 -2
  173. package/tsconfig.base.json +5 -3
  174. package/tsconfig.cjs.json +2 -2
  175. package/tsconfig.esm.json +2 -2
  176. package/dist/@nejs/basic-extensions.bundle.2.6.0.js +0 -17
  177. package/dist/@nejs/basic-extensions.bundle.2.6.0.js.map +0 -7
  178. package/dist/cjs/arrayextensions.d.ts +0 -10
  179. package/dist/cjs/arrayextensions.js +0 -73
  180. package/dist/cjs/arrayextensions.js.map +0 -1
  181. package/dist/cjs/functionextensions.js +0 -202
  182. package/dist/cjs/functionextensions.js.map +0 -1
  183. package/dist/cjs/globals.js +0 -166
  184. package/dist/cjs/globals.js.map +0 -1
  185. package/dist/cjs/mapextensions.js +0 -32
  186. package/dist/cjs/mapextensions.js.map +0 -1
  187. package/dist/cjs/newClasses/asyncIterable.js.map +0 -1
  188. package/dist/cjs/newClasses/deferred.js.map +0 -1
  189. package/dist/cjs/newClasses/descriptor.js.map +0 -1
  190. package/dist/cjs/newClasses/iterable.js.map +0 -1
  191. package/dist/cjs/newClasses/refmap.js.map +0 -1
  192. package/dist/cjs/newClasses/refset.js.map +0 -1
  193. package/dist/cjs/objectextensions.d.ts +0 -11
  194. package/dist/cjs/objectextensions.js +0 -232
  195. package/dist/cjs/objectextensions.js.map +0 -1
  196. package/dist/cjs/reflectextensions.js +0 -111
  197. package/dist/cjs/reflectextensions.js.map +0 -1
  198. package/dist/cjs/setextensions.d.ts +0 -2
  199. package/dist/cjs/setextensions.js.map +0 -1
  200. package/dist/cjs/stringextensions.js +0 -158
  201. package/dist/cjs/stringextensions.js.map +0 -1
  202. package/dist/cjs/symbolextensions.js +0 -69
  203. package/dist/cjs/symbolextensions.js.map +0 -1
  204. package/dist/cjs/weakrefextensions.js.map +0 -1
  205. package/dist/mjs/arrayextensions.d.ts +0 -10
  206. package/dist/mjs/arrayextensions.js +0 -70
  207. package/dist/mjs/arrayextensions.js.map +0 -1
  208. package/dist/mjs/functionextensions.js +0 -199
  209. package/dist/mjs/functionextensions.js.map +0 -1
  210. package/dist/mjs/globals.js +0 -163
  211. package/dist/mjs/globals.js.map +0 -1
  212. package/dist/mjs/mapextensions.js +0 -29
  213. package/dist/mjs/mapextensions.js.map +0 -1
  214. package/dist/mjs/newClasses/asyncIterable.js.map +0 -1
  215. package/dist/mjs/newClasses/deferred.js.map +0 -1
  216. package/dist/mjs/newClasses/descriptor.js.map +0 -1
  217. package/dist/mjs/newClasses/iterable.js.map +0 -1
  218. package/dist/mjs/newClasses/refmap.js.map +0 -1
  219. package/dist/mjs/newClasses/refset.js.map +0 -1
  220. package/dist/mjs/objectextensions.d.ts +0 -11
  221. package/dist/mjs/objectextensions.js +0 -229
  222. package/dist/mjs/objectextensions.js.map +0 -1
  223. package/dist/mjs/reflectextensions.js +0 -108
  224. package/dist/mjs/reflectextensions.js.map +0 -1
  225. package/dist/mjs/setextensions.d.ts +0 -2
  226. package/dist/mjs/setextensions.js.map +0 -1
  227. package/dist/mjs/stringextensions.js +0 -155
  228. package/dist/mjs/stringextensions.js.map +0 -1
  229. package/dist/mjs/symbolextensions.js +0 -66
  230. package/dist/mjs/symbolextensions.js.map +0 -1
  231. package/dist/mjs/weakrefextensions.js.map +0 -1
  232. package/src/arrayextensions.js +0 -75
  233. package/src/functionextensions.js +0 -225
  234. package/src/globals.js +0 -196
  235. package/src/mapextensions.js +0 -32
  236. package/src/objectextensions.js +0 -256
  237. package/src/reflectextensions.js +0 -118
  238. package/src/stringextensions.js +0 -166
  239. package/src/symbolextensions.js +0 -69
  240. /package/dist/cjs/{newClasses → classes}/asyncIterable.d.ts +0 -0
  241. /package/dist/cjs/{newClasses → classes}/deferred.d.ts +0 -0
  242. /package/dist/cjs/{newClasses → classes}/descriptor.d.ts +0 -0
  243. /package/dist/cjs/{newClasses → classes}/iterable.d.ts +0 -0
  244. /package/dist/cjs/{newClasses → classes}/refmap.d.ts +0 -0
  245. /package/dist/cjs/{newClasses → classes}/refset.d.ts +0 -0
  246. /package/dist/cjs/{functionextensions.d.ts → function.extensions.d.ts} +0 -0
  247. /package/dist/cjs/{globals.d.ts → global.this.d.ts} +0 -0
  248. /package/dist/cjs/{reflectextensions.d.ts → reflect.extensions.d.ts} +0 -0
  249. /package/dist/cjs/{stringextensions.d.ts → string.extensions.d.ts} +0 -0
  250. /package/dist/cjs/{weakrefextensions.d.ts → weakref.extensions.d.ts} +0 -0
  251. /package/dist/mjs/{newClasses → classes}/asyncIterable.d.ts +0 -0
  252. /package/dist/mjs/{newClasses → classes}/asyncIterable.js +0 -0
  253. /package/dist/mjs/{newClasses → classes}/deferred.d.ts +0 -0
  254. /package/dist/mjs/{newClasses → classes}/deferred.js +0 -0
  255. /package/dist/mjs/{newClasses → classes}/descriptor.d.ts +0 -0
  256. /package/dist/mjs/{newClasses → classes}/iterable.d.ts +0 -0
  257. /package/dist/mjs/{newClasses → classes}/iterable.js +0 -0
  258. /package/dist/mjs/{newClasses → classes}/refmap.d.ts +0 -0
  259. /package/dist/mjs/{newClasses → classes}/refset.d.ts +0 -0
  260. /package/dist/mjs/{newClasses → classes}/refset.js +0 -0
  261. /package/dist/mjs/{functionextensions.d.ts → function.extensions.d.ts} +0 -0
  262. /package/dist/mjs/{globals.d.ts → global.this.d.ts} +0 -0
  263. /package/dist/mjs/{reflectextensions.d.ts → reflect.extensions.d.ts} +0 -0
  264. /package/dist/mjs/{stringextensions.d.ts → string.extensions.d.ts} +0 -0
  265. /package/dist/mjs/{weakrefextensions.d.ts → weakref.extensions.d.ts} +0 -0
  266. /package/src/{newClasses → classes}/asyncIterable.js +0 -0
  267. /package/src/{newClasses → classes}/deferred.js +0 -0
  268. /package/src/{newClasses → classes}/iterable.js +0 -0
  269. /package/src/{newClasses → classes}/refset.js +0 -0
  270. /package/src/{weakrefextensions.js → weakref.extensions.js} +0 -0
@@ -0,0 +1,423 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RegExpExtensions = void 0;
4
+ const extension_1 = require("@nejs/extension");
5
+ exports.RegExpExtensions = new extension_1.Patch(RegExp, {
6
+ [extension_1.Patch.kMutablyHidden]: {
7
+ /**
8
+ * Generates a regular expression pattern that matches any character.
9
+ *
10
+ * This method creates a regular expression pattern that matches any
11
+ * character. The pattern can be configured to be greedy or non-greedy,
12
+ * and to include or exclude newline characters.
13
+ *
14
+ * @param {boolean} [greedy=false] - If true, the pattern will be greedy,
15
+ * meaning it will match as many characters as possible. If false, the
16
+ * pattern will be non-greedy, meaning it will match as few characters
17
+ * as possible.
18
+ * @param {boolean} [includeNewlines=false] - If true, the pattern will
19
+ * include newline characters ('\n' and '\r'). If false, newline
20
+ * characters will be excluded from the pattern.
21
+ * @returns {string} - The generated regular expression pattern.
22
+ *
23
+ * @example
24
+ * // Generate a non-greedy pattern that excludes newlines
25
+ * console.log(anything()) // Output: '[.]*?'
26
+ *
27
+ * @example
28
+ * // Generate a greedy pattern that includes newlines
29
+ * console.log(anything(true, true)) // Output: '[.\\n\\r]*'
30
+ */
31
+ anything(greedy = false, includeNewlines = false) {
32
+ return `[.${includeNewlines ? '\\n\\r' : ''}]*${greedy ? '' : '?'}`;
33
+ },
34
+ /**
35
+ * Creates a non-capturing group in a regular expression.
36
+ *
37
+ * This method wraps the provided string in a non-capturing group,
38
+ * which is denoted by the syntax `(?:...)` in a regular expression.
39
+ * Non-capturing groups match the pattern inside the group but do not
40
+ * capture the matched content for later use.
41
+ *
42
+ * @param {string} string - The string to be wrapped in a non-capturing group.
43
+ * @returns {string} - The string wrapped in a non-capturing group.
44
+ *
45
+ * @example
46
+ * // Suppose we have a string 'abc'
47
+ * const str = 'abc'
48
+ *
49
+ * // Using `nonCaptureGroup`
50
+ * console.log(nonCaptureGroup(str)) // Output: '(?:abc)'
51
+ */
52
+ nonCaptureGroup(string) {
53
+ return `(?:${string})`;
54
+ },
55
+ /**
56
+ * Creates a capturing group in a regular expression.
57
+ *
58
+ * This method wraps the provided string in a capturing group,
59
+ * which is denoted by the syntax `(...)` in a regular expression.
60
+ * Capturing groups match the pattern inside the group and capture
61
+ * the matched content for later use.
62
+ *
63
+ * @param {string} string - The string to be wrapped in a capturing group.
64
+ * @returns {string} - The string wrapped in a capturing group.
65
+ *
66
+ * @example
67
+ * // Suppose we have a string 'abc'
68
+ * const str = 'abc'
69
+ *
70
+ * // Using `captureGroup`
71
+ * console.log(captureGroup(str)) // Output: '(abc)'
72
+ */
73
+ captureGroup(string) {
74
+ return `(${string})`;
75
+ },
76
+ /**
77
+ * Creates a regular expression pattern that matches any one of the
78
+ * provided strings.
79
+ *
80
+ * This method takes any number of strings as arguments, and returns a
81
+ * string that represents a regular expression pattern. The pattern
82
+ * matches any one of the provided strings. The strings are joined
83
+ * together with the '|' character, which represents the OR operator
84
+ * in regular expressions.
85
+ *
86
+ * @param {...string} strings - The strings to be included in the pattern.
87
+ * @returns {string} - A string representing a regular expression pattern
88
+ * that matches any one of the provided strings.
89
+ *
90
+ * @example
91
+ * // Suppose we have strings 'abc', 'def', and 'ghi'
92
+ * const str1 = 'abc'
93
+ * const str2 = 'def'
94
+ * const str3 = 'ghi'
95
+ *
96
+ * // Using `oneOf`
97
+ * console.log(oneOf(str1, str2, str3)) // Output: 'abc|def|ghi'
98
+ */
99
+ oneOf(...strings) {
100
+ return strings.join('|');
101
+ },
102
+ /**
103
+ * Creates a regular expression pattern that matches zero or more
104
+ * occurrences of the provided string.
105
+ *
106
+ * This method wraps the provided string in a non-capturing group,
107
+ * which is denoted by the syntax `(?:...)` in a regular expression,
108
+ * and appends the `*` character, which represents zero or more
109
+ * occurrences in regular expressions.
110
+ *
111
+ * @param {string} string - The string to be matched zero or more times.
112
+ * @returns {string} - A string representing a regular expression pattern
113
+ * that matches zero or more occurrences of the provided string.
114
+ *
115
+ * @example
116
+ * // Suppose we have a string 'abc'
117
+ * const str = 'abc'
118
+ *
119
+ * // Using `zeroOrMore`
120
+ * console.log(zeroOrMore(str)) // Output: '(?:abc)*'
121
+ */
122
+ zeroOrMore(string) {
123
+ return `(?:${string})*`;
124
+ },
125
+ /**
126
+ * Creates a regular expression pattern that matches zero or one
127
+ * occurrence of the provided string.
128
+ *
129
+ * This method wraps the provided string in a non-capturing group,
130
+ * which is denoted by the syntax `(?:...)` in a regular expression,
131
+ * and appends the `?` character, which represents zero or one
132
+ * occurrence in regular expressions.
133
+ *
134
+ * @param {string} string - The string to be matched zero or one time.
135
+ * @returns {string} - A string representing a regular expression pattern
136
+ * that matches zero or one occurrence of the provided string.
137
+ *
138
+ * @example
139
+ * // Suppose we have a string 'abc'
140
+ * const str = 'abc'
141
+ *
142
+ * // Using `zeroOrOne`
143
+ * console.log(zeroOrOne(str)) // Output: '(?:abc)?'
144
+ */
145
+ zeroOrOne(string) {
146
+ return `(?:${string})?`;
147
+ },
148
+ /**
149
+ * Escapes special characters in a string for use in a regular expression.
150
+ *
151
+ * This method checks if the `RegExp.escape` method is available. If it is,
152
+ * it uses that method to escape the string. If it's not, it uses a polyfill
153
+ * method to escape the string.
154
+ *
155
+ * The polyfill method replaces all special characters in the string with
156
+ * their escaped equivalents. The special characters are defined by the
157
+ * regular expression `/[-[\]{}()*+?.,\\^$|#\s]/g`.
158
+ *
159
+ * @param {string} string - The string to be escaped.
160
+ * @returns {string} - The escaped string.
161
+ *
162
+ * @example
163
+ * // Suppose we have a string with special characters
164
+ * const str = 'Hello, [World]!'
165
+ *
166
+ * // Using `escape` or `escapePolyfill`
167
+ * console.log(RegExp[RegExp.escape ? 'escapePolyfill' : 'escape'](str))
168
+ * // Output: 'Hello\\, \\[World\\]\\!'
169
+ */
170
+ escape(string) {
171
+ return RegExpEscape(string);
172
+ },
173
+ /**
174
+ * Getter method that returns a string 'null'.
175
+ *
176
+ * This method is used when you need a string representation of null
177
+ * in your regular expressions. It simply returns the string 'null'.
178
+ *
179
+ * @returns {string} - A string 'null'.
180
+ *
181
+ * @example
182
+ * // Using `null`
183
+ * console.log(this.null) // Output: 'null'
184
+ */
185
+ get null() {
186
+ return 'null';
187
+ },
188
+ /**
189
+ * Getter method that returns a regular expression string for boolean
190
+ * values.
191
+ *
192
+ * This method uses the `oneOf` method to create a regular expression
193
+ * string that matches either 'true' or 'false'. This is useful when you
194
+ * need to match boolean values in a string using a regular expression.
195
+ *
196
+ * @returns {string} - A regular expression string that matches 'true'
197
+ * or 'false'.
198
+ *
199
+ * @example
200
+ * // Using `bool`
201
+ * const boolRegex = new RegExp(this.bool)
202
+ * console.log(boolRegex.test('true')) // Output: true
203
+ * console.log(boolRegex.test('false')) // Output: true
204
+ * console.log(boolRegex.test('maybe')) // Output: false
205
+ */
206
+ get bool() {
207
+ return this.oneOf('true', 'false');
208
+ },
209
+ /**
210
+ * Generates a regular expression string that matches the symbols of
211
+ * specified currencies.
212
+ *
213
+ * This method uses the Intl API to get the symbols of the specified
214
+ * currencies and constructs a regular expression string that matches
215
+ * these symbols. If no specific currencies are provided, it defaults
216
+ * to all known currencies. If a single currency is provided as a
217
+ * string, it is converted to an array. If the symbols array is empty
218
+ * after filtering out unknown currencies, it defaults back to all
219
+ * known currencies.
220
+ *
221
+ * @param {Array|string} [symbols=[['*'], ['USD','GBP']][0]] - The
222
+ * currencies to include in the regular expression. Can be an array
223
+ * of currency codes or a single currency code as a string. Defaults
224
+ * to all known currencies.
225
+ * @param {string} [locale='en-US'] - The locale to use when getting
226
+ * the currency symbols. Defaults to 'en-US'.
227
+ * @returns {string} - A regular expression string that matches the
228
+ * symbols of the specified currencies.
229
+ *
230
+ * @example
231
+ * // Using `currencySymbols` with default parameters
232
+ * console.log(this.currencySymbols())
233
+ * // Output: A regular expression string that matches all known
234
+ * // currency symbols
235
+ *
236
+ * @example
237
+ * // Using `currencySymbols` with specific currencies
238
+ * console.log(this.currencySymbols(['USD', 'EUR']))
239
+ * // Output: A regular expression string that matches the symbols
240
+ * // of USD and EUR
241
+ */
242
+ currencySymbols(symbols = [['*'], ['USD', 'GBP']][0], locale = 'en-US') {
243
+ const known = Intl.supportedValuesOf('currency');
244
+ const has = code => !!~known.indexOf(code);
245
+ if (typeof symbols === 'string' && has(symbols)) {
246
+ symbols = [symbols];
247
+ }
248
+ if (!Array.isArray(symbols)) {
249
+ symbols = known;
250
+ }
251
+ symbols = symbols.filter(symbol => has(symbol));
252
+ if (!symbols.length) {
253
+ symbols = known;
254
+ }
255
+ const opts = (currency) => ({ style: 'currency', currency });
256
+ const fmt = (place, currency) => Intl.NumberFormat(place, opts(currency));
257
+ const codes = (((symbols.length === 1 && symbols[0] === '*') ? known : symbols)
258
+ .filter(code => has(code))
259
+ .map(currency => {
260
+ const symbol = fmt(locale, currency).formatToParts()?.[0].value;
261
+ return symbol && `(?:${RegExp.escape(symbol)})`;
262
+ })
263
+ .join('|'));
264
+ return codes;
265
+ },
266
+ /**
267
+ * Getter method that returns a regular expression string for numbers.
268
+ *
269
+ * This method returns a regular expression string that matches both
270
+ * integer and floating point numbers. The returned regular expression
271
+ * string is '\\d+\\.?\\d*', which matches one or more digits followed
272
+ * by an optional decimal point and zero or more digits.
273
+ *
274
+ * @returns {string} - A regular expression string that matches numbers.
275
+ *
276
+ * @example
277
+ * // Using `number`
278
+ * const numberRegex = new RegExp(this.number)
279
+ * console.log(numberRegex.test('123')) // Output: true
280
+ * console.log(numberRegex.test('123.45')) // Output: true
281
+ * console.log(numberRegex.test('abc')) // Output: false
282
+ */
283
+ get number() {
284
+ const instance = Object(`\\d+\\.?\\d*`);
285
+ const self = this;
286
+ Object.defineProperties(instance, {
287
+ // alias for .float
288
+ any: { get() { return String(instance); } },
289
+ /**
290
+ * Getter method that returns a regular expression string for floating
291
+ * point numbers.
292
+ *
293
+ * This method returns a regular expression string that matches floating
294
+ * point numbers. It leverages the 'number' getter method which matches
295
+ * both integer and floating point numbers. The returned regular expression
296
+ * string is '\\d+\\.?\\d*', which matches one or more digits followed by
297
+ * an optional decimal point and zero or more digits.
298
+ *
299
+ * @returns {string} - A regular expression string that matches floating
300
+ * point numbers.
301
+ *
302
+ * @example
303
+ * // Using `float`
304
+ * const floatRegex = new RegExp(this.float)
305
+ * console.log(floatRegex.test('123.45')) // Output: true
306
+ * console.log(floatRegex.test('123')) // Output: false
307
+ * console.log(floatRegex.test('abc')) // Output: false
308
+ */
309
+ float: { get() { return String(instance); } },
310
+ // any known locale currency symbol + .float
311
+ money: { get() { return `(?:${self.currencySymbols()})?${this.float}`; } },
312
+ /**
313
+ * Getter method that returns a regular expression string for integers.
314
+ *
315
+ * This method returns a regular expression string that matches integer
316
+ * numbers. The returned regular expression string is '\\d+', which matches
317
+ * one or more digits.
318
+ *
319
+ * @returns {string} - A regular expression string that matches integers.
320
+ *
321
+ * @example
322
+ * // Using `integer`
323
+ * const integerRegex = new RegExp(this.integer)
324
+ * console.log(integerRegex.test('123')) // Output: true
325
+ * console.log(integerRegex.test('123.45')) // Output: false
326
+ * console.log(integerRegex.test('abc')) // Output: false
327
+ */
328
+ integer: { get() { return `\\d+`; } },
329
+ /**
330
+ * Getter method that returns a regular expression string for pretty
331
+ * numbers.
332
+ *
333
+ * This method returns a regular expression string that matches numbers
334
+ * with commas or spaces for thousands separators. The returned regular
335
+ * expression string is '[\\d\\$]+\\.?[\\d,\\$]*', which matches one or
336
+ * more digits or dollar signs, followed by an optional decimal point,
337
+ * and zero or more digits, commas, or dollar signs.
338
+ *
339
+ * @returns {string} - A regular expression string that matches pretty
340
+ * numbers.
341
+ *
342
+ * @example
343
+ * // Using `pretty`
344
+ * const prettyRegex = new RegExp(this.pretty)
345
+ * console.log(prettyRegex.test('1,234.56')) // Output: true
346
+ * console.log(prettyRegex.test('1234.56')) // Output: true
347
+ * console.log(prettyRegex.test('1 234.56')) // Output: true
348
+ * console.log(prettyRegex.test('abc')) // Output: false
349
+ */
350
+ pretty: {
351
+ value(locale = 'en-US') {
352
+ const symbols = self.zeroOrMore(self.currencySymbols(['*'], locale));
353
+ return `${symbols}[\\d,]+\\.?[\\d]*`;
354
+ }
355
+ },
356
+ /**
357
+ * Getter method that returns a regular expression string for JavaScript
358
+ * literals.
359
+ *
360
+ * This method returns a regular expression string that matches JavaScript
361
+ * literals. The returned regular expression string is '[\\d_]+', which
362
+ * matches one or more digits or underscores.
363
+ *
364
+ * @returns {string} - A regular expression string that matches JavaScript
365
+ * literals.
366
+ *
367
+ * @example
368
+ * // Using `jsLiteral`
369
+ * const jsLiteralRegex = new RegExp(this.jsLiteral)
370
+ * console.log(jsLiteralRegex.test('123_456')) // Output: true
371
+ * console.log(jsLiteralRegex.test('abc')) // Output: false
372
+ */
373
+ jsLiteral: { get() { return `[\\d_]+`; } }
374
+ });
375
+ return instance;
376
+ },
377
+ /**
378
+ * Getter method that returns a regular expression string for integers.
379
+ *
380
+ * This method returns a regular expression string that matches integer
381
+ * numbers. The returned regular expression string is '\\d+', which matches
382
+ * one or more digits.
383
+ *
384
+ * @returns {string} - A regular expression string that matches integers.
385
+ *
386
+ * @example
387
+ * // Using `integer`
388
+ * const integerRegex = new RegExp(this.integer)
389
+ * console.log(integerRegex.test('123')) // Output: true
390
+ * console.log(integerRegex.test('123.45')) // Output: false
391
+ * console.log(integerRegex.test('abc')) // Output: false
392
+ */
393
+ get integer() {
394
+ return `\\d+`;
395
+ },
396
+ get string() {
397
+ return {
398
+ get doubleQuoted() {
399
+ return '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
400
+ },
401
+ get singleQuoted() {
402
+ return "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'";
403
+ }
404
+ };
405
+ },
406
+ get whitespace() {
407
+ return `\\s*`;
408
+ },
409
+ get comma() {
410
+ return `,${this.whitespace}`;
411
+ },
412
+ }
413
+ }, {
414
+ conditions: {
415
+ ['escape']() { return !Reflect.has(RegExp, 'escape'); },
416
+ }
417
+ });
418
+ // Simple variant that does not require external dependencies; may not cover
419
+ // all known use cases.
420
+ function RegExpEscape(string) {
421
+ return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
422
+ }
423
+ //# sourceMappingURL=regular.expression.extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regular.expression.extensions.js","sourceRoot":"","sources":["../../src/regular.expression.extensions.js"],"names":[],"mappings":";;;AAAA,+CAAuC;AAE1B,QAAA,gBAAgB,GAAG,IAAI,iBAAK,CAAC,MAAM,EAAE;IAChD,CAAC,iBAAK,CAAC,cAAc,CAAC,EAAE;QACtB;;;;;;;;;;;;;;;;;;;;;;;WAuBG;QACH,QAAQ,CAAC,MAAM,GAAG,KAAK,EAAE,eAAe,GAAG,KAAK;YAC9C,OAAO,KAAK,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAA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AA;QACf,CAAC;QAED,IAAI,MAAM;YACR,OAAO;gBACL,IAAI,YAAY;oBACd,OAAO,gCAAgC,CAAA;gBACzC,CAAC;gBAED,IAAI,YAAY;oBACd,OAAO,gCAAgC,CAAA;gBACzC,CAAC;aACF,CAAA;QACH,CAAC;QAED,IAAI,UAAU;YACZ,OAAO,MAAM,CAAA;QACf,CAAC;QAED,IAAI,KAAK;YACP,OAAO,IAAI,IAAI,CAAC,UAAU,EAAE,CAAA;QAC9B,CAAC;KACF;CACF,EAAE;IACD,UAAU,EAAE;QACV,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAE,CAAA,CAAA,CAAC;KACvD;CACF,CAAC,CAAA;AAEF,4EAA4E;AAC5E,uBAAuB;AACvB,SAAS,YAAY,CAAC,MAAM;IAC1B,OAAO,MAAM,CAAC,OAAO,CAAC,qCAAqC,EAAE,MAAM,CAAC,CAAC;AACvE,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * `SetExtensions` is a constant that applies a patch to the global
3
+ * `Set` constructor. This patch extends the `Set` with additional
4
+ * methods and properties, enhancing its functionality.
5
+ *
6
+ * The `Patch` function takes two arguments: the target object to be patched
7
+ * (in this case, `Set`), and an object containing the methods and
8
+ * properties to be added to the target object.
9
+ *
10
+ * @example
11
+ * // Using a method added by SetExtensions
12
+ * const set = new Set();
13
+ * console.log(Set.isSet(set)); // Output: true
14
+ *
15
+ * @const
16
+ * @type {Patch}
17
+ * @memberof module:set.extensions
18
+ */
19
+ export const SetExtensions: Patch;
20
+ /**
21
+ * `SetPrototypeExtensions` is a constant that applies a patch to the
22
+ * prototype of the built-in JavaScript `Set` object. This patch extends the
23
+ * `Set` prototype with additional methods and properties, enhancing its
24
+ * functionality.
25
+ *
26
+ * The `Patch` function takes two arguments: the target object to be patched
27
+ * (in this case, `Set.prototype`), and an object containing the methods and
28
+ * properties to be added to the target object.
29
+ *
30
+ * @example
31
+ * // Using a method added by SetPrototypeExtensions
32
+ * const mySet = new Set();
33
+ * mySet.myNewMethod(); // Calls the new method added by the patch
34
+ *
35
+ * @const
36
+ * @type {Patch}
37
+ * @memberof module:set.extensions
38
+ */
39
+ export const SetPrototypeExtensions: Patch;
40
+ import { Patch } from '@nejs/extension';
@@ -1,7 +1,95 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SetPrototypeExtensions = void 0;
3
+ exports.SetPrototypeExtensions = exports.SetExtensions = void 0;
4
4
  const extension_1 = require("@nejs/extension");
5
+ /**
6
+ * `SetExtensions` is a constant that applies a patch to the global
7
+ * `Set` constructor. This patch extends the `Set` with additional
8
+ * methods and properties, enhancing its functionality.
9
+ *
10
+ * The `Patch` function takes two arguments: the target object to be patched
11
+ * (in this case, `Set`), and an object containing the methods and
12
+ * properties to be added to the target object.
13
+ *
14
+ * @example
15
+ * // Using a method added by SetExtensions
16
+ * const set = new Set();
17
+ * console.log(Set.isSet(set)); // Output: true
18
+ *
19
+ * @const
20
+ * @type {Patch}
21
+ * @memberof module:set.extensions
22
+ */
23
+ exports.SetExtensions = new extension_1.Patch(Set, {
24
+ [extension_1.Patch.kMutablyHidden]: {
25
+ /**
26
+ * Determines if the supplied `value` is a `Set` object. This check
27
+ * is performed by first looking for the `Symbol.toStringTag` on the
28
+ * `value` and checking to see if it is equal to the string "Set".
29
+ * If that check fails, `instanceof` is used as a fallback to check
30
+ * the prototype chain.
31
+ *
32
+ * @param {any} value the value that needs to be checked to determine
33
+ * if it is a `Set` object or not
34
+ * @returns {boolean} `true` if the supplied `value` is a `Set`
35
+ * object, `false` otherwise
36
+ *
37
+ * @example
38
+ * const set = new Set()
39
+ * isSet(set) // true
40
+ * isSet(new Map()) // false
41
+ * isSet([]) // false
42
+ * isSet({}) // false
43
+ */
44
+ isSet(value) {
45
+ return value?.[Symbol.toStringTag] === Set.name || value instanceof Set;
46
+ },
47
+ /**
48
+ * Conditionally returns a value based on whether the supplied
49
+ * `value` is a `Set` object or not. If the `value` is a `Set`
50
+ * object, the `thenValue` will be returned. If it is not a `Set`
51
+ * object, the `elseValue` will be returned instead.
52
+ *
53
+ * @param {any} value the value to check to determine if it is a
54
+ * `Set` object
55
+ * @param {any} thenValue the value to return if the supplied
56
+ * `value` is a `Set` object
57
+ * @param {any} elseValue the value to return if the supplied
58
+ * `value` is not a `Set` object
59
+ * @returns {any} either the `thenValue` or `elseValue` depending
60
+ * on if the supplied `value` is a `Set` object
61
+ *
62
+ * @example
63
+ * const set = new Set()
64
+ * const map = new Map()
65
+ * ifSet(set, 'is a set', 'not a set') // 'is a set'
66
+ * ifSet(map, 'is a set', 'not a set') // 'not a set'
67
+ */
68
+ ifSet(value, thenValue, elseValue) {
69
+ return isThenElse(this.isSet(value), thenValue, elseValue);
70
+ },
71
+ }
72
+ });
73
+ const { isSet: pIsSet } = exports.SetExtensions.patches;
74
+ /**
75
+ * `SetPrototypeExtensions` is a constant that applies a patch to the
76
+ * prototype of the built-in JavaScript `Set` object. This patch extends the
77
+ * `Set` prototype with additional methods and properties, enhancing its
78
+ * functionality.
79
+ *
80
+ * The `Patch` function takes two arguments: the target object to be patched
81
+ * (in this case, `Set.prototype`), and an object containing the methods and
82
+ * properties to be added to the target object.
83
+ *
84
+ * @example
85
+ * // Using a method added by SetPrototypeExtensions
86
+ * const mySet = new Set();
87
+ * mySet.myNewMethod(); // Calls the new method added by the patch
88
+ *
89
+ * @const
90
+ * @type {Patch}
91
+ * @memberof module:set.extensions
92
+ */
5
93
  exports.SetPrototypeExtensions = new extension_1.Patch(Set.prototype, {
6
94
  [extension_1.Patch.kMutablyHidden]: {
7
95
  /**
@@ -120,6 +208,52 @@ exports.SetPrototypeExtensions = new extension_1.Patch(Set.prototype, {
120
208
  }
121
209
  return undefined;
122
210
  },
211
+ /**
212
+ * Determines if the current object is a `Set` object.
213
+ *
214
+ * This is a getter that uses the `isSet` function from the
215
+ * `SetExtensions` patch to check if the current object (`this`) is
216
+ * a `Set` object.
217
+ *
218
+ * @type {boolean}
219
+ * @readonly
220
+ *
221
+ * @example
222
+ * const set = new Set()
223
+ * console.log(set.isSet) // Output: true
224
+ *
225
+ * const notSet = {}
226
+ * console.log(notSet.isSet) // Output: false
227
+ */
228
+ get isSet() {
229
+ return pIsSet(this);
230
+ },
231
+ /**
232
+ * Checks if the current object is a Set and returns the
233
+ * corresponding value based on the result.
234
+ *
235
+ * This method uses the `isThenElse` function from the
236
+ * `SetExtensions` patch to determine if the current object
237
+ * (`this`) is a Set. If it is a Set, the `thenValue` is returned.
238
+ * Otherwise, the `elseValue` is returned.
239
+ *
240
+ * @param {any} thenValue - The value to return if the current object
241
+ * is a Set.
242
+ * @param {any} elseValue - The value to return if the current object
243
+ * is not a Set.
244
+ * @returns {any} The `thenValue` if the current object is a Set, or
245
+ * the `elseValue` if it is not a Set.
246
+ *
247
+ * @example
248
+ * const set = new Set([1, 2, 3])
249
+ * console.log(set.ifSet('Is a Set', 'Not a Set')) // 'Is a Set'
250
+ *
251
+ * const notSet = {}
252
+ * console.log(notSet.ifSet('Is a Set', 'Not a Set')) // 'Not a Set'
253
+ */
254
+ ifSet(thenValue, elseValue) {
255
+ return isThenElse(pIsSet(this), thenValue, elseValue);
256
+ },
123
257
  /**
124
258
  * A getter property that returns the number of elements in the set.
125
259
  * This is an alias for the `size` property of the set.
@@ -203,4 +337,18 @@ exports.SetPrototypeExtensions = new extension_1.Patch(Set.prototype, {
203
337
  },
204
338
  },
205
339
  });
206
- //# sourceMappingURL=setextensions.js.map
340
+ // NOTE to self; this is repeated here otherwise a circular reference from
341
+ // Object<->Function<->Global occurs. See original source in global.this.js
342
+ // {@see globalThis.isThenElse}
343
+ function isThenElse(bv, tv, ev) {
344
+ if (arguments.length > 1) {
345
+ var _then = isFunction(tv) ? tv(bv) : tv;
346
+ if (arguments.length > 2) {
347
+ var _else = isFunction(ev) ? tv(bv) : ev;
348
+ return bv ? _then : _else;
349
+ }
350
+ return bv || _then;
351
+ }
352
+ return bv;
353
+ }
354
+ //# sourceMappingURL=set.extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.extensions.js","sourceRoot":"","sources":["../../src/set.extensions.js"],"names":[],"mappings":";;;AAAA,+CAAwC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,aAAa,GAAG,IAAI,iBAAK,CAAC,GAAG,EAAE;IAC1C,CAAC,iBAAK,CAAC,cAAc,CAAC,EAAE;QACtB;;;;;;;;;;;;;;;;;;WAkBG;QACH,KAAK,CAAC,KAAK;YACT,OAAO,KAAK,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,KAAK,YAAY,GAAG,CAAA;QACzE,CAAC;QAED;;;;;;;;;;;;;;;;;;;;WAoBG;QACH,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS;YAC/B,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAC5D,CAAC;KACF;CACF,CAAC,CAAA;AAEF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,qBAAa,CAAC,OAAO,CAAA;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACU,QAAA,sBAAsB,GAAG,IAAI,iBAAK,CAAC,GAAG,CAAC,SAAS,EAAE;IAC7D,CAAC,iBAAK,CAAC,cAAc,CAAC,EAAE;QACtB;;;;;;;WAOG;QACH,MAAM,CAAC,GAAG,SAAS;YACjB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,IACE,OAAO,QAAQ,KAAK,QAAQ;oBAC5B,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,EACvC,CAAC;oBACD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;oBAClB,SAAQ;gBACV,CAAC;gBAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EA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