@augment-vir/common 29.3.0 → 30.0.1

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 (296) hide show
  1. package/LICENSE-CC0 +121 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +7 -3
  4. package/dist/augments/array/array-map.d.ts +34 -0
  5. package/dist/augments/array/array-map.js +32 -0
  6. package/dist/augments/array/array-to-object.d.ts +53 -0
  7. package/dist/augments/array/array-to-object.js +67 -0
  8. package/dist/augments/array/awaited/awaited-filter.d.ts +36 -0
  9. package/dist/augments/array/awaited/awaited-filter.js +36 -0
  10. package/dist/augments/array/awaited/awaited-for-each.d.ts +31 -0
  11. package/dist/augments/array/awaited/awaited-for-each.js +34 -0
  12. package/dist/augments/array/awaited/awaited-map.d.ts +33 -0
  13. package/dist/augments/array/awaited/awaited-map.js +40 -0
  14. package/dist/augments/array/filter.d.ts +32 -0
  15. package/dist/augments/array/filter.js +74 -0
  16. package/dist/augments/array/remove-duplicates.d.ts +60 -0
  17. package/dist/augments/array/remove-duplicates.js +72 -0
  18. package/dist/augments/array/repeat-array.d.ts +23 -0
  19. package/dist/augments/array/repeat-array.js +25 -0
  20. package/dist/augments/array/shuffle-array.d.ts +9 -0
  21. package/dist/augments/array/shuffle-array.js +17 -0
  22. package/dist/augments/array/string-array.d.ts +9 -0
  23. package/dist/augments/array/string-array.js +11 -0
  24. package/dist/augments/core-exports.d.ts +1 -0
  25. package/dist/augments/core-exports.js +1 -0
  26. package/dist/augments/enum/enum-value-check.d.ts +32 -0
  27. package/dist/augments/enum/enum-value-check.js +34 -0
  28. package/dist/augments/error/combine-errors.d.ts +24 -0
  29. package/dist/augments/error/combine-errors.js +34 -0
  30. package/dist/augments/function/call-asynchronously.d.ts +25 -0
  31. package/dist/augments/function/call-asynchronously.js +26 -0
  32. package/dist/augments/function/call-with-retries.d.ts +24 -0
  33. package/dist/augments/function/call-with-retries.js +50 -0
  34. package/dist/augments/function/debounce.d.ts +89 -0
  35. package/dist/augments/function/debounce.js +112 -0
  36. package/dist/augments/function/execution-duration.d.ts +20 -0
  37. package/dist/augments/function/execution-duration.js +39 -0
  38. package/dist/augments/function/if-truthy.d.ts +28 -0
  39. package/dist/augments/function/if-truthy.js +35 -0
  40. package/dist/{types/augments → augments/function}/wrap-in-try.d.ts +14 -7
  41. package/dist/augments/function/wrap-in-try.js +98 -0
  42. package/dist/augments/json/append-json.d.ts +5 -0
  43. package/dist/augments/json/append-json.js +59 -0
  44. package/dist/augments/json/copy-through-json.d.ts +34 -0
  45. package/dist/augments/json/copy-through-json.js +42 -0
  46. package/dist/augments/json/json-compatible.d.ts +50 -0
  47. package/dist/augments/json/jsonify.d.ts +31 -0
  48. package/dist/augments/json/jsonify.js +33 -0
  49. package/dist/augments/log/log-colors.d.ts +64 -0
  50. package/dist/augments/log/log-colors.js +157 -0
  51. package/dist/augments/log/log-string.d.ts +35 -0
  52. package/dist/augments/log/log-string.js +73 -0
  53. package/dist/augments/log/log-writer.d.ts +30 -0
  54. package/dist/augments/log/log.d.ts +56 -0
  55. package/dist/augments/log/log.js +85 -0
  56. package/dist/augments/log/logger.d.ts +60 -0
  57. package/dist/augments/log/logger.js +59 -0
  58. package/dist/augments/number/clamp.d.ts +18 -0
  59. package/dist/augments/number/clamp.js +19 -0
  60. package/dist/augments/number/coords.d.ts +23 -0
  61. package/dist/augments/number/digit.d.ts +8 -0
  62. package/dist/augments/number/dimensions.d.ts +23 -0
  63. package/dist/augments/number/min-max.d.ts +18 -0
  64. package/dist/augments/number/min-max.js +16 -0
  65. package/dist/augments/number/number-conversion.d.ts +29 -0
  66. package/dist/augments/number/number-conversion.js +56 -0
  67. package/dist/augments/number/round.d.ts +22 -0
  68. package/dist/augments/number/round.js +24 -0
  69. package/dist/augments/number/scientific.d.ts +18 -0
  70. package/dist/augments/number/scientific.js +20 -0
  71. package/dist/augments/number/truncate-number.d.ts +40 -0
  72. package/dist/{esm/augments → augments/number}/truncate-number.js +39 -17
  73. package/dist/augments/number/wrap-number.d.ts +19 -0
  74. package/dist/augments/number/wrap-number.js +28 -0
  75. package/dist/augments/object/diff.d.ts +51 -0
  76. package/dist/augments/object/diff.js +149 -0
  77. package/dist/augments/object/empty.d.ts +9 -0
  78. package/dist/augments/object/get-or-set.d.ts +10 -0
  79. package/dist/augments/object/get-or-set.js +100 -0
  80. package/dist/augments/object/key-count.d.ts +21 -0
  81. package/dist/augments/object/map-entries.d.ts +13 -0
  82. package/dist/augments/object/map-entries.js +80 -0
  83. package/dist/augments/object/map-enum.d.ts +11 -0
  84. package/dist/augments/object/map-enum.js +45 -0
  85. package/dist/augments/object/map-values.d.ts +35 -0
  86. package/dist/augments/object/map-values.js +65 -0
  87. package/dist/{types/augments → augments}/object/merge-deep.d.ts +4 -0
  88. package/dist/{esm/augments → augments}/object/merge-deep.js +9 -6
  89. package/dist/augments/object/merge-defined-properties.d.ts +19 -0
  90. package/dist/augments/object/merge-defined-properties.js +32 -0
  91. package/dist/augments/object/merge-property-arrays.d.ts +29 -0
  92. package/dist/augments/object/merge-property-arrays.js +39 -0
  93. package/dist/augments/object/object-entries.d.ts +31 -0
  94. package/dist/augments/object/object-entries.js +40 -0
  95. package/dist/augments/object/object-filter.d.ts +22 -0
  96. package/dist/augments/object/object-filter.js +27 -0
  97. package/dist/augments/object/object-keys.d.ts +34 -0
  98. package/dist/augments/object/object-keys.js +43 -0
  99. package/dist/augments/object/object-values.d.ts +11 -0
  100. package/dist/augments/object/object-values.js +13 -0
  101. package/dist/augments/path/esm-path.d.ts +26 -0
  102. package/dist/augments/path/esm-path.js +31 -0
  103. package/dist/augments/prisma/prisma-models.d.ts +143 -0
  104. package/dist/augments/prisma/prisma-models.js +1 -0
  105. package/dist/augments/promise/timed-promise.d.ts +22 -0
  106. package/dist/augments/promise/timed-promise.js +51 -0
  107. package/dist/augments/random/random-boolean.d.ts +24 -0
  108. package/dist/augments/random/random-boolean.js +32 -0
  109. package/dist/augments/random/random-integer.d.ts +14 -0
  110. package/dist/augments/random/random-integer.js +34 -0
  111. package/dist/augments/random/random-string.d.ts +18 -0
  112. package/dist/augments/random/random-string.js +67 -0
  113. package/dist/augments/regexp/match.d.ts +10 -0
  114. package/dist/augments/regexp/match.js +13 -0
  115. package/dist/augments/regexp/regexp-flags.d.ts +56 -0
  116. package/dist/augments/regexp/regexp-flags.js +75 -0
  117. package/dist/augments/regexp/regexp-string.d.ts +9 -0
  118. package/dist/augments/regexp/regexp-string.js +11 -0
  119. package/dist/augments/selection-set/select-collapsed.d.ts +54 -0
  120. package/dist/augments/selection-set/select-collapsed.js +63 -0
  121. package/dist/augments/selection-set/select-from.d.ts +48 -0
  122. package/dist/augments/selection-set/select-from.js +72 -0
  123. package/dist/augments/selection-set/selection-set.d.ts +37 -0
  124. package/dist/augments/selection-set/selection-set.js +1 -0
  125. package/dist/augments/string/casing/capitalization.d.ts +17 -0
  126. package/dist/augments/string/casing/capitalization.js +25 -0
  127. package/dist/augments/string/casing/casing.d.ts +73 -0
  128. package/dist/augments/string/casing/casing.js +65 -0
  129. package/dist/augments/string/casing/kebab-and-camel.d.ts +17 -0
  130. package/dist/augments/string/casing/kebab-and-camel.js +57 -0
  131. package/dist/augments/string/comma.d.ts +26 -0
  132. package/dist/augments/string/comma.js +48 -0
  133. package/dist/augments/string/join.d.ts +21 -0
  134. package/dist/augments/string/join.js +34 -0
  135. package/dist/augments/string/prefix.d.ts +30 -0
  136. package/dist/augments/string/prefix.js +30 -0
  137. package/dist/augments/string/remove-duplicate-characters.d.ts +17 -0
  138. package/dist/augments/string/remove-duplicate-characters.js +22 -0
  139. package/dist/augments/string/replace.d.ts +18 -0
  140. package/dist/augments/string/replace.js +22 -0
  141. package/dist/augments/string/split.d.ts +31 -0
  142. package/dist/augments/string/split.js +53 -0
  143. package/dist/augments/string/substring-index.d.ts +19 -0
  144. package/dist/augments/string/substring-index.js +47 -0
  145. package/dist/augments/string/suffix.d.ts +96 -0
  146. package/dist/augments/string/suffix.js +89 -0
  147. package/dist/augments/string/white-space.d.ts +12 -0
  148. package/dist/augments/string/white-space.js +19 -0
  149. package/dist/augments/string/wrap-string.d.ts +19 -0
  150. package/dist/augments/string/wrap-string.js +20 -0
  151. package/dist/augments/type/ensure-type.d.ts +12 -0
  152. package/dist/augments/type/ensure-type.js +14 -0
  153. package/dist/augments/type/readonly.d.ts +9 -0
  154. package/dist/augments/type/readonly.js +10 -0
  155. package/dist/augments/type/type-recursion.d.ts +253 -0
  156. package/dist/augments/type/type-recursion.js +1 -0
  157. package/dist/augments/type/union.d.ts +1 -0
  158. package/dist/augments/type/union.js +1 -0
  159. package/dist/augments/type/void-type.d.ts +9 -0
  160. package/dist/augments/type/void-type.js +1 -0
  161. package/dist/augments/type/writable.d.ts +10 -0
  162. package/dist/augments/type/writable.js +10 -0
  163. package/dist/index.d.ts +83 -0
  164. package/dist/index.js +83 -0
  165. package/package.json +43 -15
  166. package/dist/cjs/augments/ansi.js +0 -27
  167. package/dist/cjs/augments/array/array.js +0 -68
  168. package/dist/cjs/augments/array/remove-duplicates.js +0 -16
  169. package/dist/cjs/augments/async.js +0 -28
  170. package/dist/cjs/augments/boolean.js +0 -19
  171. package/dist/cjs/augments/common-number.js +0 -112
  172. package/dist/cjs/augments/common-string.js +0 -245
  173. package/dist/cjs/augments/debounce.js +0 -38
  174. package/dist/cjs/augments/environment.js +0 -6
  175. package/dist/cjs/augments/error.js +0 -52
  176. package/dist/cjs/augments/esm-path.js +0 -11
  177. package/dist/cjs/augments/function.js +0 -2
  178. package/dist/cjs/augments/json-compatible.js +0 -2
  179. package/dist/cjs/augments/json.js +0 -28
  180. package/dist/cjs/augments/object/any-object.js +0 -2
  181. package/dist/cjs/augments/object/enum.js +0 -48
  182. package/dist/cjs/augments/object/filter-object.js +0 -26
  183. package/dist/cjs/augments/object/get-or-set.js +0 -40
  184. package/dist/cjs/augments/object/has-key.js +0 -6
  185. package/dist/cjs/augments/object/jsonify.js +0 -6
  186. package/dist/cjs/augments/object/key-count.js +0 -2
  187. package/dist/cjs/augments/object/map-object.js +0 -61
  188. package/dist/cjs/augments/object/merge-deep.js +0 -52
  189. package/dist/cjs/augments/object/merge-property-arrays.js +0 -14
  190. package/dist/cjs/augments/object/object-entries.js +0 -40
  191. package/dist/cjs/augments/object/object.js +0 -18
  192. package/dist/cjs/augments/object/pick-deep.js +0 -2
  193. package/dist/cjs/augments/object/selection-set.js +0 -56
  194. package/dist/cjs/augments/object/typed-has-property.js +0 -29
  195. package/dist/cjs/augments/promise/deferred-promise.js +0 -31
  196. package/dist/cjs/augments/promise/promise.js +0 -79
  197. package/dist/cjs/augments/promise/wait.js +0 -66
  198. package/dist/cjs/augments/random.js +0 -118
  199. package/dist/cjs/augments/regexp.js +0 -19
  200. package/dist/cjs/augments/string/prefixes.js +0 -20
  201. package/dist/cjs/augments/string/suffixes.js +0 -40
  202. package/dist/cjs/augments/string/uuid.js +0 -13
  203. package/dist/cjs/augments/time.js +0 -35
  204. package/dist/cjs/augments/truncate-number.js +0 -153
  205. package/dist/cjs/augments/tuple.js +0 -20
  206. package/dist/cjs/augments/type-recursion.js +0 -2
  207. package/dist/cjs/augments/type.js +0 -36
  208. package/dist/cjs/augments/union.js +0 -2
  209. package/dist/cjs/augments/wrap-in-try.js +0 -37
  210. package/dist/cjs/index.js +0 -60
  211. package/dist/esm/augments/ansi.js +0 -24
  212. package/dist/esm/augments/array/array.js +0 -57
  213. package/dist/esm/augments/array/remove-duplicates.js +0 -13
  214. package/dist/esm/augments/async.js +0 -23
  215. package/dist/esm/augments/boolean.js +0 -14
  216. package/dist/esm/augments/common-number.js +0 -100
  217. package/dist/esm/augments/common-string.js +0 -227
  218. package/dist/esm/augments/debounce.js +0 -34
  219. package/dist/esm/augments/environment.js +0 -3
  220. package/dist/esm/augments/error.js +0 -45
  221. package/dist/esm/augments/esm-path.js +0 -8
  222. package/dist/esm/augments/json.js +0 -24
  223. package/dist/esm/augments/object/enum.js +0 -41
  224. package/dist/esm/augments/object/filter-object.js +0 -21
  225. package/dist/esm/augments/object/get-or-set.js +0 -36
  226. package/dist/esm/augments/object/has-key.js +0 -3
  227. package/dist/esm/augments/object/jsonify.js +0 -3
  228. package/dist/esm/augments/object/map-object.js +0 -57
  229. package/dist/esm/augments/object/merge-property-arrays.js +0 -11
  230. package/dist/esm/augments/object/object-entries.js +0 -32
  231. package/dist/esm/augments/object/object.js +0 -14
  232. package/dist/esm/augments/object/selection-set.js +0 -52
  233. package/dist/esm/augments/object/typed-has-property.js +0 -25
  234. package/dist/esm/augments/promise/deferred-promise.js +0 -28
  235. package/dist/esm/augments/promise/promise.js +0 -71
  236. package/dist/esm/augments/promise/wait.js +0 -60
  237. package/dist/esm/augments/random.js +0 -113
  238. package/dist/esm/augments/regexp.js +0 -14
  239. package/dist/esm/augments/string/prefixes.js +0 -16
  240. package/dist/esm/augments/string/suffixes.js +0 -31
  241. package/dist/esm/augments/string/uuid.js +0 -9
  242. package/dist/esm/augments/time.js +0 -31
  243. package/dist/esm/augments/tuple.js +0 -16
  244. package/dist/esm/augments/type.js +0 -30
  245. package/dist/esm/augments/wrap-in-try.js +0 -34
  246. package/dist/esm/index.js +0 -44
  247. package/dist/types/augments/ansi.d.ts +0 -1
  248. package/dist/types/augments/array/array.d.ts +0 -26
  249. package/dist/types/augments/array/remove-duplicates.d.ts +0 -1
  250. package/dist/types/augments/async.d.ts +0 -14
  251. package/dist/types/augments/boolean.d.ts +0 -6
  252. package/dist/types/augments/common-number.d.ts +0 -52
  253. package/dist/types/augments/common-string.d.ts +0 -74
  254. package/dist/types/augments/debounce.d.ts +0 -15
  255. package/dist/types/augments/environment.d.ts +0 -1
  256. package/dist/types/augments/error.d.ts +0 -9
  257. package/dist/types/augments/esm-path.d.ts +0 -4
  258. package/dist/types/augments/function.d.ts +0 -25
  259. package/dist/types/augments/json-compatible.d.ts +0 -22
  260. package/dist/types/augments/json.d.ts +0 -9
  261. package/dist/types/augments/object/any-object.d.ts +0 -2
  262. package/dist/types/augments/object/enum.d.ts +0 -8
  263. package/dist/types/augments/object/filter-object.d.ts +0 -4
  264. package/dist/types/augments/object/get-or-set.d.ts +0 -26
  265. package/dist/types/augments/object/has-key.d.ts +0 -1
  266. package/dist/types/augments/object/jsonify.d.ts +0 -2
  267. package/dist/types/augments/object/key-count.d.ts +0 -13
  268. package/dist/types/augments/object/map-object.d.ts +0 -20
  269. package/dist/types/augments/object/merge-property-arrays.d.ts +0 -1
  270. package/dist/types/augments/object/object-entries.d.ts +0 -8
  271. package/dist/types/augments/object/object.d.ts +0 -21
  272. package/dist/types/augments/object/pick-deep.d.ts +0 -14
  273. package/dist/types/augments/object/selection-set.d.ts +0 -27
  274. package/dist/types/augments/object/typed-has-property.d.ts +0 -7
  275. package/dist/types/augments/promise/deferred-promise.d.ts +0 -8
  276. package/dist/types/augments/promise/promise.d.ts +0 -15
  277. package/dist/types/augments/promise/wait.d.ts +0 -18
  278. package/dist/types/augments/random.d.ts +0 -37
  279. package/dist/types/augments/regexp.d.ts +0 -3
  280. package/dist/types/augments/string/prefixes.d.ts +0 -9
  281. package/dist/types/augments/string/suffixes.d.ts +0 -17
  282. package/dist/types/augments/string/uuid.d.ts +0 -5
  283. package/dist/types/augments/time.d.ts +0 -14
  284. package/dist/types/augments/truncate-number.d.ts +0 -19
  285. package/dist/types/augments/tuple.d.ts +0 -17
  286. package/dist/types/augments/type-recursion.d.ts +0 -161
  287. package/dist/types/augments/type.d.ts +0 -69
  288. package/dist/types/augments/union.d.ts +0 -5
  289. package/dist/types/index.d.ts +0 -44
  290. /package/dist/{esm/augments → augments/json}/json-compatible.js +0 -0
  291. /package/dist/{esm/augments/function.js → augments/log/log-writer.js} +0 -0
  292. /package/dist/{esm/augments/object/any-object.js → augments/number/coords.js} +0 -0
  293. /package/dist/{esm/augments/object/key-count.js → augments/number/digit.js} +0 -0
  294. /package/dist/{esm/augments/object/pick-deep.js → augments/number/dimensions.js} +0 -0
  295. /package/dist/{esm/augments/type-recursion.js → augments/object/empty.js} +0 -0
  296. /package/dist/{esm/augments/union.js → augments/object/key-count.js} +0 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Creates a new RegExp by adding the given `flags` to the original RegExp.
