@augment-vir/common 29.2.0 → 30.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/LICENSE-CC0 +121 -0
  2. package/LICENSE-MIT +21 -0
  3. package/dist/augments/array/array-map.d.ts +6 -0
  4. package/dist/augments/array/array-map.js +4 -0
  5. package/dist/augments/array/array-to-object.d.ts +17 -0
  6. package/dist/augments/array/array-to-object.js +31 -0
  7. package/dist/augments/array/awaited/awaited-filter.d.ts +7 -0
  8. package/dist/augments/array/awaited/awaited-filter.js +7 -0
  9. package/dist/augments/array/awaited/awaited-for-each.d.ts +6 -0
  10. package/dist/augments/array/awaited/awaited-for-each.js +9 -0
  11. package/dist/augments/array/awaited/awaited-map.d.ts +1 -0
  12. package/dist/augments/array/awaited/awaited-map.js +8 -0
  13. package/dist/augments/array/filter.d.ts +3 -0
  14. package/dist/augments/array/filter.js +13 -0
  15. package/dist/augments/array/repeat-array.d.ts +1 -0
  16. package/dist/augments/array/repeat-array.js +3 -0
  17. package/dist/augments/array/shuffle-array.d.ts +2 -0
  18. package/dist/augments/array/shuffle-array.js +10 -0
  19. package/dist/augments/array/string-array.d.ts +1 -0
  20. package/dist/augments/array/string-array.js +3 -0
  21. package/dist/augments/boolean/if-truthy.d.ts +2 -0
  22. package/dist/{esm/augments/boolean.js → augments/boolean/if-truthy.js} +2 -7
  23. package/dist/augments/core-exports.d.ts +1 -0
  24. package/dist/augments/core-exports.js +1 -0
  25. package/dist/augments/enum/enum-value-check.d.ts +2 -0
  26. package/dist/augments/enum/enum-value-check.js +4 -0
  27. package/dist/augments/error/combine-errors.d.ts +3 -0
  28. package/dist/augments/error/combine-errors.js +12 -0
  29. package/dist/augments/function/call-asynchronously.d.ts +6 -0
  30. package/dist/augments/function/call-asynchronously.js +7 -0
  31. package/dist/augments/function/call-with-retries.d.ts +4 -0
  32. package/dist/augments/function/call-with-retries.js +27 -0
  33. package/dist/augments/function/debounce.d.ts +22 -0
  34. package/dist/augments/function/debounce.js +50 -0
  35. package/dist/augments/function/execution-duration.d.ts +8 -0
  36. package/dist/{esm/augments/time.js → augments/function/execution-duration.js} +7 -12
  37. package/dist/{types/augments → augments/function}/wrap-in-try.d.ts +2 -3
  38. package/dist/{esm/augments → augments/function}/wrap-in-try.js +4 -4
  39. package/dist/augments/json/append-json.d.ts +5 -0
  40. package/dist/augments/json/append-json.js +26 -0
  41. package/dist/augments/json/copy-through-json.d.ts +3 -0
  42. package/dist/augments/json/copy-through-json.js +11 -0
  43. package/dist/augments/json/jsonify.d.ts +2 -0
  44. package/dist/augments/json/jsonify.js +4 -0
  45. package/dist/augments/log/log-colors.d.ts +23 -0
  46. package/dist/augments/log/log-colors.js +116 -0
  47. package/dist/augments/log/log-string.d.ts +14 -0
  48. package/dist/augments/log/log-string.js +66 -0
  49. package/dist/augments/log/log-writer.d.ts +8 -0
  50. package/dist/augments/log/log.d.ts +13 -0
  51. package/dist/augments/log/log.js +42 -0
  52. package/dist/augments/log/logger.d.ts +11 -0
  53. package/dist/augments/log/logger.js +38 -0
  54. package/dist/augments/number/clamp.d.ts +7 -0
  55. package/dist/augments/number/clamp.js +8 -0
  56. package/dist/augments/number/coords.d.ts +19 -0
  57. package/dist/augments/number/digit.d.ts +1 -0
  58. package/dist/augments/number/dimensions.d.ts +19 -0
  59. package/dist/augments/number/min-max.d.ts +11 -0
  60. package/dist/augments/number/min-max.js +14 -0
  61. package/dist/augments/number/number-conversion.d.ts +23 -0
  62. package/dist/augments/number/number-conversion.js +50 -0
  63. package/dist/augments/number/round.d.ts +3 -0
  64. package/dist/augments/number/round.js +5 -0
  65. package/dist/augments/number/scientific.d.ts +1 -0
  66. package/dist/augments/number/scientific.js +3 -0
  67. package/dist/{esm/augments → augments/number}/truncate-number.js +14 -12
  68. package/dist/augments/number/wrap-number.d.ts +13 -0
  69. package/dist/augments/number/wrap-number.js +22 -0
  70. package/dist/augments/object/diff.d.ts +29 -0
  71. package/dist/augments/object/diff.js +133 -0
  72. package/dist/augments/object/empty.d.ts +3 -0
  73. package/dist/augments/object/get-or-set.d.ts +31 -0
  74. package/dist/{esm/augments → augments}/object/get-or-set.js +5 -3
  75. package/dist/{types/augments → augments}/object/key-count.d.ts +9 -5
  76. package/dist/augments/object/map-entries.d.ts +13 -0
  77. package/dist/augments/object/map-entries.js +57 -0
  78. package/dist/augments/object/map-enum.d.ts +4 -0
  79. package/dist/augments/object/map-enum.js +21 -0
  80. package/dist/{types/augments/object/map-object.d.ts → augments/object/map-values.d.ts} +6 -3
  81. package/dist/{esm/augments/object/map-object.js → augments/object/map-values.js} +9 -9
  82. package/dist/{esm/augments → augments}/object/merge-deep.js +5 -6
  83. package/dist/augments/object/merge-defined-properties.d.ts +6 -0
  84. package/dist/augments/object/merge-defined-properties.js +19 -0
  85. package/dist/{esm/augments → augments}/object/merge-property-arrays.js +1 -1
  86. package/dist/augments/object/object-entries.d.ts +4 -0
  87. package/dist/augments/object/object-entries.js +13 -0
  88. package/dist/augments/object/object-filter.d.ts +2 -0
  89. package/dist/augments/object/object-filter.js +7 -0
  90. package/dist/augments/object/object-keys.d.ts +2 -0
  91. package/dist/augments/object/object-keys.js +11 -0
  92. package/dist/augments/object/object-values.d.ts +2 -0
  93. package/dist/augments/object/object-values.js +4 -0
  94. package/dist/augments/prisma/prisma-models.d.ts +106 -0
  95. package/dist/augments/prisma/prisma-models.js +1 -0
  96. package/dist/augments/promise/timed-promise.d.ts +7 -0
  97. package/dist/augments/promise/timed-promise.js +36 -0
  98. package/dist/augments/random/random-boolean.d.ts +18 -0
  99. package/dist/augments/random/random-boolean.js +26 -0
  100. package/dist/augments/random/random-integer.d.ts +12 -0
  101. package/dist/augments/random/random-integer.js +32 -0
  102. package/dist/augments/random/random-string.d.ts +14 -0
  103. package/dist/augments/random/random-string.js +63 -0
  104. package/dist/{types/augments/regexp.d.ts → augments/regexp/regexp-flags.d.ts} +1 -1
  105. package/dist/augments/regexp/regexp-flags.js +18 -0
  106. package/dist/augments/regexp/regexp-string.d.ts +5 -0
  107. package/dist/augments/regexp/regexp-string.js +7 -0
  108. package/dist/augments/regexp/safe-match.d.ts +1 -0
  109. package/dist/augments/regexp/safe-match.js +4 -0
  110. package/dist/augments/selection-set/select-collapsed.d.ts +11 -0
  111. package/dist/augments/selection-set/select-collapsed.js +25 -0
  112. package/dist/augments/selection-set/select-from.d.ts +3 -0
  113. package/dist/augments/selection-set/select-from.js +25 -0
  114. package/dist/augments/selection-set/selection-set.d.ts +18 -0
  115. package/dist/augments/selection-set/selection-set.js +4 -0
  116. package/dist/augments/string/casing/capitalization.d.ts +3 -0
  117. package/dist/augments/string/casing/capitalization.js +11 -0
  118. package/dist/augments/string/casing/casing.d.ts +27 -0
  119. package/dist/augments/string/casing/casing.js +40 -0
  120. package/dist/augments/string/casing/kebab-and-camel.d.ts +3 -0
  121. package/dist/augments/string/casing/kebab-and-camel.js +42 -0
  122. package/dist/augments/string/commas.d.ts +7 -0
  123. package/dist/augments/string/commas.js +29 -0
  124. package/dist/augments/string/join.d.ts +10 -0
  125. package/dist/augments/string/join.js +23 -0
  126. package/dist/{types/augments/string/prefixes.d.ts → augments/string/prefix.d.ts} +16 -1
  127. package/dist/{esm/augments/string/prefixes.js → augments/string/prefix.js} +11 -1
  128. package/dist/augments/string/replace.d.ts +1 -0
  129. package/dist/augments/string/replace.js +5 -0
  130. package/dist/augments/string/split.d.ts +4 -0
  131. package/dist/augments/string/split.js +28 -0
  132. package/dist/augments/string/substring-index.d.ts +13 -0
  133. package/dist/augments/string/substring-index.js +38 -0
  134. package/dist/augments/string/suffix.d.ts +74 -0
  135. package/dist/augments/string/suffix.js +73 -0
  136. package/dist/augments/string/white-space.d.ts +5 -0
  137. package/dist/augments/string/white-space.js +12 -0
  138. package/dist/augments/string/wrap-string.d.ts +4 -0
  139. package/dist/augments/string/wrap-string.js +5 -0
  140. package/dist/augments/type/ensure-type.d.ts +8 -0
  141. package/dist/augments/type/ensure-type.js +10 -0
  142. package/dist/augments/type/readonly.d.ts +2 -0
  143. package/dist/augments/type/readonly.js +3 -0
  144. package/dist/augments/type/type-recursion.js +1 -0
  145. package/dist/augments/type/void-type.d.ts +5 -0
  146. package/dist/augments/type/void-type.js +1 -0
  147. package/dist/augments/type/writable.d.ts +3 -0
  148. package/dist/augments/type/writable.js +3 -0
  149. package/dist/index.d.ts +81 -0
  150. package/dist/index.js +81 -0
  151. package/package.json +33 -15
  152. package/README.md +0 -7
  153. package/dist/cjs/augments/ansi.js +0 -27
  154. package/dist/cjs/augments/array/array.js +0 -68
  155. package/dist/cjs/augments/array/remove-duplicates.js +0 -16
  156. package/dist/cjs/augments/async.js +0 -28
  157. package/dist/cjs/augments/boolean.js +0 -19
  158. package/dist/cjs/augments/common-number.js +0 -112
  159. package/dist/cjs/augments/common-string.js +0 -245
  160. package/dist/cjs/augments/debounce.js +0 -38
  161. package/dist/cjs/augments/environment.js +0 -6
  162. package/dist/cjs/augments/error.js +0 -52
  163. package/dist/cjs/augments/esm-path.js +0 -11
  164. package/dist/cjs/augments/function.js +0 -2
  165. package/dist/cjs/augments/json-compatible.js +0 -2
  166. package/dist/cjs/augments/json.js +0 -28
  167. package/dist/cjs/augments/object/any-object.js +0 -2
  168. package/dist/cjs/augments/object/enum.js +0 -48
  169. package/dist/cjs/augments/object/filter-object.js +0 -26
  170. package/dist/cjs/augments/object/get-or-set.js +0 -40
  171. package/dist/cjs/augments/object/has-key.js +0 -6
  172. package/dist/cjs/augments/object/jsonify.js +0 -6
  173. package/dist/cjs/augments/object/key-count.js +0 -2
  174. package/dist/cjs/augments/object/map-object.js +0 -61
  175. package/dist/cjs/augments/object/merge-deep.js +0 -52
  176. package/dist/cjs/augments/object/merge-property-arrays.js +0 -14
  177. package/dist/cjs/augments/object/object-entries.js +0 -40
  178. package/dist/cjs/augments/object/object.js +0 -18
  179. package/dist/cjs/augments/object/pick-deep.js +0 -2
  180. package/dist/cjs/augments/object/selection-set.js +0 -56
  181. package/dist/cjs/augments/object/typed-has-property.js +0 -29
  182. package/dist/cjs/augments/promise/deferred-promise.js +0 -31
  183. package/dist/cjs/augments/promise/promise.js +0 -79
  184. package/dist/cjs/augments/promise/wait.js +0 -66
  185. package/dist/cjs/augments/random.js +0 -123
  186. package/dist/cjs/augments/regexp.js +0 -19
  187. package/dist/cjs/augments/string/prefixes.js +0 -20
  188. package/dist/cjs/augments/string/suffixes.js +0 -40
  189. package/dist/cjs/augments/string/uuid.js +0 -7
  190. package/dist/cjs/augments/time.js +0 -35
  191. package/dist/cjs/augments/truncate-number.js +0 -153
  192. package/dist/cjs/augments/tuple.js +0 -20
  193. package/dist/cjs/augments/type-recursion.js +0 -2
  194. package/dist/cjs/augments/type.js +0 -36
  195. package/dist/cjs/augments/union.js +0 -2
  196. package/dist/cjs/augments/wrap-in-try.js +0 -37
  197. package/dist/cjs/index.js +0 -60
  198. package/dist/esm/augments/ansi.js +0 -24
  199. package/dist/esm/augments/array/array.js +0 -57
  200. package/dist/esm/augments/async.js +0 -23
  201. package/dist/esm/augments/common-number.js +0 -100
  202. package/dist/esm/augments/common-string.js +0 -227
  203. package/dist/esm/augments/debounce.js +0 -34
  204. package/dist/esm/augments/environment.js +0 -3
  205. package/dist/esm/augments/error.js +0 -45
  206. package/dist/esm/augments/json.js +0 -24
  207. package/dist/esm/augments/object/enum.js +0 -41
  208. package/dist/esm/augments/object/filter-object.js +0 -21
  209. package/dist/esm/augments/object/has-key.js +0 -3
  210. package/dist/esm/augments/object/jsonify.js +0 -3
  211. package/dist/esm/augments/object/object-entries.js +0 -32
  212. package/dist/esm/augments/object/object.js +0 -14
  213. package/dist/esm/augments/object/selection-set.js +0 -52
  214. package/dist/esm/augments/object/typed-has-property.js +0 -25
  215. package/dist/esm/augments/promise/deferred-promise.js +0 -28
  216. package/dist/esm/augments/promise/promise.js +0 -71
  217. package/dist/esm/augments/promise/wait.js +0 -60
  218. package/dist/esm/augments/random.js +0 -117
  219. package/dist/esm/augments/regexp.js +0 -14
  220. package/dist/esm/augments/string/suffixes.js +0 -31
  221. package/dist/esm/augments/string/uuid.js +0 -4
  222. package/dist/esm/augments/tuple.js +0 -16
  223. package/dist/esm/augments/type.js +0 -30
  224. package/dist/esm/index.js +0 -44
  225. package/dist/types/augments/ansi.d.ts +0 -1
  226. package/dist/types/augments/array/array.d.ts +0 -26
  227. package/dist/types/augments/async.d.ts +0 -14
  228. package/dist/types/augments/boolean.d.ts +0 -6
  229. package/dist/types/augments/common-number.d.ts +0 -52
  230. package/dist/types/augments/common-string.d.ts +0 -74
  231. package/dist/types/augments/debounce.d.ts +0 -15
  232. package/dist/types/augments/environment.d.ts +0 -1
  233. package/dist/types/augments/error.d.ts +0 -9
  234. package/dist/types/augments/function.d.ts +0 -25
  235. package/dist/types/augments/json.d.ts +0 -9
  236. package/dist/types/augments/object/any-object.d.ts +0 -2
  237. package/dist/types/augments/object/enum.d.ts +0 -8
  238. package/dist/types/augments/object/filter-object.d.ts +0 -4
  239. package/dist/types/augments/object/get-or-set.d.ts +0 -26
  240. package/dist/types/augments/object/has-key.d.ts +0 -1
  241. package/dist/types/augments/object/jsonify.d.ts +0 -2
  242. package/dist/types/augments/object/object-entries.d.ts +0 -8
  243. package/dist/types/augments/object/object.d.ts +0 -21
  244. package/dist/types/augments/object/pick-deep.d.ts +0 -14
  245. package/dist/types/augments/object/selection-set.d.ts +0 -27
  246. package/dist/types/augments/object/typed-has-property.d.ts +0 -7
  247. package/dist/types/augments/promise/deferred-promise.d.ts +0 -8
  248. package/dist/types/augments/promise/promise.d.ts +0 -15
  249. package/dist/types/augments/promise/wait.d.ts +0 -18
  250. package/dist/types/augments/random.d.ts +0 -39
  251. package/dist/types/augments/string/suffixes.d.ts +0 -17
  252. package/dist/types/augments/string/uuid.d.ts +0 -1
  253. package/dist/types/augments/time.d.ts +0 -14
  254. package/dist/types/augments/tuple.d.ts +0 -17
  255. package/dist/types/augments/type.d.ts +0 -69
  256. package/dist/types/augments/union.d.ts +0 -5
  257. package/dist/types/index.d.ts +0 -44
  258. /package/dist/{types/augments → augments}/array/remove-duplicates.d.ts +0 -0
  259. /package/dist/{esm/augments → augments}/array/remove-duplicates.js +0 -0
  260. /package/dist/{types/augments → augments/file}/esm-path.d.ts +0 -0
  261. /package/dist/{esm/augments → augments/file}/esm-path.js +0 -0
  262. /package/dist/{types/augments → augments/json}/json-compatible.d.ts +0 -0
  263. /package/dist/{esm/augments → augments/json}/json-compatible.js +0 -0
  264. /package/dist/{esm/augments/function.js → augments/log/log-writer.js} +0 -0
  265. /package/dist/{esm/augments/object/any-object.js → augments/number/coords.js} +0 -0
  266. /package/dist/{esm/augments/object/key-count.js → augments/number/digit.js} +0 -0
  267. /package/dist/{esm/augments/object/pick-deep.js → augments/number/dimensions.js} +0 -0
  268. /package/dist/{types/augments → augments/number}/truncate-number.d.ts +0 -0
  269. /package/dist/{esm/augments/type-recursion.js → augments/object/empty.js} +0 -0
  270. /package/dist/{esm/augments/union.js → augments/object/key-count.js} +0 -0
  271. /package/dist/{types/augments → augments}/object/merge-deep.d.ts +0 -0
  272. /package/dist/{types/augments → augments}/object/merge-property-arrays.d.ts +0 -0
  273. /package/dist/{types/augments → augments/type}/type-recursion.d.ts +0 -0
