@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,57 @@
1
+ import { mergeDefinedProperties } from '../../object/merge-defined-properties.js';
2
+ import { maybeCapitalize } from './capitalization.js';
3
+ import { defaultCasingOptions, isCase, StringCase } from './casing.js';
4
+ /**
5
+ * Converts a kebab-case string to CamelCase.
6
+ *
7
+ * @category String
8
+ * @category Package : @augment-vir/common
9
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
10
+ */
11
+ export function kebabCaseToCamelCase(rawKebabCase, casingOptions = {}) {
12
+ const kebabCase = rawKebabCase.toLowerCase();
13
+ if (!kebabCase.length) {
14
+ return '';
15
+ }
16
+ const camelCase = kebabCase
17
+ .replace(/^-+/, '')
18
+ .replace(/-{2,}/g, '-')
19
+ .replace(/-(?:.|$)/g, (dashMatch) => {
20
+ const letter = dashMatch[1];
21
+ if (letter) {
22
+ return letter.toUpperCase();
23
+ }
24
+ else {
25
+ return '';
26
+ }
27
+ });
28
+ return maybeCapitalize(camelCase, mergeDefinedProperties(defaultCasingOptions, casingOptions));
29
+ }
30
+ /**
31
+ * Converts a CamelCase string to kebab-case.
32
+ *
33
+ * @category String
34
+ * @category Package : @augment-vir/common
35
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
36
+ */
37
+ export function camelCaseToKebabCase(rawCamelCase) {
38
+ const kebabCase = rawCamelCase
39
+ .split('')
40
+ .reduce((accum, currentLetter, index, originalString) => {
41
+ const previousLetter = index > 0 ? originalString[index - 1] || '' : '';
42
+ const nextLetter = index < originalString.length - 1 ? originalString[index + 1] || '' : '';
43
+ const possibleWordBoundary = isCase(previousLetter, StringCase.Lower, { rejectNoCaseCharacters: true }) ||
44
+ isCase(nextLetter, StringCase.Lower, { rejectNoCaseCharacters: true });
45
+ if (currentLetter === currentLetter.toLowerCase() ||
46
+ index === 0 ||
47
+ !possibleWordBoundary) {
48
+ accum += currentLetter;
49
+ }
50
+ else {
51
+ accum += `-${currentLetter.toLowerCase()}`;
52
+ }
53
+ return accum;
54
+ }, '')
55
+ .toLowerCase();
56
+ return kebabCase;
57
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Removes all commas from the given string.
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 declare function removeCommas(input: string): string;
9
+ /**
10
+ * Convert the given number into a string, then add commas like a normal number would have.
11
+ *
12
+ * @category String
13
+ * @category Number
14
+ * @category Package : @augment-vir/common
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * import {addCommasToNumber} from '@augment-vir/common';
19
+ *
20
+ * addCommasToNumber(1000123.456);
21
+ * // output is `'1,000,123.456'`
22
+ * ```
23
+ *
24
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
25
+ */
26
+ export declare function addCommasToNumber(input: number | string): string;
@@ -0,0 +1,48 @@
1
+ import { safeMatch } from '../regexp/match.js';
2
+ /**
3
+ * Removes all commas from the given string.
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 function removeCommas(input) {
10
+ return input.replace(/,/g, '');
11
+ }
12
+ /**
13
+ * Convert the given number into a string, then add commas like a normal number would have.
14
+ *
15
+ * @category String
16
+ * @category Number
17
+ * @category Package : @augment-vir/common
18
+ * @example
19
+ *
20
+ * ```ts
21
+ * import {addCommasToNumber} from '@augment-vir/common';
22
+ *
23
+ * addCommasToNumber(1000123.456);
24
+ * // output is `'1,000,123.456'`
25
+ * ```
26
+ *
27
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
28
+ */
29
+ export function addCommasToNumber(input) {
30
+ if (typeof input === 'string' && isNaN(Number(input))) {
31
+ return 'NaN';
32
+ }
33
+ const numericValue = Number(input);
34
+ const isNegative = numericValue < 0;
35
+ const stringValue = String(Math.abs(numericValue));
36
+ const [digits = '', decimalValues,] = stringValue.split('.');
37
+ const decimalString = decimalValues ? `.${decimalValues}` : '';
38
+ const separated = safeMatch(digits.split('').reverse().join(''), /.{1,3}/g)
39
+ .reverse()
40
+ .map((entry) => entry.split('').reverse().join(''));
41
+ const valueWithCommas = separated.join(',');
42
+ const negativeMarker = isNegative ? '-' : '';
43
+ return [
44
+ negativeMarker,
45
+ valueWithCommas,
46
+ decimalString,
47
+ ].join('');
48
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Join elements into a string with commas separating each value. Add a conjunction before the final
3
+ * item in the list. If the array has a length < 2, the conjunction is not added. If the list is
4
+ * only of length 2, then no commas are added.
5
+ *
6
+ * @category String
7
+ * @category Package : @augment-vir/common
8
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
9
+ */
10
+ export declare function joinWithFinalConjunction(
11
+ /**
12
+ * Array of items to be converted into strings. Works best if these are simply strings to begin
13
+ * with.
14
+ */
15
+ list: ReadonlyArray<any>,
16
+ /**
17
+ * The conjunction to be used before the final element.
18
+ *
19
+ * @default 'and'
20
+ */
21
+ conjunction?: string): string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Join elements into a string with commas separating each value. Add a conjunction before the final
3
+ * item in the list. If the array has a length < 2, the conjunction is not added. If the list is
4
+ * only of length 2, then no commas are added.
5
+ *
6
+ * @category String
7
+ * @category Package : @augment-vir/common
8
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
9
+ */
10
+ export function joinWithFinalConjunction(
11
+ /**
12
+ * Array of items to be converted into strings. Works best if these are simply strings to begin
13
+ * with.
14
+ */
15
+ list,
16
+ /**
17
+ * The conjunction to be used before the final element.
18
+ *
19
+ * @default 'and'
20
+ */
21
+ conjunction = 'and') {
22
+ if (list.length < 2) {
23
+ /**
24
+ * If there are not multiple things in the list to join, just turn the list into a string
25
+ * for an empty list, this will be '', for a single item list, this will just be the first
26
+ * item as a string.
27
+ */
28
+ return list.join('');
29
+ }
30
+ /** When there are only two items in the list, we don't want any commas. */
31
+ const commaSep = list.length > 2 ? ', ' : ' ';
32
+ const commaJoined = list.slice(0, -1).join(commaSep);
33
+ return `${commaJoined}${commaSep}${conjunction} ${list[list.length - 1]}`;
34
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Generic string type but with the given prefix prepended to it.
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 type WithPrefix<Prefix extends string> = `${Prefix}${string}`;
9
+ /**
10
+ * Adds a prefix to a string if it does not already exist.
11
+ *
12
+ * @category String
13
+ * @category Package : @augment-vir/common
14
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
15
+ */
16
+ export declare function addPrefix<const Prefix extends string>({ value, prefix, }: {
17
+ value: unknown;
18
+ prefix: Prefix;
19
+ }): WithPrefix<Prefix>;
20
+ /**
21
+ * Removes a prefix from a string if it exists.
22
+ *
23
+ * @category String
24
+ * @category Package : @augment-vir/common
25
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
26
+ */
27
+ export declare function removePrefix<const Prefix extends string>({ value, prefix, }: {
28
+ value: string;
29
+ prefix: Prefix;
30
+ }): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Adds a prefix to a string if it does not already exist.
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 addPrefix({ value, prefix, }) {
9
+ if (String(value).startsWith(prefix)) {
10
+ return String(value);
11
+ }
12
+ else {
13
+ return `${prefix}${String(value)}`;
14
+ }
15
+ }
16
+ /**
17
+ * Removes a prefix from a string if it exists.
18
+ *
19
+ * @category String
20
+ * @category Package : @augment-vir/common
21
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
22
+ */
23
+ export function removePrefix({ value, prefix, }) {
24
+ if (value.startsWith(prefix)) {
25
+ return value.slice(prefix.length);
26
+ }
27
+ else {
28
+ return value;
29
+ }
30
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Removes duplicate characters from any number of strings.
3
+ *
4
+ * @category String
5
+ * @category Package : @augment-vir/common
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import {removeDuplicateCharacters} from '@augment-vir/common';
10
+ *
11
+ * removeDuplicateCharacters('aAaBc', 'QrsAa');
12
+ * // output is `'aABcQrs'`
13
+ * ```
14
+ *
15
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
16
+ */
17
+ export declare function removeDuplicateCharacters(...values: ReadonlyArray<string>): string;
@@ -0,0 +1,22 @@
1
+ import { removeDuplicates } from '../array/remove-duplicates.js';
2
+ /**
3
+ * Removes duplicate characters from any number of strings.
4
+ *
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {removeDuplicateCharacters} from '@augment-vir/common';
11
+ *
12
+ * removeDuplicateCharacters('aAaBc', 'QrsAa');
13
+ * // output is `'aABcQrs'`
14
+ * ```
15
+ *
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
18
+ export function removeDuplicateCharacters(...values) {
19
+ const combined = values.join('');
20
+ const deDuped = removeDuplicates(Array.from(combined));
21
+ return Array.from(deDuped).join('');
22
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Replaces whatever substring is at the given index in the original string with the new string.
3
+ * Optionally, provide a length of the substring to get replaced.
4
+ *
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {replaceStringAtIndex} from '@augment-vir/common';
11
+ *
12
+ * replaceStringAtIndex('eat the waffles', 4, 'his'); // outputs `'eat his waffles'`
13
+ * replaceStringAtIndex('eat the waffles', 4, 'my', 3); // outputs `'eat my waffles'`
14
+ * ```
15
+ *
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
18
+ export declare function replaceStringAtIndex(originalString: string, start: number, newString: string, length?: number): string;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Replaces whatever substring is at the given index in the original string with the new string.
3
+ * Optionally, provide a length of the substring to get replaced.
4
+ *
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {replaceStringAtIndex} from '@augment-vir/common';
11
+ *
12
+ * replaceStringAtIndex('eat the waffles', 4, 'his'); // outputs `'eat his waffles'`
13
+ * replaceStringAtIndex('eat the waffles', 4, 'my', 3); // outputs `'eat my waffles'`
14
+ * ```
15
+ *
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
18
+ export function replaceStringAtIndex(originalString, start, newString, length = newString.length) {
19
+ const before = originalString.slice(0, Math.max(0, start));
20
+ const after = originalString.slice(Math.max(0, start + length));
21
+ return `${before}${newString}${after}`;
22
+ }
@@ -0,0 +1,31 @@
1
+ import type { AtLeastTuple } from '@augment-vir/core';
2
+ /**
3
+ * Same as *
4
+ * [`''.split`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5
+ * but includes the split delimiter in the output array.
6
+ *
7
+ * @category String
8
+ * @category Package : @augment-vir/common
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * import {splitIncludeSplit} from '@augment-vir/common';
13
+ *
14
+ * splitIncludeSplit('1,2,3', ',', {caseSensitive: false}); // outputs `['1', ',', '2', ',', '3']`
15
+ * ```
16
+ *
17
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
18
+ */
19
+ export declare function splitIncludeSplit(original: string, splitDelimiter: string | RegExp, { caseSensitive }: {
20
+ caseSensitive: boolean;
21
+ }): readonly string[];
22
+ /**
23
+ * Same as
24
+ * [`''.split`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/split)
25
+ * but typed better: it always returns an array with at least one string.
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 declare function safeSplit(input: string, splitString: string): AtLeastTuple<string, 1>;
@@ -0,0 +1,53 @@
1
+ import { setRegExpCaseSensitivity } from '../regexp/regexp-flags.js';
2
+ import { findSubstringIndexes } from './substring-index.js';
3
+ /**
4
+ * Same as *
5
+ * [`''.split`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/split)
6
+ * but includes the split delimiter in the output array.
7
+ *
8
+ * @category String
9
+ * @category Package : @augment-vir/common
10
+ * @example
11
+ *
12
+ * ```ts
13
+ * import {splitIncludeSplit} from '@augment-vir/common';
14
+ *
15
+ * splitIncludeSplit('1,2,3', ',', {caseSensitive: false}); // outputs `['1', ',', '2', ',', '3']`
16
+ * ```
17
+ *
18
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
19
+ */
20
+ export function splitIncludeSplit(original, splitDelimiter, { caseSensitive }) {
21
+ const indexLengths = findSubstringIndexes({
22
+ searchIn: original,
23
+ searchFor: splitDelimiter,
24
+ caseSensitive,
25
+ includeLength: true,
26
+ });
27
+ const splitter = setRegExpCaseSensitivity(splitDelimiter, { caseSensitive });
28
+ const splits = original.split(splitter);
29
+ return splits.reduce((accum, current, index) => {
30
+ // this will be undefined on the last index
31
+ const splitterLength = indexLengths[index];
32
+ const includeCurrent = accum.concat(current);
33
+ if (splitterLength) {
34
+ const splitterMatch = original.slice(splitterLength.index, splitterLength.index + splitterLength.length);
35
+ return includeCurrent.concat(splitterMatch);
36
+ }
37
+ else {
38
+ return includeCurrent;
39
+ }
40
+ }, []);
41
+ }
42
+ /**
43
+ * Same as
44
+ * [`''.split`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/split)
45
+ * but typed better: it always returns an array with at least one string.
46
+ *
47
+ * @category String
48
+ * @category Package : @augment-vir/common
49
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
50
+ */
51
+ export function safeSplit(input, splitString) {
52
+ return input.split(splitString);
53
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Finds all indexes of a `searchFor` string or RegExp in `searchIn`. Ths is similar to
3
+ * [`''.indexOf`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
4
+ * except that it finds _all_ indexes of.
5
+ *
6
+ * @category String
7
+ * @category Package : @augment-vir/common
8
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
9
+ */
10
+ export declare function findSubstringIndexes<IncludeLength extends boolean | undefined>({ searchIn, searchFor, caseSensitive, includeLength, }: {
11
+ searchIn: string;
12
+ searchFor: string | RegExp;
13
+ caseSensitive: boolean;
14
+ /** Set to true to get an array of objects with the found indexes _and_ their lengths. */
15
+ includeLength?: IncludeLength;
16
+ }): IncludeLength extends true ? {
17
+ index: number;
18
+ length: number;
19
+ }[] : number[];
@@ -0,0 +1,47 @@
1
+ import { addRegExpFlags, setRegExpCaseSensitivity } from '../regexp/regexp-flags.js';
2
+ /**
3
+ * Finds all indexes of a `searchFor` string or RegExp in `searchIn`. Ths is similar to
4
+ * [`''.indexOf`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
5
+ * except that it finds _all_ indexes of.
6
+ *
7
+ * @category String
8
+ * @category Package : @augment-vir/common
9
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
10
+ */
11
+ export function findSubstringIndexes({ searchIn, searchFor, caseSensitive, includeLength, }) {
12
+ const searchRegExp = addRegExpFlags(setRegExpCaseSensitivity(searchFor, { caseSensitive }), 'g');
13
+ const indexes = [];
14
+ const indexesAndLengths = [];
15
+ searchIn.replace(searchRegExp, (...matchResults) => {
16
+ /**
17
+ * Grabbing the second to last entry in the array (rather than the second) takes capture
18
+ * groups into account.
19
+ */
20
+ const matchIndex = matchResults[matchResults.length - 2];
21
+ // this is used as a type safety catch and cannot actually be triggered on purpose
22
+ /* node:coverage ignore next 5 */
23
+ if (typeof matchIndex !== 'number') {
24
+ throw new TypeError(`Match index "${matchIndex}" is not a number. Searching for "${searchFor}" in "${searchIn}".`);
25
+ }
26
+ const regExpMatch = matchResults[0];
27
+ // this is used as a type safety catch and cannot actually be triggered on purpose
28
+ /* node:coverage ignore next 5 */
29
+ if (typeof regExpMatch !== 'string') {
30
+ throw new TypeError(`regExpMatch should've been a string but was ${typeof regExpMatch}!`);
31
+ }
32
+ indexesAndLengths.push({ index: matchIndex, length: regExpMatch.length });
33
+ indexes.push(matchIndex);
34
+ const originalMatch = matchResults[0];
35
+ // this is used as a type safety catch and cannot actually be triggered on purpose
36
+ /* node:coverage ignore next 5 */
37
+ if (typeof originalMatch !== 'string') {
38
+ throw new TypeError(`Original match when searching for "${searchFor}" in "${searchIn}" at index ${matchIndex} is not a string.`);
39
+ }
40
+ /**
41
+ * Don't actually change any text. What we do here doesn't matter because we're not
42
+ * using the output of the .replace method, we're just producing side effects.
43
+ */
44
+ return originalMatch;
45
+ });
46
+ return (includeLength ? indexesAndLengths : indexes);
47
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Generic string type but with the given suffix appended to it.
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 type WithSuffix<Suffix extends string> = `${string}${Suffix}`;
9
+ /**
10
+ * Suffix for {@link addPercent} and {@link removePercent}.
11
+ *
12
+ * @category String
13
+ * @category Package : @augment-vir/common
14
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
15
+ */
16
+ export declare const percentSuffix = "%";
17
+ /**
18
+ * Suffix for {@link addPx} and {@link removePx}.
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 pxSuffix = "px";
25
+ /**
26
+ * Generic string type but with the `'px'` suffix appended to it.
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 type WithPx = WithSuffix<typeof pxSuffix>;
33
+ /**
34
+ * Generic string type but with the `'%'` suffix appended to it.
35
+ *
36
+ * @category String
37
+ * @category Package : @augment-vir/common
38
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
39
+ */
40
+ export type WithPercent = WithSuffix<typeof percentSuffix>;
41
+ /**
42
+ * Adds the `'px'` suffix to a string if it does not already exist.
43
+ *
44
+ * @category String
45
+ * @category Package : @augment-vir/common
46
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
47
+ */
48
+ export declare function addPx(input: number | string): WithPx;
49
+ /**
50
+ * Removes the `'px'` suffix from a string if it exists.
51
+ *
52
+ * @category String
53
+ * @category Package : @augment-vir/common
54
+ * @throws `TypeError` if the input can't be converted into a number.
55
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
56
+ */
57
+ export declare function removePx(input: string): number;
58
+ /**
59
+ * Adds the `'%'` suffix to a string if it does not already exist.
60
+ *
61
+ * @category String
62
+ * @category Package : @augment-vir/common
63
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
64
+ */
65
+ export declare function addPercent(input: number | string): WithPercent;
66
+ /**
67
+ * Removes the `'%'` suffix from a string if it exists.
68
+ *
69
+ * @category String
70
+ * @category Package : @augment-vir/common
71
+ * @throws `TypeError` if the input can't be converted into a number.
72
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
73
+ */
74
+ export declare function removePercent(input: string): number;
75
+ /**
76
+ * Adds a suffix to a string if it does not already exist.
77
+ *
78
+ * @category String
79
+ * @category Package : @augment-vir/common
80
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
81
+ */
82
+ export declare function addSuffix<const Suffix extends string>({ value, suffix, }: {
83
+ value: unknown;
84
+ suffix: Suffix;
85
+ }): WithSuffix<Suffix>;
86
+ /**
87
+ * Removes a suffix from a string if it exists.
88
+ *
89
+ * @category String
90
+ * @category Package : @augment-vir/common
91
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
92
+ */
93
+ export declare function removeSuffix<const Suffix extends string>({ value, suffix, }: {
94
+ value: string;
95
+ suffix: Suffix;
96
+ }): string;