@nejs/basic-extensions 2.21.0 → 2.22.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/.idea/markdown.xml +8 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/ne-basic-extensions.iml +8 -0
  4. package/.idea/vcs.xml +6 -0
  5. package/CODE_STYLE.md +393 -0
  6. package/CODING_PHILOSOPHY.md +36 -0
  7. package/DOCUMENTATION_GUIDELINES.md +221 -0
  8. package/README.md +78 -4
  9. package/dist/@nejs/basic-extensions.bundle.2.22.6.js +25 -0
  10. package/dist/@nejs/basic-extensions.bundle.2.22.6.js.map +7 -0
  11. package/dist/cjs/classes/index.cjs +11129 -0
  12. package/dist/cjs/classes/index.cjs.map +7 -0
  13. package/dist/cjs/index.cjs +15191 -0
  14. package/dist/cjs/index.cjs.map +7 -0
  15. package/dist/cjs/utils/index.cjs +3954 -0
  16. package/dist/cjs/utils/index.cjs.map +7 -0
  17. package/dist/esm/basic-extensions.mjs +25 -0
  18. package/dist/esm/basic-extensions.mjs.map +7 -0
  19. package/package.json +16 -22
  20. package/repl.bootstrap.js +4 -7
  21. package/repl.history +30 -30
  22. package/src/big.int.extension.js +171 -45
  23. package/src/classes/enumeration.js +466 -0
  24. package/src/classes/index.js +5 -1
  25. package/src/index.js +5 -1
  26. package/src/math.extension.js +73 -0
  27. package/src/number.extension.js +18 -0
  28. package/src/regular.expression.extensions.js +0 -35
  29. package/src/utils/toolkit.js +699 -516
  30. package/tests/arrayextensions.test.js +3 -3
  31. package/tests/index.test.js +3 -1
  32. package/tests/newClasses/asyncIterable.test.js +3 -3
  33. package/tests/newClasses/deferred.test.js +3 -3
  34. package/tests/newClasses/descriptor.test.js +3 -3
  35. package/tests/newClasses/iterable.test.js +3 -3
  36. package/tests/newClasses/refmap.test.js +3 -3
  37. package/tests/newClasses/refset.test.js +3 -3
  38. package/tests/objectextensions.test.js +3 -3
  39. package/tests/setextensions.test.js +3 -3
  40. package/tests/stringextensions.test.js +3 -2
  41. package/tests/utils/descriptor.utils.test.js +1 -1
  42. package/tests/utils/toolkit.test.js +429 -163
  43. package/.esdoc.json +0 -9
  44. package/.vscode/settings.json +0 -5
  45. package/bin/build +0 -27
  46. package/bin/clean +0 -14
  47. package/bin/esbuild +0 -91
  48. package/bin/fixup +0 -13
  49. package/bin/repl.basics.js +0 -584
  50. package/bin/repl.signature.js +0 -63
  51. package/bin/version +0 -100
  52. package/dist/@nejs/basic-extensions.bundle.2.21.0.js +0 -25
  53. package/dist/@nejs/basic-extensions.bundle.2.21.0.js.map +0 -7
  54. package/dist/cjs/array.extensions.d.ts +0 -39
  55. package/dist/cjs/array.extensions.js +0 -477
  56. package/dist/cjs/array.extensions.js.map +0 -1
  57. package/dist/cjs/big.int.extension.d.ts +0 -31
  58. package/dist/cjs/big.int.extension.js +0 -165
  59. package/dist/cjs/big.int.extension.js.map +0 -1
  60. package/dist/cjs/classes/asyncIterable.d.ts +0 -126
  61. package/dist/cjs/classes/asyncIterable.js +0 -209
  62. package/dist/cjs/classes/asyncIterable.js.map +0 -1
  63. package/dist/cjs/classes/deferred.d.ts +0 -146
  64. package/dist/cjs/classes/deferred.js +0 -291
  65. package/dist/cjs/classes/deferred.js.map +0 -1
  66. package/dist/cjs/classes/descriptor.d.ts +0 -334
  67. package/dist/cjs/classes/descriptor.js +0 -537
  68. package/dist/cjs/classes/descriptor.js.map +0 -1
  69. package/dist/cjs/classes/enum.d.ts +0 -50
  70. package/dist/cjs/classes/enum.js +0 -405
  71. package/dist/cjs/classes/enum.js.map +0 -1
  72. package/dist/cjs/classes/index.d.ts +0 -15
  73. package/dist/cjs/classes/index.js +0 -63
  74. package/dist/cjs/classes/index.js.map +0 -1
  75. package/dist/cjs/classes/introspector.d.ts +0 -20
  76. package/dist/cjs/classes/introspector.js +0 -130
  77. package/dist/cjs/classes/introspector.js.map +0 -1
  78. package/dist/cjs/classes/iterable.d.ts +0 -169
  79. package/dist/cjs/classes/iterable.js +0 -268
  80. package/dist/cjs/classes/iterable.js.map +0 -1
  81. package/dist/cjs/classes/param.parser.d.ts +0 -221
  82. package/dist/cjs/classes/param.parser.js +0 -242
  83. package/dist/cjs/classes/param.parser.js.map +0 -1
  84. package/dist/cjs/classes/pluggable.proxy.d.ts +0 -153
  85. package/dist/cjs/classes/pluggable.proxy.js +0 -444
  86. package/dist/cjs/classes/pluggable.proxy.js.map +0 -1
  87. package/dist/cjs/classes/property.d.ts +0 -79
  88. package/dist/cjs/classes/property.js +0 -284
  89. package/dist/cjs/classes/property.js.map +0 -1
  90. package/dist/cjs/classes/refmap.d.ts +0 -238
  91. package/dist/cjs/classes/refmap.js +0 -421
  92. package/dist/cjs/classes/refmap.js.map +0 -1
  93. package/dist/cjs/classes/refset.d.ts +0 -186
  94. package/dist/cjs/classes/refset.js +0 -370
  95. package/dist/cjs/classes/refset.js.map +0 -1
  96. package/dist/cjs/classes/symkeys.d.ts +0 -349
  97. package/dist/cjs/classes/symkeys.js +0 -510
  98. package/dist/cjs/classes/symkeys.js.map +0 -1
  99. package/dist/cjs/classes/type.d.ts +0 -56
  100. package/dist/cjs/classes/type.js +0 -405
  101. package/dist/cjs/classes/type.js.map +0 -1
  102. package/dist/cjs/function.extensions.d.ts +0 -12
  103. package/dist/cjs/function.extensions.js +0 -758
  104. package/dist/cjs/function.extensions.js.map +0 -1
  105. package/dist/cjs/global.this.d.ts +0 -2
  106. package/dist/cjs/global.this.js +0 -300
  107. package/dist/cjs/global.this.js.map +0 -1
  108. package/dist/cjs/index.d.ts +0 -31
  109. package/dist/cjs/index.js +0 -226
  110. package/dist/cjs/index.js.map +0 -1
  111. package/dist/cjs/json.extensions.d.ts +0 -2
  112. package/dist/cjs/json.extensions.js +0 -109
  113. package/dist/cjs/json.extensions.js.map +0 -1
  114. package/dist/cjs/map.extensions.d.ts +0 -3
  115. package/dist/cjs/map.extensions.js +0 -143
  116. package/dist/cjs/map.extensions.js.map +0 -1
  117. package/dist/cjs/number.extension.d.ts +0 -44
  118. package/dist/cjs/number.extension.js +0 -261
  119. package/dist/cjs/number.extension.js.map +0 -1
  120. package/dist/cjs/object.extensions.d.ts +0 -33
  121. package/dist/cjs/object.extensions.js +0 -1091
  122. package/dist/cjs/object.extensions.js.map +0 -1
  123. package/dist/cjs/package.json +0 -3
  124. package/dist/cjs/proxy.extensions.d.ts +0 -2
  125. package/dist/cjs/proxy.extensions.js +0 -207
  126. package/dist/cjs/proxy.extensions.js.map +0 -1
  127. package/dist/cjs/reflect.extensions.d.ts +0 -14
  128. package/dist/cjs/reflect.extensions.js +0 -316
  129. package/dist/cjs/reflect.extensions.js.map +0 -1
  130. package/dist/cjs/regular.expression.extensions.d.ts +0 -2
  131. package/dist/cjs/regular.expression.extensions.js +0 -423
  132. package/dist/cjs/regular.expression.extensions.js.map +0 -1
  133. package/dist/cjs/set.extensions.d.ts +0 -40
  134. package/dist/cjs/set.extensions.js +0 -355
  135. package/dist/cjs/set.extensions.js.map +0 -1
  136. package/dist/cjs/string.extensions.d.ts +0 -23
  137. package/dist/cjs/string.extensions.js +0 -704
  138. package/dist/cjs/string.extensions.js.map +0 -1
  139. package/dist/cjs/symbol.extensions.d.ts +0 -11
  140. package/dist/cjs/symbol.extensions.js +0 -735
  141. package/dist/cjs/symbol.extensions.js.map +0 -1
  142. package/dist/cjs/utils/copy.object.d.ts +0 -408
  143. package/dist/cjs/utils/copy.object.js +0 -720
  144. package/dist/cjs/utils/copy.object.js.map +0 -1
  145. package/dist/cjs/utils/descriptor.utils.d.ts +0 -298
  146. package/dist/cjs/utils/descriptor.utils.js +0 -889
  147. package/dist/cjs/utils/descriptor.utils.js.map +0 -1
  148. package/dist/cjs/utils/index.d.ts +0 -75
  149. package/dist/cjs/utils/index.js +0 -61
  150. package/dist/cjs/utils/index.js.map +0 -1
  151. package/dist/cjs/utils/stdout.d.ts +0 -742
  152. package/dist/cjs/utils/stdout.js +0 -1042
  153. package/dist/cjs/utils/stdout.js.map +0 -1
  154. package/dist/cjs/utils/toolkit.d.ts +0 -1898
  155. package/dist/cjs/utils/toolkit.js +0 -1378
  156. package/dist/cjs/utils/toolkit.js.map +0 -1
  157. package/dist/cjs/weakref.extensions.d.ts +0 -2
  158. package/dist/cjs/weakref.extensions.js +0 -19
  159. package/dist/cjs/weakref.extensions.js.map +0 -1
  160. package/dist/mjs/array.extensions.d.ts +0 -39
  161. package/dist/mjs/array.extensions.js +0 -474
  162. package/dist/mjs/array.extensions.js.map +0 -1
  163. package/dist/mjs/big.int.extension.d.ts +0 -31
  164. package/dist/mjs/big.int.extension.js +0 -162
  165. package/dist/mjs/big.int.extension.js.map +0 -1
  166. package/dist/mjs/classes/asyncIterable.d.ts +0 -126
  167. package/dist/mjs/classes/asyncIterable.js +0 -204
  168. package/dist/mjs/classes/asyncIterable.js.map +0 -1
  169. package/dist/mjs/classes/deferred.d.ts +0 -146
  170. package/dist/mjs/classes/deferred.js +0 -287
  171. package/dist/mjs/classes/deferred.js.map +0 -1
  172. package/dist/mjs/classes/descriptor.d.ts +0 -334
  173. package/dist/mjs/classes/descriptor.js +0 -533
  174. package/dist/mjs/classes/descriptor.js.map +0 -1
  175. package/dist/mjs/classes/enum.d.ts +0 -50
  176. package/dist/mjs/classes/enum.js +0 -400
  177. package/dist/mjs/classes/enum.js.map +0 -1
  178. package/dist/mjs/classes/index.d.ts +0 -15
  179. package/dist/mjs/classes/index.js +0 -46
  180. package/dist/mjs/classes/index.js.map +0 -1
  181. package/dist/mjs/classes/introspector.d.ts +0 -20
  182. package/dist/mjs/classes/introspector.js +0 -126
  183. package/dist/mjs/classes/introspector.js.map +0 -1
  184. package/dist/mjs/classes/iterable.d.ts +0 -169
  185. package/dist/mjs/classes/iterable.js +0 -263
  186. package/dist/mjs/classes/iterable.js.map +0 -1
  187. package/dist/mjs/classes/param.parser.d.ts +0 -221
  188. package/dist/mjs/classes/param.parser.js +0 -238
  189. package/dist/mjs/classes/param.parser.js.map +0 -1
  190. package/dist/mjs/classes/pluggable.proxy.d.ts +0 -153
  191. package/dist/mjs/classes/pluggable.proxy.js +0 -438
  192. package/dist/mjs/classes/pluggable.proxy.js.map +0 -1
  193. package/dist/mjs/classes/property.d.ts +0 -79
  194. package/dist/mjs/classes/property.js +0 -280
  195. package/dist/mjs/classes/property.js.map +0 -1
  196. package/dist/mjs/classes/refmap.d.ts +0 -238
  197. package/dist/mjs/classes/refmap.js +0 -417
  198. package/dist/mjs/classes/refmap.js.map +0 -1
  199. package/dist/mjs/classes/refset.d.ts +0 -186
  200. package/dist/mjs/classes/refset.js +0 -366
  201. package/dist/mjs/classes/refset.js.map +0 -1
  202. package/dist/mjs/classes/symkeys.d.ts +0 -349
  203. package/dist/mjs/classes/symkeys.js +0 -506
  204. package/dist/mjs/classes/symkeys.js.map +0 -1
  205. package/dist/mjs/classes/type.d.ts +0 -56
  206. package/dist/mjs/classes/type.js +0 -401
  207. package/dist/mjs/classes/type.js.map +0 -1
  208. package/dist/mjs/function.extensions.d.ts +0 -12
  209. package/dist/mjs/function.extensions.js +0 -755
  210. package/dist/mjs/function.extensions.js.map +0 -1
  211. package/dist/mjs/global.this.d.ts +0 -2
  212. package/dist/mjs/global.this.js +0 -264
  213. package/dist/mjs/global.this.js.map +0 -1
  214. package/dist/mjs/index.d.ts +0 -31
  215. package/dist/mjs/index.js +0 -204
  216. package/dist/mjs/index.js.map +0 -1
  217. package/dist/mjs/json.extensions.d.ts +0 -2
  218. package/dist/mjs/json.extensions.js +0 -106
  219. package/dist/mjs/json.extensions.js.map +0 -1
  220. package/dist/mjs/map.extensions.d.ts +0 -3
  221. package/dist/mjs/map.extensions.js +0 -140
  222. package/dist/mjs/map.extensions.js.map +0 -1
  223. package/dist/mjs/number.extension.d.ts +0 -44
  224. package/dist/mjs/number.extension.js +0 -258
  225. package/dist/mjs/number.extension.js.map +0 -1
  226. package/dist/mjs/object.extensions.d.ts +0 -33
  227. package/dist/mjs/object.extensions.js +0 -1088
  228. package/dist/mjs/object.extensions.js.map +0 -1
  229. package/dist/mjs/package.json +0 -3
  230. package/dist/mjs/proxy.extensions.d.ts +0 -2
  231. package/dist/mjs/proxy.extensions.js +0 -204
  232. package/dist/mjs/proxy.extensions.js.map +0 -1
  233. package/dist/mjs/reflect.extensions.d.ts +0 -14
  234. package/dist/mjs/reflect.extensions.js +0 -313
  235. package/dist/mjs/reflect.extensions.js.map +0 -1
  236. package/dist/mjs/regular.expression.extensions.d.ts +0 -2
  237. package/dist/mjs/regular.expression.extensions.js +0 -420
  238. package/dist/mjs/regular.expression.extensions.js.map +0 -1
  239. package/dist/mjs/set.extensions.d.ts +0 -40
  240. package/dist/mjs/set.extensions.js +0 -352
  241. package/dist/mjs/set.extensions.js.map +0 -1
  242. package/dist/mjs/string.extensions.d.ts +0 -23
  243. package/dist/mjs/string.extensions.js +0 -701
  244. package/dist/mjs/string.extensions.js.map +0 -1
  245. package/dist/mjs/symbol.extensions.d.ts +0 -11
  246. package/dist/mjs/symbol.extensions.js +0 -732
  247. package/dist/mjs/symbol.extensions.js.map +0 -1
  248. package/dist/mjs/utils/copy.object.d.ts +0 -408
  249. package/dist/mjs/utils/copy.object.js +0 -702
  250. package/dist/mjs/utils/copy.object.js.map +0 -1
  251. package/dist/mjs/utils/descriptor.utils.d.ts +0 -298
  252. package/dist/mjs/utils/descriptor.utils.js +0 -875
  253. package/dist/mjs/utils/descriptor.utils.js.map +0 -1
  254. package/dist/mjs/utils/index.d.ts +0 -75
  255. package/dist/mjs/utils/index.js +0 -45
  256. package/dist/mjs/utils/index.js.map +0 -1
  257. package/dist/mjs/utils/stdout.d.ts +0 -742
  258. package/dist/mjs/utils/stdout.js +0 -1037
  259. package/dist/mjs/utils/stdout.js.map +0 -1
  260. package/dist/mjs/utils/toolkit.d.ts +0 -1898
  261. package/dist/mjs/utils/toolkit.js +0 -1373
  262. package/dist/mjs/utils/toolkit.js.map +0 -1
  263. package/dist/mjs/weakref.extensions.d.ts +0 -2
  264. package/dist/mjs/weakref.extensions.js +0 -16
  265. package/dist/mjs/weakref.extensions.js.map +0 -1
  266. package/jsdoc-config.json +0 -31
  267. package/tsconfig.base.json +0 -28
  268. package/tsconfig.cjs.json +0 -8
  269. package/tsconfig.esm.json +0 -8
  270. package/vitest.config.js +0 -7