@@ -0,0 +1,10 @@
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
+ * @param list Array of items to be converted into strings. Works best if these are simply strings
7
+ * to begin with.
8
+ * @param conjunction Defaults to 'and'. The conjunction to be used before the final element.
9
+ */
10
+ export declare function joinWithFinalConjunction(list: ReadonlyArray<any>, conjunction?: string): string;
@@ -0,0 +1,23 @@
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
+ * @param list Array of items to be converted into strings. Works best if these are simply strings
7
+ * to begin with.
8
+ * @param conjunction Defaults to 'and'. The conjunction to be used before the final element.
9
+ */
10
+ export function joinWithFinalConjunction(list, conjunction = 'and') {
11
+ if (list.length < 2) {
12
+ /**
13
+ * If there are not multiple things in the list to join, just turn the list into a string
14
+ * for an empty list, this will be '', for a single item list, this will just be the first
15
+ * item as a string.
16
+ */
17
+ return list.join('');
18
+ }
19
+ /** When there are only two items in the list, we don't want any commas. */
20
+ const commaSep = list.length > 2 ? ', ' : ' ';
21
+ const commaJoined = list.slice(0, -1).join(commaSep);
22
+ return `${commaJoined}${commaSep}${conjunction} ${list[list.length - 1]}`;
23
+ }
@@ -1,9 +1,24 @@
1
+ /**
2
+ * Generic string type but with the given prefix prepended to it.
3
+ *
4
+ * @category String
5
+ */
1
6
  export type WithPrefix<Prefix extends string> = `${Prefix}${string}`;
