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