@@ -1,420 +0,0 @@
1
- import { Patch } from '@nejs/extension';
2
- export const RegExpExtensions = new Patch(RegExp, {
3
- [Patch.kMutablyHidden]: {
4
- /**
5
- * Generates a regular expression pattern that matches any character.
6
- *
7
- * This method creates a regular expression pattern that matches any
8
- * character. The pattern can be configured to be greedy or non-greedy,
9
- * and to include or exclude newline characters.
10
- *
11
- * @param {boolean} [greedy=false] - If true, the pattern will be greedy,
12
- * meaning it will match as many characters as possible. If false, the
13
- * pattern will be non-greedy, meaning it will match as few characters
14
- * as possible.
15
- * @param {boolean} [includeNewlines=false] - If true, the pattern will
16
- * include newline characters ('\n' and '\r'). If false, newline
17
- * characters will be excluded from the pattern.
18
- * @returns {string} - The generated regular expression pattern.
19
- *
20
- * @example
21
- * // Generate a non-greedy pattern that excludes newlines
22
- * console.log(anything()) // Output: '[.]*?'
23
- *
24
- * @example
25
- * // Generate a greedy pattern that includes newlines
26
- * console.log(anything(true, true)) // Output: '[.\\n\\r]*'
27
- */
28
- anything(greedy = false, includeNewlines = false) {
29
- return `[.${includeNewlines ? '\\n\\r' : ''}]*${greedy ? '' : '?'}`;
30
- },
31
- /**
32
- * Creates a non-capturing group in a regular expression.
33
- *
34
- * This method wraps the provided string in a non-capturing group,
35
- * which is denoted by the syntax `(?:...)` in a regular expression.
36
- * Non-capturing groups match the pattern inside the group but do not
37
- * capture the matched content for later use.
38
- *
39
- * @param {string} string - The string to be wrapped in a non-capturing group.
40
- * @returns {string} - The string wrapped in a non-capturing group.
41
- *
42
- * @example
43
- * // Suppose we have a string 'abc'
44
- * const str = 'abc'
45
- *
46
- * // Using `nonCaptureGroup`
47
- * console.log(nonCaptureGroup(str)) // Output: '(?:abc)'
48
- */
49
- nonCaptureGroup(string) {
50
- return `(?:${string})`;
51
- },
52
- /**
53
- * Creates a capturing group in a regular expression.
54
- *
55
- * This method wraps the provided string in a capturing group,
56
- * which is denoted by the syntax `(...)` in a regular expression.
57
- * Capturing groups match the pattern inside the group and capture
58
- * the matched content for later use.
59
- *
60
- * @param {string} string - The string to be wrapped in a capturing group.
61
- * @returns {string} - The string wrapped in a capturing group.
62
- *
63
- * @example
64
- * // Suppose we have a string 'abc'
65
- * const str = 'abc'
66
- *
67
- * // Using `captureGroup`
68
- * console.log(captureGroup(str)) // Output: '(abc)'
69
- */
70
- captureGroup(string) {
71
- return `(${string})`;
72
- },
73
- /**
74
- * Creates a regular expression pattern that matches any one of the
75
- * provided strings.
76
- *
77
- * This method takes any number of strings as arguments, and returns a
78
- * string that represents a regular expression pattern. The pattern
79
- * matches any one of the provided strings. The strings are joined
80
- * together with the '|' character, which represents the OR operator
81
- * in regular expressions.
82
- *
83
- * @param {...string} strings - The strings to be included in the pattern.
84
- * @returns {string} - A string representing a regular expression pattern
85
- * that matches any one of the provided strings.
86
- *
87
- * @example
88
- * // Suppose we have strings 'abc', 'def', and 'ghi'
89
- * const str1 = 'abc'
90
- * const str2 = 'def'
91
- * const str3 = 'ghi'
92
- *
93
- * // Using `oneOf`
94
- * console.log(oneOf(str1, str2, str3)) // Output: 'abc|def|ghi'
95
- */
96
- oneOf(...strings) {
97
- return strings.join('|');
98
- },
99
- /**
100
- * Creates a regular expression pattern that matches zero or more
101
- * occurrences of the provided string.
102
- *
103
- * This method wraps the provided string in a non-capturing group,
104
- * which is denoted by the syntax `(?:...)` in a regular expression,
105
- * and appends the `*` character, which represents zero or more
106
- * occurrences in regular expressions.
107
- *
108
- * @param {string} string - The string to be matched zero or more times.
109
- * @returns {string} - A string representing a regular expression pattern
110
- * that matches zero or more occurrences of the provided string.
111
- *
112
- * @example
113
- * // Suppose we have a string 'abc'
114
- * const str = 'abc'
115
- *
116
- * // Using `zeroOrMore`
117
- * console.log(zeroOrMore(str)) // Output: '(?:abc)*'
118
- */
119
- zeroOrMore(string) {
120
- return `(?:${string})*`;
121
- },
122
- /**
123
- * Creates a regular expression pattern that matches zero or one
124
- * occurrence of the provided string.
125
- *
126
- * This method wraps the provided string in a non-capturing group,
127
- * which is denoted by the syntax `(?:...)` in a regular expression,
128
- * and appends the `?` character, which represents zero or one
129
- * occurrence in regular expressions.
130
- *
131
- * @param {string} string - The string to be matched zero or one time.
132
- * @returns {string} - A string representing a regular expression pattern
133
- * that matches zero or one occurrence of the provided string.
134
- *
135
- * @example
136
- * // Suppose we have a string 'abc'
137
- * const str = 'abc'
138
- *
139
- * // Using `zeroOrOne`
140
- * console.log(zeroOrOne(str)) // Output: '(?:abc)?'
141
- */
142
- zeroOrOne(string) {
143
- return `(?:${string})?`;
144
- },
145
- /**
146
- * Escapes special characters in a string for use in a regular expression.
147
- *
148
- * This method checks if the `RegExp.escape` method is available. If it is,
149
- * it uses that method to escape the string. If it's not, it uses a polyfill
150
- * method to escape the string.
151
- *
152
- * The polyfill method replaces all special characters in the string with
153
- * their escaped equivalents. The special characters are defined by the
154
- * regular expression `/[-[\]{}()*+?.,\\^$|#\s]/g`.
155
- *
156
- * @param {string} string - The string to be escaped.
157
- * @returns {string} - The escaped string.
158
- *
159
- * @example
160
- * // Suppose we have a string with special characters
161
- * const str = 'Hello, [World]!'
162
- *
163
- * // Using `escape` or `escapePolyfill`
164
- * console.log(RegExp[RegExp.escape ? 'escapePolyfill' : 'escape'](str))
165
- * // Output: 'Hello\\, \\[World\\]\\!'
166
- */
167
- escape(string) {
168
- return RegExpEscape(string);
169
- },
170
- /**
171
- * Getter method that returns a string 'null'.
172
- *
173
- * This method is used when you need a string representation of null
174
- * in your regular expressions. It simply returns the string 'null'.
175
- *
176
- * @returns {string} - A string 'null'.
177
- *
178
- * @example
179
- * // Using `null`
180
- * console.log(this.null) // Output: 'null'
181
- */
182
- get null() {
183
- return 'null';
184
- },
185
- /**
186
- * Getter method that returns a regular expression string for boolean
187
- * values.
188
- *
189
- * This method uses the `oneOf` method to create a regular expression
190
- * string that matches either 'true' or 'false'. This is useful when you
191
- * need to match boolean values in a string using a regular expression.
192
- *
193
- * @returns {string} - A regular expression string that matches 'true'
194
- * or 'false'.
195
- *
196
- * @example
197
- * // Using `bool`
198
- * const boolRegex = new RegExp(this.bool)
199
- * console.log(boolRegex.test('true')) // Output: true
200
- * console.log(boolRegex.test('false')) // Output: true
201
- * console.log(boolRegex.test('maybe')) // Output: false
202
- */
203
- get bool() {
204
- return this.oneOf('true', 'false');
205
- },
206
- /**
207
- * Generates a regular expression string that matches the symbols of
208
- * specified currencies.
209
- *
210
- * This method uses the Intl API to get the symbols of the specified
211
- * currencies and constructs a regular expression string that matches
212
- * these symbols. If no specific currencies are provided, it defaults
213
- * to all known currencies. If a single currency is provided as a
214
- * string, it is converted to an array. If the symbols array is empty
215
- * after filtering out unknown currencies, it defaults back to all
216
- * known currencies.
217
- *
218
- * @param {Array|string} [symbols=[['*'], ['USD','GBP']][0]] - The
219
- * currencies to include in the regular expression. Can be an array
220
- * of currency codes or a single currency code as a string. Defaults
221
- * to all known currencies.
222
- * @param {string} [locale='en-US'] - The locale to use when getting
223
- * the currency symbols. Defaults to 'en-US'.
224
- * @returns {string} - A regular expression string that matches the
225
- * symbols of the specified currencies.
226
- *
227
- * @example
228
- * // Using `currencySymbols` with default parameters
229
- * console.log(this.currencySymbols())
230
- * // Output: A regular expression string that matches all known
231
- * // currency symbols
232
- *
233
- * @example
234
- * // Using `currencySymbols` with specific currencies
235
- * console.log(this.currencySymbols(['USD', 'EUR']))
236
- * // Output: A regular expression string that matches the symbols
237
- * // of USD and EUR
238
- */
239
- currencySymbols(symbols = [['*'], ['USD', 'GBP']][0], locale = 'en-US') {
240
- const known = Intl.supportedValuesOf('currency');
241
- const has = code => !!~known.indexOf(code);
242
- if (typeof symbols === 'string' && has(symbols)) {
243
- symbols = [symbols];
244
- }
245
- if (!Array.isArray(symbols)) {
246
- symbols = known;
247
- }
248
- symbols = symbols.filter(symbol => has(symbol));
249
- if (!symbols.length) {
250
- symbols = known;
251
- }
252
- const opts = (currency) => ({ style: 'currency', currency });
253
- const fmt = (place, currency) => Intl.NumberFormat(place, opts(currency));
254
- const codes = (((symbols.length === 1 && symbols[0] === '*') ? known : symbols)
255
- .filter(code => has(code))
256
- .map(currency => {
257
- const symbol = fmt(locale, currency).formatToParts()?.[0].value;
258
- return symbol && `(?:${RegExp.escape(symbol)})`;
259
- })
260
- .join('|'));
261
- return codes;
262
- },
263
- /**
264
- * Getter method that returns a regular expression string for numbers.
265
- *
266
- * This method returns a regular expression string that matches both
267
- * integer and floating point numbers. The returned regular expression
268
- * string is '\\d+\\.?\\d*', which matches one or more digits followed
269
- * by an optional decimal point and zero or more digits.
270
- *
271
- * @returns {string} - A regular expression string that matches numbers.
272
- *
273
- * @example
274
- * // Using `number`
275
- * const numberRegex = new RegExp(this.number)
276
- * console.log(numberRegex.test('123')) // Output: true
277
- * console.log(numberRegex.test('123.45')) // Output: true
278
- * console.log(numberRegex.test('abc')) // Output: false
279
- */
280
- get number() {
281
- const instance = Object(`\\d+\\.?\\d*`);
282
- const self = this;
283
- Object.defineProperties(instance, {
284
- // alias for .float
285
- any: { get() { return String(instance); } },
286
- /**
287
- * Getter method that returns a regular expression string for floating
288
- * point numbers.
289
- *
290
- * This method returns a regular expression string that matches floating
291
- * point numbers. It leverages the 'number' getter method which matches
292
- * both integer and floating point numbers. The returned regular expression
293
- * string is '\\d+\\.?\\d*', which matches one or more digits followed by
294
- * an optional decimal point and zero or more digits.
295
- *
296
- * @returns {string} - A regular expression string that matches floating
297
- * point numbers.
298
- *
299
- * @example
300
- * // Using `float`
301
- * const floatRegex = new RegExp(this.float)
302
- * console.log(floatRegex.test('123.45')) // Output: true
303
- * console.log(floatRegex.test('123')) // Output: false
304
- * console.log(floatRegex.test('abc')) // Output: false
305
- */
306
- float: { get() { return String(instance); } },
307
- // any known locale currency symbol + .float
308
- money: { get() { return `(?:${self.currencySymbols()})?${this.float}`; } },
309
- /**
310
- * Getter method that returns a regular expression string for integers.
311
- *
312
- * This method returns a regular expression string that matches integer
313
- * numbers. The returned regular expression string is '\\d+', which matches
314
- * one or more digits.
315
- *
316
- * @returns {string} - A regular expression string that matches integers.
317
- *
318
- * @example
319
- * // Using `integer`
320
- * const integerRegex = new RegExp(this.integer)
321
- * console.log(integerRegex.test('123')) // Output: true
322
- * console.log(integerRegex.test('123.45')) // Output: false
323
- * console.log(integerRegex.test('abc')) // Output: false
324
- */
325
- integer: { get() { return `\\d+`; } },
326
- /**
327
- * Getter method that returns a regular expression string for pretty
328
- * numbers.
329
- *
330
- * This method returns a regular expression string that matches numbers
331
- * with commas or spaces for thousands separators. The returned regular
332
- * expression string is '[\\d\\$]+\\.?[\\d,\\$]*', which matches one or
333
- * more digits or dollar signs, followed by an optional decimal point,
334
- * and zero or more digits, commas, or dollar signs.
335
- *
336
- * @returns {string} - A regular expression string that matches pretty
337
- * numbers.
338
- *
339
- * @example
340
- * // Using `pretty`
341
- * const prettyRegex = new RegExp(this.pretty)
342
- * console.log(prettyRegex.test('1,234.56')) // Output: true
343
- * console.log(prettyRegex.test('1234.56')) // Output: true
344
- * console.log(prettyRegex.test('1 234.56')) // Output: true
345
- * console.log(prettyRegex.test('abc')) // Output: false
346
- */
347
- pretty: {
348
- value(locale = 'en-US') {
349
- const symbols = self.zeroOrMore(self.currencySymbols(['*'], locale));
350
- return `${symbols}[\\d,]+\\.?[\\d]*`;
351
- }
352
- },
353
- /**
354
- * Getter method that returns a regular expression string for JavaScript
355
- * literals.
356
- *
357
- * This method returns a regular expression string that matches JavaScript
358
- * literals. The returned regular expression string is '[\\d_]+', which
359
- * matches one or more digits or underscores.
360
- *
361
- * @returns {string} - A regular expression string that matches JavaScript
362
- * literals.
363
- *
364
- * @example
365
- * // Using `jsLiteral`
366
- * const jsLiteralRegex = new RegExp(this.jsLiteral)
367
- * console.log(jsLiteralRegex.test('123_456')) // Output: true
368
- * console.log(jsLiteralRegex.test('abc')) // Output: false
369
- */
370
- jsLiteral: { get() { return `[\\d_]+`; } }
371
- });
372
- return instance;
373
- },
374
- /**
375
- * Getter method that returns a regular expression string for integers.
376
- *
377
- * This method returns a regular expression string that matches integer
378
- * numbers. The returned regular expression string is '\\d+', which matches
379
- * one or more digits.
380
- *
381
- * @returns {string} - A regular expression string that matches integers.
382
- *
383
- * @example
384
- * // Using `integer`
385
- * const integerRegex = new RegExp(this.integer)
386
- * console.log(integerRegex.test('123')) // Output: true
387
- * console.log(integerRegex.test('123.45')) // Output: false
388
- * console.log(integerRegex.test('abc')) // Output: false
389
- */
390
- get integer() {
391
- return `\\d+`;
392
- },
393
- get string() {
394
- return {
395
- get doubleQuoted() {
396
- return '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
397
- },
398
- get singleQuoted() {
399
- return "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'";
400
- }
401
- };
402
- },
403
- get whitespace() {
404
- return `\\s*`;
405
- },
406
- get comma() {
407
- return `,${this.whitespace}`;
408
- },
409
- }
410
- }, {
411
- conditions: {
412
- ['escape']() { return !Reflect.has(RegExp, 'escape'); },
413
- }
414
- });
415
- // Simple variant that does not require external dependencies; may not cover
416
- // all known use cases.
417
- function RegExpEscape(string) {
418
- return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
419
- }
420
- //# sourceMappingURL=regular.expression.extensions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"regular.expression.extensions.js","sourceRoot":"","sources":["../../src/regular.expression.extensions.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAEvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE;IAChD,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;QACtB;;;;;;;;;;;;;;;;;;;;;;;WAuBG;QACH,QAAQ,CAAC,MAAM,GAAG,KAAK,EAAE,eAAe,GAAG,KAAK;YAC9C,OAAO,KAAK,e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AC,CAAA;YAEF,OAAO,QAAQ,CAAA;QACjB,CAAC;QAGD;;;;;;;;;;;;;;;WAeG;QACH,IAAI,OAAO;YACT,OAAO,MAAM,CAAA;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"}
@@ -1,40 +0,0 @@
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';