7
+ /**
8
+ * Adds a prefix to a string if it does not already exist.
9
+ *
10
+ * @category String
11
+ */
2
12
  export declare function addPrefix<const Prefix extends string>({ value, prefix, }: {
3
13
  value: unknown;
4
14
  prefix: Prefix;
5
15
  }): WithPrefix<Prefix>;
16
+ /**
17
+ * Removes a prefix from a string if it exists.
18
+ *
19
+ * @category String
20
+ */
6
21
  export declare function removePrefix<const Prefix extends string>({ value, prefix, }: {
7
- value: WithPrefix<Prefix> | string;
22
+ value: string;
8
23
  prefix: Prefix;
9
24
  }): string;
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Adds a prefix to a string if it does not already exist.
3
+ *
4
+ * @category String
5
+ */
1
6
  export function addPrefix({ value, prefix, }) {
2
7
  if (String(value).startsWith(prefix)) {
3
8
  return String(value);
@@ -6,9 +11,14 @@ export function addPrefix({ value, prefix, }) {
6
11
  return `${prefix}${String(value)}`;
7
12
  }
8
13
  }
14
+ /**
15
+ * Removes a prefix from a string if it exists.
16
+ *
17
+ * @category String
18
+ */
9
19
  export function removePrefix({ value, prefix, }) {
10
20
  if (value.startsWith(prefix)) {
11
- return value.substring(prefix.length);
21
+ return value.slice(prefix.length);
12
22
  }
13
23
  else {
14
24
  return value;
@@ -0,0 +1 @@
1
+ export declare function replaceStringAtIndex(originalString: string, start: number, newString: string, length?: number): string;
@@ -0,0 +1,5 @@
1
+ export function replaceStringAtIndex(originalString, start, newString, length = newString.length) {
2
+ const before = originalString.slice(0, Math.max(0, start));
3
+ const after = originalString.slice(Math.max(0, start + length));
4
+ return `${before}${newString}${after}`;
5
+ }
@@ -0,0 +1,4 @@
1
+ import type { AtLeastTuple } from '@augment-vir/core';
2
+ /** Same as String.prototype.split but includes the delimiter to split by in the output array. */
3
+ export declare function splitIncludeSplit(original: string, splitterInput: string | RegExp, caseSensitive: boolean): readonly string[];
4
+ export declare function safeSplit(input: string, splitString: string): AtLeastTuple<string, 1>;
@@ -0,0 +1,28 @@
1
+ import { makeCaseInsensitiveRegExp } from '../regexp/regexp-flags.js';
2
+ import { getSubstringIndexes } from './substring-index.js';
3
+ /** Same as String.prototype.split but includes the delimiter to split by in the output array. */
4
+ export function splitIncludeSplit(original, splitterInput, caseSensitive) {
5
+ const indexLengths = getSubstringIndexes({
6
+ searchIn: original,
7
+ searchFor: splitterInput,
8
+ caseSensitive,
9
+ includeLength: true,
10
+ });
11
+ const splitter = makeCaseInsensitiveRegExp(splitterInput, caseSensitive);
12
+ const splits = original.split(splitter);
13
+ return splits.reduce((accum, current, index) => {
14
+ // this will be undefined on the last index
15
+ const splitterLength = indexLengths[index];
16
+ const includeCurrent = accum.concat(current);
17
+ if (splitterLength) {
18
+ const splitterMatch = original.slice(splitterLength.index, splitterLength.index + splitterLength.length);
19
+ return includeCurrent.concat(splitterMatch);
20
+ }
21
+ else {
22
+ return includeCurrent;
23
+ }
24
+ }, []);
25
+ }
26
+ export function safeSplit(input, splitString) {
27
+ return input.split(splitString);
28
+ }
@@ -0,0 +1,13 @@
1
+ export declare function getSubstringIndexes<IncludeLength extends boolean | undefined>({ searchIn, searchFor, caseSensitive, includeLength, }: {
2
+ searchIn: string;
3
+ searchFor: string | RegExp;
4
+ /**
5
+ * CaseSensitive only applies when the input is a string. Otherwise, the RegExp's "i" flag is
6
+ * used to determine case sensitivity.
7
+ */
8
+ caseSensitive: boolean;
9
+ includeLength?: IncludeLength;
10
+ }): IncludeLength extends true ? {
11
+ index: number;
12
+ length: number;
13
+ }[] : number[];
@@ -0,0 +1,38 @@
1
+ import { makeCaseInsensitiveRegExp } from '../regexp/regexp-flags.js';
2
+ export function getSubstringIndexes({ searchIn, searchFor, caseSensitive, includeLength, }) {
3
+ const searchRegExp = makeCaseInsensitiveRegExp(searchFor, caseSensitive);
4
+ const indexes = [];
5
+ const indexesAndLengths = [];
6
+ searchIn.replace(searchRegExp, (...matchResults) => {
7
+ /**
8
+ * Grabbing the second to last entry in the array (rather than the second) takes capture
9
+ * groups into account.
10
+ */
11
+ const matchIndex = matchResults[matchResults.length - 2];
12
+ // this is used as a type safety catch and cannot actually be triggered on purpose
13
+ /* node:coverage ignore next 5 */
14
+ if (typeof matchIndex !== 'number') {
15
+ throw new TypeError(`Match index "${matchIndex}" is not a number. Searching for "${searchFor}" in "${searchIn}".`);
16
+ }
17
+ const regExpMatch = matchResults[0];
18
+ // this is used as a type safety catch and cannot actually be triggered on purpose
19
+ /* node:coverage ignore next 5 */
20
+ if (typeof regExpMatch !== 'string') {
21
+ throw new TypeError(`regExpMatch should've been a string but was ${typeof regExpMatch}!`);
22
+ }
23
+ indexesAndLengths.push({ index: matchIndex, length: regExpMatch.length });
24
+ indexes.push(matchIndex);
25
+ const originalMatch = matchResults[0];
26
+ // this is used as a type safety catch and cannot actually be triggered on purpose
27
+ /* node:coverage ignore next 5 */
28
+ if (typeof originalMatch !== 'string') {
29
+ throw new TypeError(`Original match when searching for "${searchFor}" in "${searchIn}" at index ${matchIndex} is not a string.`);
30
+ }
31
+ /**
32
+ * Don't actually change any text. What we do here doesn't matter because we're not
33
+ * using the output of the .replace method, we're just producing side effects.
34
+ */
35
+ return originalMatch;
36
+ });
37
+ return (includeLength ? indexesAndLengths : indexes);
38
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Generic string type but with the given suffix appended to it.
3
+ *
4
+ * @category String
5
+ */
6
+ export type WithSuffix<Suffix extends string> = `${string}${Suffix}`;
7
+ /**
8
+ * Suffix for {@link addPercent} and {@link removePercent}.
9
+ *
10
+ * @category String
11
+ */
12
+ export declare const percentSuffix = "%";
13
+ /**
14
+ * Suffix for {@link addPx} and {@link removePx}.
15
+ *
16
+ * @category String
17
+ */
18
+ export declare const pxSuffix = "px";
19
+ /**
20
+ * Generic string type but with the `'px'` suffix appended to it.
21
+ *
22
+ * @category String
23
+ */
24
+ export type WithPx = WithSuffix<typeof pxSuffix>;
25
+ /**
26
+ * Generic string type but with the `'%'` suffix appended to it.
27
+ *
28
+ * @category String
29
+ */
30
+ export type WithPercent = WithSuffix<typeof percentSuffix>;
31
+ /**
32
+ * Adds the `'px'` suffix to a string if it does not already exist.
33
+ *
34
+ * @category String
35
+ */
36
+ export declare function addPx(input: number | string): WithPx;
37
+ /**
38
+ * Removes the `'px'` suffix from a string if it exists.
39
+ *
40
+ * @category String
41
+ * @throws `TypeError` if the input can't be converted into a number.
42
+ */
43
+ export declare function removePx(input: string): number;
44
+ /**
45
+ * Adds the `'%'` suffix to a string if it does not already exist.
46
+ *
47
+ * @category String
48
+ */
49
+ export declare function addPercent(input: number | string): WithPercent;
50
+ /**
51
+ * Removes the `'%'` suffix from a string if it exists.
52
+ *
53
+ * @category String
54
+ * @throws `TypeError` if the input can't be converted into a number.
55
+ */
56
+ export declare function removePercent(input: string): number;
57
+ /**
58
+ * Adds a suffix to a string if it does not already exist.
59
+ *
60
+ * @category String
61
+ */
62
+ export declare function addSuffix<const Suffix extends string>({ value, suffix, }: {
63
+ value: unknown;
64
+ suffix: Suffix;
65
+ }): WithSuffix<Suffix>;
66
+ /**
67
+ * Removes a suffix from a string if it exists.
68
+ *
69
+ * @category String
70
+ */
71
+ export declare function removeSuffix<const Suffix extends string>({ value, suffix, }: {
72
+ value: string;
73
+ suffix: Suffix;
74
+ }): string;
@@ -0,0 +1,73 @@
1
+ import { toEnsuredNumber } from '../number/number-conversion.js';
2
+ /**
3
+ * Suffix for {@link addPercent} and {@link removePercent}.
4
+ *
5
+ * @category String
6
+ */
7
+ export const percentSuffix = '%';
8
+ /**
9
+ * Suffix for {@link addPx} and {@link removePx}.
10
+ *
11
+ * @category String
12
+ */
13
+ export const pxSuffix = 'px';
14
+ /**
15
+ * Adds the `'px'` suffix to a string if it does not already exist.
16
+ *
17
+ * @category String
18
+ */
19
+ export function addPx(input) {
20
+ return addSuffix({ value: input, suffix: pxSuffix });
21
+ }
22
+ /**
23
+ * Removes the `'px'` suffix from a string if it exists.
24
+ *
25
+ * @category String
26
+ * @throws `TypeError` if the input can't be converted into a number.
27
+ */
28
+ export function removePx(input) {
29
+ return toEnsuredNumber(removeSuffix({ value: input, suffix: pxSuffix }));
30
+ }
31
+ /**
32
+ * Adds the `'%'` suffix to a string if it does not already exist.
33
+ *
34
+ * @category String
35
+ */
36
+ export function addPercent(input) {
37
+ return addSuffix({ value: input, suffix: percentSuffix });
38
+ }
39
+ /**
40
+ * Removes the `'%'` suffix from a string if it exists.
41
+ *
42
+ * @category String
43
+ * @throws `TypeError` if the input can't be converted into a number.
44
+ */
45
+ export function removePercent(input) {
46
+ return toEnsuredNumber(removeSuffix({ value: input, suffix: percentSuffix }));
47
+ }
48
+ /**
49
+ * Adds a suffix to a string if it does not already exist.
50
+ *
51
+ * @category String
52
+ */
53
+ export function addSuffix({ value, suffix, }) {
54
+ if (String(value).endsWith(suffix)) {
55
+ return String(value);
56
+ }
57
+ else {
58
+ return `${String(value)}${suffix}`;
59
+ }
60
+ }
61
+ /**
62
+ * Removes a suffix from a string if it exists.
63
+ *
64
+ * @category String
65
+ */
66
+ export function removeSuffix({ value, suffix, }) {
67
+ if (value.endsWith(suffix)) {
68
+ return value.slice(0, Math.max(0, value.length - suffix.length));
69
+ }
70
+ else {
71
+ return value;
72
+ }
73
+ }
@@ -0,0 +1,5 @@
1
+ import { PartialWithUndefined } from '@augment-vir/core';
2
+ /** Collapse all consecutive white space into just one space and trim surrounding whitespace. */
3
+ export declare function collapseWhiteSpace(input: string, { keepNewLines }?: PartialWithUndefined<{
4
+ keepNewLines: boolean;
5
+ }>): string;
@@ -0,0 +1,12 @@
1
+ /** Collapse all consecutive white space into just one space and trim surrounding whitespace. */
2
+ export function collapseWhiteSpace(input, { keepNewLines } = {}) {
3
+ if (keepNewLines) {
4
+ return input
5
+ .trim()
6
+ .replaceAll(/[^\S\r\n]+/g, ' ')
7
+ .replaceAll(/[^\S\r\n]?\n+[^\S\r\n]?/g, '\n');
8
+ }
9
+ else {
10
+ return input.trim().replaceAll(/\s+/g, ' ');
11
+ }
12
+ }
@@ -0,0 +1,4 @@
1
+ export declare function wrapString({ value, wrapper }: {
2
+ value: string;
3
+ wrapper: string;
4
+ }): string;
@@ -0,0 +1,5 @@
1
+ import { addPrefix } from './prefix.js';
2
+ import { addSuffix } from './suffix.js';
3
+ export function wrapString({ value, wrapper }) {
4
+ return addPrefix({ value: addSuffix({ value, suffix: wrapper }), prefix: wrapper });
5
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This is a type helper that ensures the given input matches the given generic type. The generic is
3
+ * setup in such a way that if it is omitted (which is typically allowed in TypeScript, resulting in
4
+ * the generic being inferred from the inputs), there will actually be a type error. This forces
5
+ * each usage of this function to explicitly specify the generic, thus giving us type safety for the
6
+ * input.
7
+ */
8
+ export declare function ensureType<ExpectedType = never>(input: NoInfer<ExpectedType>): NoInfer<ExpectedType>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This is a type helper that ensures the given input matches the given generic type. The generic is
3
+ * setup in such a way that if it is omitted (which is typically allowed in TypeScript, resulting in
4
+ * the generic being inferred from the inputs), there will actually be a type error. This forces
5
+ * each usage of this function to explicitly specify the generic, thus giving us type safety for the
6
+ * input.
7
+ */
8
+ export function ensureType(input) {
9
+ return input;
10
+ }
@@ -0,0 +1,2 @@
1
+ export type { ReadonlyDeep } from 'type-fest';
2
+ export declare function makeReadonly<T>(input: T): Readonly<T>;
@@ -0,0 +1,3 @@
1
+ export function makeReadonly(input) {
2
+ return input;
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Require that the NonVoid parameter is not void. If it is void, the ErrorType or an error string
3
+ * type is returned. If it not void, the given SuccessType is returned.
4
+ */
5
+ export type RequireNonVoid<NonVoid, SuccessType, ErrorType = 'Input should not be void'> = void extends NonVoid ? (NonVoid extends void ? ErrorType : SuccessType) : SuccessType;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Writable } from 'type-fest';
2
+ export type { Writable, WritableDeep } from 'type-fest';
3
+ export declare function makeWritable<T>(input: T): Writable<T>;
@@ -0,0 +1,3 @@
1
+ export function makeWritable(input) {
2
+ return input;
3
+ }
@@ -0,0 +1,81 @@
1
+ export * from './augments/array/array-map.js';
2
+ export * from './augments/array/array-to-object.js';
3
+ export * from './augments/array/awaited/awaited-filter.js';
4
+ export * from './augments/array/awaited/awaited-for-each.js';
5
+ export * from './augments/array/awaited/awaited-map.js';
6
+ export * from './augments/array/filter.js';
7
+ export * from './augments/array/remove-duplicates.js';
8
+ export * from './augments/array/repeat-array.js';
9
+ export * from './augments/array/shuffle-array.js';
10
+ export * from './augments/array/string-array.js';
11
+ export * from './augments/boolean/if-truthy.js';
12
+ export * from './augments/core-exports.js';
13
+ export * from './augments/enum/enum-value-check.js';
14
+ export * from './augments/error/combine-errors.js';
15
+ export * from './augments/file/esm-path.js';
16
+ export * from './augments/function/call-asynchronously.js';
17
+ export * from './augments/function/call-with-retries.js';
18
+ export * from './augments/function/debounce.js';
19
+ export * from './augments/function/execution-duration.js';
20
+ export * from './augments/function/wrap-in-try.js';
21
+ export * from './augments/json/append-json.js';
22
+ export * from './augments/json/copy-through-json.js';
23
+ export * from './augments/json/json-compatible.js';
24
+ export * from './augments/json/jsonify.js';
25
+ export * from './augments/log/log-colors.js';
26
+ export * from './augments/log/log-string.js';
27
+ export * from './augments/log/log-writer.js';
28
+ export * from './augments/log/log.js';
29
+ export * from './augments/log/logger.js';
30
+ export * from './augments/number/clamp.js';
31
+ export * from './augments/number/coords.js';
32
+ export * from './augments/number/digit.js';
33
+ export * from './augments/number/dimensions.js';
34
+ export * from './augments/number/min-max.js';
35
+ export * from './augments/number/number-conversion.js';
36
+ export * from './augments/number/round.js';
37
+ export * from './augments/number/scientific.js';
38
+ export * from './augments/number/truncate-number.js';
39
+ export * from './augments/number/wrap-number.js';
40
+ export * from './augments/object/diff.js';
41
+ export * from './augments/object/empty.js';
42
+ export * from './augments/object/get-or-set.js';
43
+ export * from './augments/object/key-count.js';
44
+ export * from './augments/object/map-entries.js';
45
+ export * from './augments/object/map-enum.js';
46
+ export * from './augments/object/map-values.js';
47
+ export * from './augments/object/merge-deep.js';
48
+ export * from './augments/object/merge-defined-properties.js';
49
+ export * from './augments/object/merge-property-arrays.js';
50
+ export * from './augments/object/object-entries.js';
51
+ export * from './augments/object/object-filter.js';
52
+ export * from './augments/object/object-keys.js';
53
+ export * from './augments/object/object-values.js';
54
+ export * from './augments/prisma/prisma-models.js';
55
+ export * from './augments/promise/timed-promise.js';
56
+ export * from './augments/random/random-boolean.js';
57
+ export * from './augments/random/random-integer.js';
58
+ export * from './augments/random/random-string.js';
59
+ export * from './augments/regexp/regexp-flags.js';
60
+ export * from './augments/regexp/regexp-string.js';
61
+ export * from './augments/regexp/safe-match.js';
62
+ export * from './augments/selection-set/select-collapsed.js';
63
+ export * from './augments/selection-set/select-from.js';
64
+ export * from './augments/selection-set/selection-set.js';
65
+ export * from './augments/string/casing/capitalization.js';
66
+ export * from './augments/string/casing/casing.js';
67
+ export * from './augments/string/casing/kebab-and-camel.js';
68
+ export * from './augments/string/commas.js';
69
+ export * from './augments/string/join.js';
70
+ export * from './augments/string/prefix.js';
71
+ export * from './augments/string/replace.js';
72
+ export * from './augments/string/split.js';
73
+ export * from './augments/string/substring-index.js';
74
+ export * from './augments/string/suffix.js';
75
+ export * from './augments/string/white-space.js';
76
+ export * from './augments/string/wrap-string.js';
77
+ export * from './augments/type/ensure-type.js';
78
+ export * from './augments/type/readonly.js';
79
+ export * from './augments/type/type-recursion.js';
80
+ export * from './augments/type/void-type.js';
81
+ export * from './augments/type/writable.js';
package/dist/index.js ADDED
@@ -0,0 +1,81 @@
1
+ export * from './augments/array/array-map.js';
2
+ export * from './augments/array/array-to-object.js';
3
+ export * from './augments/array/awaited/awaited-filter.js';
4
+ export * from './augments/array/awaited/awaited-for-each.js';
5
+ export * from './augments/array/awaited/awaited-map.js';
6
+ export * from './augments/array/filter.js';
7
+ export * from './augments/array/remove-duplicates.js';
8
+ export * from './augments/array/repeat-array.js';
9
+ export * from './augments/array/shuffle-array.js';
10
+ export * from './augments/array/string-array.js';
11
+ export * from './augments/boolean/if-truthy.js';
12
+ export * from './augments/core-exports.js';
13
+ export * from './augments/enum/enum-value-check.js';
14
+ export * from './augments/error/combine-errors.js';
15
+ export * from './augments/file/esm-path.js';
16
+ export * from './augments/function/call-asynchronously.js';
17
+ export * from './augments/function/call-with-retries.js';
18
+ export * from './augments/function/debounce.js';
19
+ export * from './augments/function/execution-duration.js';
20
+ export * from './augments/function/wrap-in-try.js';
21
+ export * from './augments/json/append-json.js';
22
+ export * from './augments/json/copy-through-json.js';
23
+ export * from './augments/json/json-compatible.js';
24
+ export * from './augments/json/jsonify.js';
25
+ export * from './augments/log/log-colors.js';
26
+ export * from './augments/log/log-string.js';
27
+ export * from './augments/log/log-writer.js';
28
+ export * from './augments/log/log.js';
29
+ export * from './augments/log/logger.js';
30
+ export * from './augments/number/clamp.js';
31
+ export * from './augments/number/coords.js';
32
+ export * from './augments/number/digit.js';
33
+ export * from './augments/number/dimensions.js';
34
+ export * from './augments/number/min-max.js';
35
+ export * from './augments/number/number-conversion.js';
36
+ export * from './augments/number/round.js';
37
+ export * from './augments/number/scientific.js';
38
+ export * from './augments/number/truncate-number.js';
39
+ export * from './augments/number/wrap-number.js';
40
+ export * from './augments/object/diff.js';
41
+ export * from './augments/object/empty.js';
42
+ export * from './augments/object/get-or-set.js';
43
+ export * from './augments/object/key-count.js';
44
+ export * from './augments/object/map-entries.js';
45
+ export * from './augments/object/map-enum.js';
46
+ export * from './augments/object/map-values.js';
47
+ export * from './augments/object/merge-deep.js';
48
+ export * from './augments/object/merge-defined-properties.js';
49
+ export * from './augments/object/merge-property-arrays.js';
50
+ export * from './augments/object/object-entries.js';
51
+ export * from './augments/object/object-filter.js';
52
+ export * from './augments/object/object-keys.js';
53
+ export * from './augments/object/object-values.js';
54
+ export * from './augments/prisma/prisma-models.js';
55
+ export * from './augments/promise/timed-promise.js';
56
+ export * from './augments/random/random-boolean.js';
57
+ export * from './augments/random/random-integer.js';
58
+ export * from './augments/random/random-string.js';
59
+ export * from './augments/regexp/regexp-flags.js';
60
+ export * from './augments/regexp/regexp-string.js';
61
+ export * from './augments/regexp/safe-match.js';
62
+ export * from './augments/selection-set/select-collapsed.js';
63
+ export * from './augments/selection-set/select-from.js';
64
+ export * from './augments/selection-set/selection-set.js';
65
+ export * from './augments/string/casing/capitalization.js';
66
+ export * from './augments/string/casing/casing.js';
67
+ export * from './augments/string/casing/kebab-and-camel.js';
68
+ export * from './augments/string/commas.js';
69
+ export * from './augments/string/join.js';
70
+ export * from './augments/string/prefix.js';
71
+ export * from './augments/string/replace.js';
72
+ export * from './augments/string/split.js';
73
+ export * from './augments/string/substring-index.js';
74
+ export * from './augments/string/suffix.js';
75
+ export * from './augments/string/white-space.js';
76
+ export * from './augments/string/wrap-string.js';
77
+ export * from './augments/type/ensure-type.js';
78
+ export * from './augments/type/readonly.js';
79
+ export * from './augments/type/type-recursion.js';
80
+ export * from './augments/type/void-type.js';
81
+ export * from './augments/type/writable.js';