3
+ *
4
+ * @category RegExp
5
+ * @category Package : @augment-vir/common
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import {addRegExpFlags} from '@augment-vir/common';
10
+ *
11
+ * addRegExpFlags(/a/i, 'gm');
12
+ * // output is `/a/igm`
13
+ * ```
14
+ *
15
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
16
+ */
17
+ export declare function addRegExpFlags(originalRegExpOrString: RegExp | string, flags: string): RegExp;
18
+ /**
19
+ * Creates a new RegExp with the given `flags`.
20
+ *
21
+ * @category RegExp
22
+ * @category Package : @augment-vir/common
23
+ * @example
24
+ *
25
+ * ```ts
26
+ * import {setRegExpFlags} from '@augment-vir/common';
27
+ *
28
+ * setRegExpFlags(/a/i, 'gm');
29
+ * // output is `/a/gm`
30
+ * ```
31
+ *
32
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
33
+ */
34
+ export declare function setRegExpFlags(originalRegExpOrString: RegExp | string, flags: string): RegExp;
35
+ /**
36
+ * Creates a new RegExp by adding or removing the case insensitivity flag `'i'`, based on the given
37
+ * `caseSensitive` input. The first input can also be a string and it will be converted into a
38
+ * RegExp.
39
+ *
40
+ * @category RegExp
41
+ * @category Package : @augment-vir/common
42
+ * @example
43
+ *
44
+ * ```ts
45
+ * import {setRegExpCaseSensitivity} from '@augment-vir/common';
46
+ *
47
+ * setRegExpCaseSensitivity(/abc/i, {caseSensitive: true}); // output is `/abc/`
48
+ * setRegExpCaseSensitivity(/abc/, {caseSensitive: false}); // output is `/abc/i`
49
+ * setRegExpCaseSensitivity('abc', {caseSensitive: true}); // output is `/abc/i`
50
+ * ```
51
+ *
52
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
53
+ */
54
+ export declare function setRegExpCaseSensitivity(originalRegExpOrString: string | RegExp, { caseSensitive }: {
55
+ caseSensitive: boolean;
56
+ }): RegExp;
@@ -0,0 +1,75 @@
1
+ import { removeDuplicateCharacters } from '../string/remove-duplicate-characters.js';
2
+ import { escapeStringForRegExp } from './regexp-string.js';
3
+ /**
4
+ * Creates a new RegExp by adding the given `flags` to the original RegExp.
5
+ *
6
+ * @category RegExp
7
+ * @category Package : @augment-vir/common
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * import {addRegExpFlags} from '@augment-vir/common';
12
+ *
13
+ * addRegExpFlags(/a/i, 'gm');
14
+ * // output is `/a/igm`
15
+ * ```
16
+ *
17
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
18
+ */
19
+ export function addRegExpFlags(originalRegExpOrString, flags) {
20
+ const allFlags = removeDuplicateCharacters([
21
+ typeof originalRegExpOrString === 'string' ? '' : originalRegExpOrString.flags,
22
+ flags,
23
+ ]
24
+ .join('')
25
+ .toLowerCase());
26
+ return setRegExpFlags(originalRegExpOrString, allFlags);
27
+ }
28
+ /**
29
+ * Creates a new RegExp with the given `flags`.
30
+ *
31
+ * @category RegExp
32
+ * @category Package : @augment-vir/common
33
+ * @example
34
+ *
35
+ * ```ts
36
+ * import {setRegExpFlags} from '@augment-vir/common';
37
+ *
38
+ * setRegExpFlags(/a/i, 'gm');
39
+ * // output is `/a/gm`
40
+ * ```
41
+ *
42
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
43
+ */
44
+ export function setRegExpFlags(originalRegExpOrString, flags) {
45
+ const allFlags = removeDuplicateCharacters(flags);
46
+ if (typeof originalRegExpOrString === 'string') {
47
+ return new RegExp(escapeStringForRegExp(originalRegExpOrString), allFlags);
48
+ }
49
+ else {
50
+ return new RegExp(originalRegExpOrString.source, allFlags);
51
+ }
52
+ }
53
+ /**
54
+ * Creates a new RegExp by adding or removing the case insensitivity flag `'i'`, based on the given
55
+ * `caseSensitive` input. The first input can also be a string and it will be converted into a
56
+ * RegExp.
57
+ *
58
+ * @category RegExp
59
+ * @category Package : @augment-vir/common
60
+ * @example
61
+ *
62
+ * ```ts
63
+ * import {setRegExpCaseSensitivity} from '@augment-vir/common';
64
+ *
65
+ * setRegExpCaseSensitivity(/abc/i, {caseSensitive: true}); // output is `/abc/`
66
+ * setRegExpCaseSensitivity(/abc/, {caseSensitive: false}); // output is `/abc/i`
67
+ * setRegExpCaseSensitivity('abc', {caseSensitive: true}); // output is `/abc/i`
68
+ * ```
69
+ *
70
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
71
+ */
72
+ export function setRegExpCaseSensitivity(originalRegExpOrString, { caseSensitive }) {
73
+ const caseSensitivityFlag = caseSensitive ? '' : 'i';
74
+ return addRegExpFlags(originalRegExpOrString, caseSensitivityFlag);
75
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Escapes characters from the given string so that it can be used within a RegExp without being
3
+ * parsed as RegExp syntax.
4
+ *
5
+ * @category RegExp
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
9
+ export declare function escapeStringForRegExp(input: string): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Escapes characters from the given string so that it can be used within a RegExp without being
3
+ * parsed as RegExp syntax.
4
+ *
5
+ * @category RegExp
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
9
+ export function escapeStringForRegExp(input) {
10
+ return input.replaceAll(/[\^$\\.*+?()[\]{}|]/g, String.raw `\$&`);
11
+ }
@@ -0,0 +1,54 @@
1
+ import type { AnyObject, Values } from '@augment-vir/core';
2
+ import { ExcludeEmpty } from '../object/empty.js';
3
+ import { KeyCount } from '../object/key-count.js';
4
+ import { TsRecurse, TsRecursionStart, TsRecursionTracker, TsTooMuchRecursion } from '../type/type-recursion.js';
5
+ import { GenericSelectionSet, SelectFrom, SelectionSet } from './selection-set.js';
6
+ /**
7
+ * The same as {@link selectFrom} except that the final output is collapsed until the first nested
8
+ * value that has more than 1 key or that is not an object.
9
+ *
10
+ * @category Selection
11
+ * @category Package : @augment-vir/common
12
+ * @example
13
+ *
14
+ * ```ts
15
+ * import {selectCollapsedFrom} from '@augment-vir/common';
16
+ *
17
+ * selectCollapsedFrom(
18
+ * [
19
+ * {
20
+ * child: {
21
+ * grandChild: 'hi',
22
+ * grandChild2: 3,
23
+ * grandChild3: /something/,
24
+ * },
25
+ * },
26
+ * {
27
+ * child: {
28
+ * grandChild: 'hi',
29
+ * grandChild2: 4,
30
+ * grandChild3: /something/,
31
+ * },
32
+ * },
33
+ * ],
34
+ * {
35
+ * child: {
36
+ * grandChild2: true,
37
+ * },
38
+ * },
39
+ * );
40
+ * // output is `[3, 4]`
41
+ * ```
42
+ *
43
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
44
+ */
45
+ export declare function selectCollapsedFrom<Full extends AnyObject, const Selection extends SelectionSet<NoInfer<Full>>>(originalObject: Readonly<Full>, selectionSet: Readonly<Selection>): PickCollapsedSelection<Full, Selection>;
46
+ /**
47
+ * Collapses a selected value to the first part of the selection that contains more than 1 key or
48
+ * that is not an object. This produces the output type for {@link selectCollapsedFrom}.
49
+ *
50
+ * @category Selection
51
+ * @category Package : @augment-vir/common
52
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
53
+ */
54
+ export type PickCollapsedSelection<Full extends Readonly<AnyObject>, Selection extends SelectionSet<Full>, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? 'Error: recursive object depth is too deep.' : KeyCount<ExcludeEmpty<NonNullable<SelectFrom<Full, Selection, Depth>>>> extends 1 ? Selection[keyof SelectFrom<Full, Selection, Depth>] extends GenericSelectionSet ? PickCollapsedSelection<NonNullable<Full[keyof SelectFrom<Full, Selection, Depth>]>, Selection[keyof SelectFrom<Full, Selection, Depth>], TsRecurse<Depth>> | Extract<Full[keyof SelectFrom<Full, Selection, Depth>], undefined | null> : Values<SelectFrom<Full, Selection, Depth>> : SelectFrom<Full, Selection, Depth>;
@@ -0,0 +1,63 @@
1
+ import { check } from '@augment-vir/assert';
2
+ import { selectFrom, shouldPreserveInSelectionSet } from './select-from.js';
3
+ /**
4
+ * The same as {@link selectFrom} except that the final output is collapsed until the first nested
5
+ * value that has more than 1 key or that is not an object.
6
+ *
7
+ * @category Selection
8
+ * @category Package : @augment-vir/common
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * import {selectCollapsedFrom} from '@augment-vir/common';
13
+ *
14
+ * selectCollapsedFrom(
15
+ * [
16
+ * {
17
+ * child: {
18
+ * grandChild: 'hi',
19
+ * grandChild2: 3,
20
+ * grandChild3: /something/,
21
+ * },
22
+ * },
23
+ * {
24
+ * child: {
25
+ * grandChild: 'hi',
26
+ * grandChild2: 4,
27
+ * grandChild3: /something/,
28
+ * },
29
+ * },
30
+ * ],
31
+ * {
32
+ * child: {
33
+ * grandChild2: true,
34
+ * },
35
+ * },
36
+ * );
37
+ * // output is `[3, 4]`
38
+ * ```
39
+ *
40
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
41
+ */
42
+ export function selectCollapsedFrom(originalObject, selectionSet) {
43
+ const selected = selectFrom(originalObject, selectionSet);
44
+ return collapseObject(selected, selectionSet);
45
+ }
46
+ function collapseObject(input, selectionSet) {
47
+ if (shouldPreserveInSelectionSet(input)) {
48
+ return input;
49
+ }
50
+ const keys = Object.keys(input);
51
+ if (Array.isArray(input)) {
52
+ return input.map((innerInput) => collapseObject(innerInput, selectionSet));
53
+ }
54
+ else if (check.isLengthAtLeast(keys, 2)) {
55
+ return input;
56
+ }
57
+ else if (check.isLengthAtLeast(keys, 1) && check.isObject(selectionSet)) {
58
+ return collapseObject(input[keys[0]], selectionSet[keys[0]]);
59
+ }
60
+ else {
61
+ return input;
62
+ }
63
+ }
@@ -0,0 +1,48 @@
1
+ import type { AnyObject } from '@augment-vir/core';
2
+ import { SelectFrom, SelectionSet } from './selection-set.js';
3
+ /**
4
+ * Determine if the given input should be preserved in the selection output, meaning it won't be
5
+ * recursed into.
6
+ *
7
+ * @ignore
8
+ */
9
+ export declare function shouldPreserveInSelectionSet(input: unknown): boolean;
10
+ /**
11
+ * Performs a SQL-like nested selection on an object, extracting the selected values.
12
+ *
13
+ * @category Selection
14
+ * @category Package : @augment-vir/common
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * import {selectFrom} from '@augment-vir/common';
19
+ *
20
+ * selectFrom(
21
+ * [
22
+ * {
23
+ * child: {
24
+ * grandChild: 'hi',
25
+ * grandChild2: 3,
26
+ * grandChild3: /something/,
27
+ * },
28
+ * },
29
+ * {
30
+ * child: {
31
+ * grandChild: 'hi',
32
+ * grandChild2: 4,
33
+ * grandChild3: /something/,
34
+ * },
35
+ * },
36
+ * ],
37
+ * {
38
+ * child: {
39
+ * grandChild2: true,
40
+ * },
41
+ * },
42
+ * );
43
+ * // output is `[{child: {grandChild2: 3}}, {child: {grandChild2: 4}}]`
44
+ * ```
45
+ *
46
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
47
+ */
48
+ export declare function selectFrom<Full extends AnyObject, const Selection extends SelectionSet<NoInfer<Full>>>(originalObject: Readonly<Full>, selectionSet: Readonly<Selection>): SelectFrom<Full, Selection>;
@@ -0,0 +1,72 @@
1
+ import { check } from '@augment-vir/assert';
2
+ import { mapObjectValues } from '../object/map-values.js';
3
+ import { omitObjectKeys } from '../object/object-keys.js';
4
+ /**
5
+ * Determine if the given input should be preserved in the selection output, meaning it won't be
6
+ * recursed into.
7
+ *
8
+ * @ignore
9
+ */
10
+ export function shouldPreserveInSelectionSet(input) {
11
+ return check.isPrimitive(input) || input instanceof RegExp || input instanceof Promise;
12
+ }
13
+ /**
14
+ * Performs a SQL-like nested selection on an object, extracting the selected values.
15
+ *
16
+ * @category Selection
17
+ * @category Package : @augment-vir/common
18
+ * @example
19
+ *
20
+ * ```ts
21
+ * import {selectFrom} from '@augment-vir/common';
22
+ *
23
+ * selectFrom(
24
+ * [
25
+ * {
26
+ * child: {
27
+ * grandChild: 'hi',
28
+ * grandChild2: 3,
29
+ * grandChild3: /something/,
30
+ * },
31
+ * },
32
+ * {
33
+ * child: {
34
+ * grandChild: 'hi',
35
+ * grandChild2: 4,
36
+ * grandChild3: /something/,
37
+ * },
38
+ * },
39
+ * ],
40
+ * {
41
+ * child: {
42
+ * grandChild2: true,
43
+ * },
44
+ * },
45
+ * );
46
+ * // output is `[{child: {grandChild2: 3}}, {child: {grandChild2: 4}}]`
47
+ * ```
48
+ *
49
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
50
+ */
51
+ export function selectFrom(originalObject, selectionSet) {
52
+ if (Array.isArray(originalObject)) {
53
+ return originalObject.map((originalEntry) => selectFrom(originalEntry, selectionSet));
54
+ }
55
+ const keysToRemove = [];
56
+ return omitObjectKeys(mapObjectValues(originalObject, (key, value) => {
57
+ const selection = selectionSet[key];
58
+ if (selection === true) {
59
+ return value;
60
+ }
61
+ else if (!selection) {
62
+ keysToRemove.push(key);
63
+ return undefined;
64
+ }
65
+ else if (shouldPreserveInSelectionSet(value)) {
66
+ return value;
67
+ }
68
+ else {
69
+ return selectFrom(value, selection);
70
+ }
71
+ }), keysToRemove);
72
+ }
@@ -0,0 +1,37 @@
1
+ import type { AnyObject } from '@augment-vir/core';
2
+ import { IsAny, IsNever, Primitive, UnionToIntersection } from 'type-fest';
3
+ import { TsRecurse, TsRecursionStart, TsRecursionTracker, TsTooMuchRecursion } from '../type/type-recursion.js';
4
+ /** All types that won't be recursed into when defining a {@link SelectionSet}. */
5
+ type SelectionTypesToPreserve = Primitive | RegExp | Promise<any>;
6
+ /**
7
+ * A generic selection set without specific keys. Useful for type parameter baselines.
8
+ *
9
+ * @category Selection
10
+ * @category Package : @augment-vir/common
11
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
12
+ */
13
+ export type GenericSelectionSet = {
14
+ [Key in PropertyKey]: unknown;
15
+ };
16
+ /**
17
+ * Performs a SQL-like nested selection on an object, extracting the selected values. This produces
18
+ * the output type for `selectFrom`.
19
+ *
20
+ * @category Selection
21
+ * @category Package : @augment-vir/common
22
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
23
+ */
24
+ export type SelectFrom<Full extends Readonly<AnyObject>, Selection extends SelectionSet<Full>, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? ['Error: recursive object depth is too deep.'] : Full extends ReadonlyArray<infer Element extends any> ? (SelectFrom<Extract<Element, AnyObject>, Selection, TsRecurse<Depth>> | Exclude<Element, AnyObject>)[] : {
25
+ -readonly [Key in keyof Selection as Selection[Key] extends false ? never : Key extends keyof Full ? Key : never]: (Selection[Key] extends GenericSelectionSet ? SelectFrom<NonNullable<Extract<Full[Key], AnyObject>>, Selection[Key], TsRecurse<Depth>> : Full[Key]) | Exclude<Full[Key], AnyObject>;
26
+ };
27
+ /**
28
+ * Defines a selection set for a given object type. This is used in {@link SelectFrom}.
29
+ *
30
+ * @category Selection
31
+ * @category Package : @augment-vir/common
32
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
33
+ */
34
+ export type SelectionSet<Full extends Readonly<AnyObject>, Depth extends TsRecursionTracker = TsRecursionStart> = IsAny<Full> extends true ? any : Depth extends TsTooMuchRecursion ? boolean : Full extends ReadonlyArray<infer FullChild extends AnyObject> ? SelectionSet<FullChild, TsRecurse<Depth>> : Partial<{
35
+ [Key in keyof Full]: IsNever<Exclude<Full[Key], SelectionTypesToPreserve>> extends true ? boolean : UnionToIntersection<SelectionSet<NonNullable<Required<Full>[Key]>, TsRecurse<Depth>>> | boolean;
36
+ }>;
37
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { CasingOptions } from './casing.js';
2
+ /**
3
+ * Capitalize the first letter of the input _only if_ the given options specifies doing so.
4
+ *
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
9
+ export declare function maybeCapitalize(input: string, casingOptions: Pick<CasingOptions, 'capitalizeFirstLetter'>): string;
10
+ /**
11
+ * Capitalize the first letter of the input.
12
+ *
13
+ * @category String
14
+ * @category Package : @augment-vir/common
15
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
16
+ */
17
+ export declare function capitalizeFirstLetter<InputGeneric extends string>(input: InputGeneric): Capitalize<InputGeneric>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Capitalize the first letter of the input _only if_ the given options specifies doing so.
3
+ *
4
+ * @category String
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
+ */
8
+ export function maybeCapitalize(input, casingOptions) {
9
+ return casingOptions.capitalizeFirstLetter ? capitalizeFirstLetter(input) : input;
10
+ }
11
+ /**
12
+ * Capitalize the first letter of the input.
13
+ *
14
+ * @category String
15
+ * @category Package : @augment-vir/common
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
18
+ export function capitalizeFirstLetter(input) {
19
+ if (!input.length) {
20
+ return '';
21
+ }
22
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
23
+ const firstLetter = input[0];
24
+ return (firstLetter.toUpperCase() + input.slice(1));
25
+ }
@@ -0,0 +1,73 @@
1
+ import { PartialWithUndefined } from '@augment-vir/core';
2
+ /**
3
+ * Options for casing functions in `@augment-vir/common`.
4
+ *
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
9
+ export type CasingOptions = {
10
+ /**
11
+ * Capitalize the first letter of the string.
12
+ *
13
+ * @default false
14
+ */
15
+ capitalizeFirstLetter: boolean;
16
+ };
17
+ /**
18
+ * Default options for {@link CasingOptions}.
19
+ *
20
+ * @category String
21
+ * @category Package : @augment-vir/common
22
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
23
+ */
24
+ export declare const defaultCasingOptions: Required<CasingOptions>;
25
+ /**
26
+ * The different string cases.
27
+ *
28
+ * @category String
29
+ * @category Package : @augment-vir/common
30
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
31
+ */
32
+ export declare enum StringCase {
33
+ Upper = "upper",
34
+ Lower = "lower"
35
+ }
36
+ /**
37
+ * Indicates whether the given string has different lower and upper case variants. (Some strings
38
+ * don't, such as all numbers or `'√'`.)
39
+ *
40
+ * @category String
41
+ * @category Package : @augment-vir/common
42
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
43
+ */
44
+ export declare function hasCase(input: string): boolean;
45
+ /**
46
+ * Options for {@link isCase}.
47
+ *
48
+ * @category String
49
+ * @category Package : @augment-vir/common
50
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
51
+ */
52
+ export type IsCaseOptions = {
53
+ /**
54
+ * Set to `true` to fail on characters that don't have different upper and lower case versions
55
+ * (such as punctuation, like `'.'` or symbols, like `'√'`).
56
+ *
57
+ * @default false
58
+ */
59
+ rejectNoCaseCharacters: boolean;
60
+ };
61
+ /**
62
+ * Checks if the given string is exclusively of the specific case.
63
+ *
64
+ * Note that some characters have no casing, such as punctuation (they have no difference between
65
+ * upper and lower casings). By default, those letters always return `true` for this function,
66
+ * regardless of which `caseType` is provided. To instead return `false` for any such characters,
67
+ * pass in an options object and set `rejectNoCaseCharacters` to true.
68
+ *
69
+ * @category String
70
+ * @category Package : @augment-vir/common
71
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
72
+ */
73
+ export declare function isCase(input: string, caseType: StringCase, options?: PartialWithUndefined<IsCaseOptions>): boolean;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Default options for {@link CasingOptions}.
3
+ *
4
+ * @category String
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
+ */
8
+ export const defaultCasingOptions = {
9
+ capitalizeFirstLetter: false,
10
+ };
11
+ /**
12
+ * The different string cases.
13
+ *
14
+ * @category String
15
+ * @category Package : @augment-vir/common
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
18
+ export var StringCase;
19
+ (function (StringCase) {
20
+ StringCase["Upper"] = "upper";
21
+ StringCase["Lower"] = "lower";
22
+ })(StringCase || (StringCase = {}));
23
+ /**
24
+ * Indicates whether the given string has different lower and upper case variants. (Some strings
25
+ * don't, such as all numbers or `'√'`.)
26
+ *
27
+ * @category String
28
+ * @category Package : @augment-vir/common
29
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
30
+ */
31
+ export function hasCase(input) {
32
+ return input.toLowerCase() !== input.toUpperCase();
33
+ }
34
+ /**
35
+ * Checks if the given string is exclusively of the specific case.
36
+ *
37
+ * Note that some characters have no casing, such as punctuation (they have no difference between
38
+ * upper and lower casings). By default, those letters always return `true` for this function,
39
+ * regardless of which `caseType` is provided. To instead return `false` for any such characters,
40
+ * pass in an options object and set `rejectNoCaseCharacters` to true.
41
+ *
42
+ * @category String
43
+ * @category Package : @augment-vir/common
44
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
45
+ */
46
+ export function isCase(input, caseType, options) {
47
+ if (!input && options?.rejectNoCaseCharacters) {
48
+ return false;
49
+ }
50
+ for (const letter of input) {
51
+ if (!hasCase(letter)) {
52
+ if (options?.rejectNoCaseCharacters) {
53
+ return false;
54
+ }
55
+ else {
56
+ continue;
57
+ }
58
+ }
59
+ else if ((caseType === StringCase.Upper && letter !== letter.toUpperCase()) ||
60
+ (caseType === StringCase.Lower && letter !== letter.toLowerCase())) {
61
+ return false;
62
+ }
63
+ }
64
+ return true;
65
+ }
@@ -0,0 +1,17 @@
1
+ import { CasingOptions } from './casing.js';
2
+ /**
3
+ * Converts a kebab-case string to CamelCase.
4
+ *
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
9
+ export declare function kebabCaseToCamelCase(rawKebabCase: string, casingOptions?: Partial<CasingOptions> | undefined): string;
10
+ /**
11
+ * Converts a CamelCase string to kebab-case.
12
+ *
13
+ * @category String
14
+ * @category Package : @augment-vir/common
15
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
16
+ */
17
+ export declare function camelCaseToKebabCase(rawCamelCase: string): string;