@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
@@ -1,245 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StringCaseEnum = exports.removeColor = void 0;
4
- exports.joinWithFinalConjunction = joinWithFinalConjunction;
5
- exports.wrapString = wrapString;
6
- exports.removeAnsiEscapeCodes = removeAnsiEscapeCodes;
7
- exports.removeCommasFromNumberString = removeCommasFromNumberString;
8
- exports.collapseWhiteSpace = collapseWhiteSpace;
9
- exports.splitIncludeSplit = splitIncludeSplit;
10
- exports.capitalizeFirstLetter = capitalizeFirstLetter;
11
- exports.kebabCaseToCamelCase = kebabCaseToCamelCase;
12
- exports.hasCase = hasCase;
13
- exports.isCase = isCase;
14
- exports.camelCaseToKebabCase = camelCaseToKebabCase;
15
- exports.replaceStringAtIndex = replaceStringAtIndex;
16
- exports.escapeStringForRegExp = escapeStringForRegExp;
17
- exports.getAllIndexesOf = getAllIndexesOf;
18
- exports.typedSplit = typedSplit;
19
- const ansi_1 = require("./ansi");
20
- const regexp_1 = require("./regexp");
21
- /**
22
- * Join elements into a string with commas separating each value. Add a conjunction before the final
23
- * item in the list. If the array has a length < 2, the conjunction is not added. If the list is
24
- * only of length 2, then no commas are added.
25
- *
26
- * @param list Array of items to be converted into strings. Works best if these are simply strings
27
- * to begin with.
28
- * @param conjunction Defaults to 'and'. The conjunction to be used before the final element.
29
- */
30
- function joinWithFinalConjunction(list, conjunction = 'and') {
31
- if (list.length < 2) {
32
- /**
33
- * If there are not multiple things in the list to join, just turn the list into a string
34
- * for an empty list, this will be '', for a single item list, this will just be the first
35
- * item as a string.
36
- */
37
- return list.join('');
38
- }
39
- /** When there are only two items in the list, we don't want any commas. */
40
- const commaSep = list.length > 2 ? ', ' : ' ';
41
- const commaJoined = list.slice(0, -1).join(commaSep);
42
- const fullyJoined = `${commaJoined}${commaSep}${conjunction} ${list[list.length - 1]}`;
43
- return fullyJoined;
44
- }
45
- /** Wraps `value` on both sides with `wrapper`. */
46
- function wrapString({ value, wrapper }) {
47
- return [
48
- wrapper,
49
- wrapper,
50
- ].join(value);
51
- }
52
- function removeAnsiEscapeCodes(input) {
53
- return input.replace(ansi_1.ansiRegex, '');
54
- }
55
- exports.removeColor = removeAnsiEscapeCodes;
56
- function removeCommasFromNumberString(numberString) {
57
- return numberString.replace(/,/g, '');
58
- }
59
- /** Collapse all consecutive white space into just one space and trim surrounding whitespace. */
60
- function collapseWhiteSpace(input, { keepNewLines } = {}) {
61
- const newLineReplacement = keepNewLines
62
- ? input.replace(/[\s\n]*\n+[\s\n]*/g, '\n')
63
- : // sometimes \n isn't included in \s
64
- input.replace(/\n/g, ' ');
65
- return newLineReplacement
66
- .trim()
67
- .replace(/[^\S\r\n]/g, ' ')
68
- .replace(/\s{2,}/g, ' ');
69
- }
70
- /** Same as String.prototype.split but includes the delimiter to split by in the output array. */
71
- function splitIncludeSplit(original, splitterInput, caseSensitive) {
72
- const indexLengths = getAllIndexesOf({
73
- searchIn: original,
74
- searchFor: splitterInput,
75
- caseSensitive,
76
- includeLength: true,
77
- });
78
- const splitter = makeCaseInsensitiveRegExp(splitterInput, caseSensitive);
79
- const splits = original.split(splitter);
80
- const splitterIncluded = splits.reduce((accum, current, index) => {
81
- // this will be undefined on the last index
82
- const splitterLength = indexLengths[index];
83
- const includeCurrent = accum.concat(current);
84
- if (splitterLength) {
85
- const splitterMatch = original.slice(splitterLength.index, splitterLength.index + splitterLength.length);
86
- return includeCurrent.concat(splitterMatch);
87
- }
88
- else {
89
- return includeCurrent;
90
- }
91
- }, []);
92
- return splitterIncluded;
93
- }
94
- const defaultCasingOptions = {
95
- capitalizeFirstLetter: false,
96
- };
97
- function capitalizeFirstLetter(input) {
98
- if (!input.length) {
99
- return '';
100
- }
101
- const firstLetter = input[0];
102
- return (firstLetter.toUpperCase() + input.slice(1));
103
- }
104
- function maybeCapitalize(input, casingOptions) {
105
- return casingOptions.capitalizeFirstLetter ? capitalizeFirstLetter(input) : input;
106
- }
107
- function kebabCaseToCamelCase(rawKebabCase, casingOptions = defaultCasingOptions) {
108
- const kebabCase = rawKebabCase.toLowerCase();
109
- if (!kebabCase.length) {
110
- return '';
111
- }
112
- const camelCase = kebabCase
113
- .replace(/^-+/, '')
114
- .replace(/-{2,}/g, '-')
115
- .replace(/-(?:.|$)/g, (dashMatch) => {
116
- const letter = dashMatch[1];
117
- if (letter) {
118
- return letter.toUpperCase();
119
- }
120
- else {
121
- return '';
122
- }
123
- });
124
- return maybeCapitalize(camelCase, casingOptions);
125
- }
126
- var StringCaseEnum;
127
- (function (StringCaseEnum) {
128
- StringCaseEnum["Upper"] = "upper";
129
- StringCaseEnum["Lower"] = "lower";
130
- })(StringCaseEnum || (exports.StringCaseEnum = StringCaseEnum = {}));
131
- /** Indicates whether the given string has different lower and upper case variants. */
132
- function hasCase(input) {
133
- return input.toLowerCase() !== input.toUpperCase();
134
- }
135
- /**
136
- * Checks if the given string is exclusively of the specific case.
137
- *
138
- * Note that some characters have no casing, such as punctuation (they have no difference between
139
- * upper and lower casings). By default, those letters always return `true` for this function,
140
- * regardless of which `caseType` is provided. To instead return `false` for any such characters,
141
- * pass in an options object and set blockNoCaseCharacters to true.
142
- */
143
- function isCase(input, caseType, options) {
144
- if (!input && options?.blockNoCaseCharacters) {
145
- return false;
146
- }
147
- for (let letterIndex = 0; letterIndex < input.length; letterIndex++) {
148
- const letter = input[letterIndex] || '';
149
- if (!hasCase(letter)) {
150
- if (options?.blockNoCaseCharacters) {
151
- return false;
152
- }
153
- else {
154
- continue;
155
- }
156
- }
157
- if (caseType === StringCaseEnum.Upper && letter !== letter.toUpperCase()) {
158
- return false;
159
- }
160
- else if (caseType === StringCaseEnum.Lower && letter !== letter.toLowerCase()) {
161
- return false;
162
- }
163
- }
164
- return true;
165
- }
166
- function camelCaseToKebabCase(rawCamelCase) {
167
- const kebabCase = rawCamelCase
168
- .split('')
169
- .reduce((accum, currentLetter, index, originalString) => {
170
- const previousLetter = index > 0 ? originalString[index - 1] || '' : '';
171
- const nextLetter = index < originalString.length - 1 ? originalString[index + 1] || '' : '';
172
- const possibleWordBoundary = isCase(previousLetter, StringCaseEnum.Lower, { blockNoCaseCharacters: true }) ||
173
- isCase(nextLetter, StringCaseEnum.Lower, { blockNoCaseCharacters: true });
174
- if (currentLetter === currentLetter.toLowerCase() ||
175
- index === 0 ||
176
- !possibleWordBoundary) {
177
- accum += currentLetter;
178
- }
179
- else {
180
- accum += `-${currentLetter.toLowerCase()}`;
181
- }
182
- return accum;
183
- }, '')
184
- .toLowerCase();
185
- return kebabCase;
186
- }
187
- function replaceStringAtIndex(originalString, start, newString, length = newString.length) {
188
- const before = originalString.substring(0, start);
189
- const after = originalString.substring(start + length);
190
- return `${before}${newString}${after}`;
191
- }
192
- /**
193
- * Escapes characters from the given string so that it can be used within a RegExp without being
194
- * parsed as RegExp syntax.
195
- */
196
- function escapeStringForRegExp(input) {
197
- return input.replace(/[\^$\\.*+?()[\]{}|]/g, '\\$&');
198
- }
199
- function makeCaseInsensitiveRegExp(searchForInput, caseSensitive) {
200
- const regExpFlags = `g${!caseSensitive && typeof searchForInput === 'string' ? 'i' : ''}`;
201
- const searchFor = searchForInput instanceof RegExp
202
- ? new RegExp(searchForInput.source, (0, regexp_1.deDupeRegExFlags)(`${searchForInput.flags}${regExpFlags}`))
203
- : new RegExp(escapeStringForRegExp(searchForInput), regExpFlags);
204
- return searchFor;
205
- }
206
- function getAllIndexesOf({ searchIn, searchFor, caseSensitive, includeLength, }) {
207
- const searchRegExp = makeCaseInsensitiveRegExp(searchFor, caseSensitive);
208
- const indexes = [];
209
- const indexesAndLengths = [];
210
- searchIn.replace(searchRegExp, (...matchResults) => {
211
- /**
212
- * Grabbing the second to last entry in the array (rather than the second) takes capture
213
- * groups into account.
214
- */
215
- const matchIndex = matchResults[matchResults.length - 2];
216
- // this is used as a type safety catch and cannot actually be triggered on purpose
217
- // istanbul ignore next
218
- if (typeof matchIndex !== 'number') {
219
- throw new Error(`Match index "${matchIndex}" is not a number. Searching for "${searchFor}" in "${searchIn}".`);
220
- }
221
- const regExpMatch = matchResults[0];
222
- // this is used as a type safety catch and cannot actually be triggered on purpose
223
- // istanbul ignore next
224
- if (typeof regExpMatch !== 'string') {
225
- throw new Error(`regExpMatch should've been a string but was ${typeof regExpMatch}!`);
226
- }
227
- indexesAndLengths.push({ index: matchIndex, length: regExpMatch.length });
228
- indexes.push(matchIndex);
229
- const originalMatch = matchResults[0];
230
- // this is used as a type safety catch and cannot actually be triggered on purpose
231
- // istanbul ignore next
232
- if (typeof originalMatch !== 'string') {
233
- throw new Error(`Original match when searching for "${searchFor}" in "${searchIn}" at index ${matchIndex} is not a string.`);
234
- }
235
- /**
236
- * Don't actually change any text. What we do here doesn't matter because we're not
237
- * using the output of the .replace method, we're just producing side effects.
238
- */
239
- return originalMatch;
240
- });
241
- return (includeLength ? indexesAndLengths : indexes);
242
- }
243
- function typedSplit(input, splitString) {
244
- return input.split(splitString);
245
- }
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DebounceStyle = void 0;
4
- exports.createDebounce = createDebounce;
5
- var DebounceStyle;
6
- (function (DebounceStyle) {
7
- /**
8
- * Fires on the first call, then waits the given amount of milliseconds until a subsequent call
9
- * can be made.
10
- */
11
- DebounceStyle["FirstThenWait"] = "first-then-wait";
12
- /**
13
- * Waits the given amount of milliseconds after the first call and then fires the latest
14
- * assigned callback.
15
- */
16
- DebounceStyle["AfterWait"] = "after-wait";
17
- })(DebounceStyle || (exports.DebounceStyle = DebounceStyle = {}));
18
- function createDebounce(debounceStyle, debounceDuration) {
19
- let nextCallTimestamp = 0;
20
- let latestCallback = undefined;
21
- return (callback) => {
22
- latestCallback = callback;
23
- const now = Date.now();
24
- if (nextCallTimestamp > now) {
25
- return;
26
- }
27
- if (debounceStyle === DebounceStyle.FirstThenWait) {
28
- latestCallback();
29
- }
30
- else if (debounceStyle === DebounceStyle.AfterWait) {
31
- setTimeout(() => {
32
- /** Use whatever the latest latestCallback is. */
33
- latestCallback?.();
34
- }, debounceDuration.milliseconds);
35
- }
36
- nextCallTimestamp = now + debounceDuration.milliseconds;
37
- };
38
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBrowser = isBrowser;
4
- function isBrowser() {
5
- return typeof window !== 'undefined';
6
- }
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.combineErrors = combineErrors;
4
- exports.combineErrorMessages = combineErrorMessages;
5
- exports.extractErrorMessage = extractErrorMessage;
6
- exports.ensureError = ensureError;
7
- exports.ensureErrorAndPrependMessage = ensureErrorAndPrependMessage;
8
- const boolean_1 = require("./boolean");
9
- const typed_has_property_1 = require("./object/typed-has-property");
10
- function combineErrors(errors) {
11
- if (!errors || errors.length === 0) {
12
- return undefined;
13
- }
14
- const firstError = errors[0];
15
- if (errors.length === 1 && firstError) {
16
- return firstError;
17
- }
18
- return new Error(errors.map((error) => extractErrorMessage(error).trim()).join('\n'));
19
- }
20
- function combineErrorMessages(errors) {
21
- if (!errors) {
22
- return '';
23
- }
24
- return errors.map(extractErrorMessage).filter(boolean_1.isTruthy).join('\n');
25
- }
26
- function extractErrorMessage(maybeError) {
27
- if (!maybeError) {
28
- return '';
29
- }
30
- if (maybeError instanceof Error) {
31
- return maybeError.message;
32
- }
33
- else if ((0, typed_has_property_1.typedHasProperty)(maybeError, 'message')) {
34
- return String(maybeError.message);
35
- }
36
- else {
37
- return String(maybeError);
38
- }
39
- }
40
- function ensureError(maybeError) {
41
- if (maybeError instanceof Error) {
42
- return maybeError;
43
- }
44
- else {
45
- return new Error(extractErrorMessage(maybeError));
46
- }
47
- }
48
- function ensureErrorAndPrependMessage(maybeError, prependMessage) {
49
- const error = ensureError(maybeError);
50
- error.message = `${prependMessage}: ${error.message}`;
51
- return error;
52
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEsmPath = getEsmPath;
4
- function getEsmPath(importMeta) {
5
- const filePath = new URL('', importMeta.url).pathname;
6
- const dirPath = new URL('.', importMeta.url).pathname;
7
- return {
8
- filePath,
9
- dirPath,
10
- };
11
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseJson = parseJson;
4
- exports.stringifyJson = stringifyJson;
5
- const wrap_in_try_1 = require("./wrap-in-try");
6
- function parseJson({ jsonString, errorHandler, }) {
7
- try {
8
- const parsedJson = JSON.parse(jsonString);
9
- return parsedJson;
10
- }
11
- catch (error) {
12
- if (errorHandler) {
13
- return errorHandler(error);
14
- }
15
- else {
16
- throw error;
17
- }
18
- }
19
- }
20
- function stringifyJson(jsonValue, { whitespace, ...tryOptions } = {}) {
21
- const result = (0, wrap_in_try_1.wrapInTry)(() => JSON.stringify(jsonValue, undefined, whitespace), tryOptions);
22
- if (result instanceof Error) {
23
- throw result;
24
- }
25
- else {
26
- return result;
27
- }
28
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEnumTypedKeys = getEnumTypedKeys;
4
- exports.getEnumTypedValues = getEnumTypedValues;
5
- exports.isEnumValue = isEnumValue;
6
- exports.ensureEnum = ensureEnum;
7
- exports.filterToEnumValues = filterToEnumValues;
8
- const object_entries_1 = require("./object-entries");
9
- function getEnumTypedKeys(input) {
10
- // enum keys are always strings
11
- return (0, object_entries_1.getObjectTypedKeys)(input).filter((key) => isNaN(Number(key)));
12
- }
13
- function getEnumTypedValues(input) {
14
- const keys = getEnumTypedKeys(input);
15
- return keys.map((key) => input[key]);
16
- }
17
- /** Check if the given value is within the given enum. */
18
- function isEnumValue(input, checkEnum) {
19
- return getEnumTypedValues(checkEnum).includes(input);
20
- }
21
- /** Interpret a primitive as an enum value with type safety. */
22
- function ensureEnum(value, checkEnum) {
23
- if (isEnumValue(value, checkEnum)) {
24
- return value;
25
- }
26
- else {
27
- const enumValues = getEnumTypedValues(checkEnum);
28
- throw new Error(`Given value '${value}' does not match given enum. Possible enum values: ${enumValues.join(',')}`);
29
- }
30
- }
31
- function filterToEnumValues(inputs, checkEnum, caseInsensitive = false) {
32
- if (caseInsensitive) {
33
- return inputs.reduce((accum, currentInput) => {
34
- const matchedEnumValue = getEnumTypedValues(checkEnum).find((actualEnumValue) => {
35
- return String(actualEnumValue).toUpperCase() === String(currentInput).toUpperCase();
36
- });
37
- if (matchedEnumValue) {
38
- return accum.concat(matchedEnumValue);
39
- }
40
- else {
41
- return accum;
42
- }
43
- }, []);
44
- }
45
- else {
46
- return inputs.filter((input) => isEnumValue(input, checkEnum));
47
- }
48
- }
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filterObject = filterObject;
4
- exports.omitObjectKeys = omitObjectKeys;
5
- exports.pickObjectKeys = pickObjectKeys;
6
- const object_entries_1 = require("./object-entries");
7
- function filterObject(inputObject, callback) {
8
- const filteredKeys = (0, object_entries_1.getObjectTypedKeys)(inputObject).filter((key) => {
9
- const value = inputObject[key];
10
- return callback(key, value, inputObject);
11
- });
12
- return filteredKeys.reduce((accum, key) => {
13
- accum[key] = inputObject[key];
14
- return accum;
15
- }, {});
16
- }
17
- function omitObjectKeys(inputObject, omitTheseKeys) {
18
- return filterObject(inputObject, (currentKey) => {
19
- return !omitTheseKeys.includes(currentKey);
20
- });
21
- }
22
- function pickObjectKeys(inputObject, pickTheseKeys) {
23
- return filterObject(inputObject, (currentKey) => {
24
- return pickTheseKeys.includes(currentKey);
25
- });
26
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOrSetFromMap = getOrSetFromMap;
4
- exports.getOrSet = getOrSet;
5
- const run_time_assertions_1 = require("run-time-assertions");
6
- function getOrSetFromMap(map, key, createNewValueCallback) {
7
- const mapKey = key;
8
- if (map.has(mapKey)) {
9
- return map.get(mapKey);
10
- }
11
- else {
12
- const newValue = createNewValueCallback();
13
- map.set(mapKey, newValue);
14
- return newValue;
15
- }
16
- }
17
- function getOrSet(originalObject, key, createCallback) {
18
- if (key in originalObject) {
19
- return originalObject[key];
20
- }
21
- else {
22
- const createdValue = createCallback();
23
- if ((0, run_time_assertions_1.isPromise)(createdValue)) {
24
- return new Promise(async (resolve, reject) => {
25
- try {
26
- const awaitedValue = await createdValue;
27
- originalObject[key] = awaitedValue;
28
- resolve(awaitedValue);
29
- }
30
- catch (error) {
31
- reject(error);
32
- }
33
- });
34
- }
35
- else {
36
- originalObject[key] = createdValue;
37
- return createdValue;
38
- }
39
- }
40
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasKey = hasKey;
4
- function hasKey(parent, property) {
5
- return property in parent;
6
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsonify = jsonify;
4
- function jsonify(input) {
5
- return JSON.parse(JSON.stringify(input));
6
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapObjectValuesSync = mapObjectValuesSync;
4
- exports.mapObjectValues = mapObjectValues;
5
- const object_entries_1 = require("./object-entries");
6
- /**
7
- * Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
8
- * that this will not wrap the return value in a promise if any of the new object values are
9
- * promises. This function also requires currying in order to get the types correct. This allows you
10
- * to explicitly state the return type.
11
- *
12
- * @example
13
- * mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback);
14
- */
15
- function mapObjectValuesSync(inputObject) {
16
- function innerMap(mapCallback) {
17
- const mappedObject = (0, object_entries_1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => {
18
- const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
19
- return {
20
- ...accum,
21
- [currentKey]: mappedValue,
22
- };
23
- }, {});
24
- return mappedObject;
25
- }
26
- return innerMap;
27
- }
28
- /**
29
- * Creates a new object with the same properties as the input object, but with values set to the
30
- * result of mapCallback for each property.
31
- */
32
- function mapObjectValues(inputObject, mapCallback) {
33
- let gotAPromise = false;
34
- const mappedObject = (0, object_entries_1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => {
35
- const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
36
- if (mappedValue instanceof Promise) {
37
- gotAPromise = true;
38
- }
39
- return {
40
- ...accum,
41
- [currentKey]: mappedValue,
42
- };
43
- }, {});
44
- if (gotAPromise) {
45
- return new Promise(async (resolve, reject) => {
46
- try {
47
- await Promise.all((0, object_entries_1.getObjectTypedKeys)(mappedObject).map(async (key) => {
48
- const value = await mappedObject[key];
49
- mappedObject[key] = value;
50
- }));
51
- resolve(mappedObject);
52
- }
53
- catch (error) {
54
- reject(error);
55
- }
56
- });
57
- }
58
- else {
59
- return mappedObject;
60
- }
61
- }
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeDeep = mergeDeep;
4
- const run_time_assertions_1 = require("run-time-assertions");
5
- const tuple_1 = require("../tuple");
6
- /**
7
- * Accepts multiple objects and merges their key-value pairs recursively. Any values set to
8
- * undefined will be removed.
9
- *
10
- * Note that order matters! Each input object will overwrite the properties of the previous objects.
11
- */
12
- function mergeDeep(...inputs) {
13
- if (!(0, tuple_1.isLengthAtLeast)(inputs, 1)) {
14
- // nothing to merge if no inputs
15
- return {};
16
- }
17
- if (inputs.length === 1) {
18
- // nothing to merge if only one input
19
- return inputs[0];
20
- }
21
- let result = undefined;
22
- const mergeProps = {};
23
- inputs.forEach((individualInput) => {
24
- if (!(0, run_time_assertions_1.isRunTimeType)(individualInput, 'object')) {
25
- /** If not an object, we can't merge. So overwrite instead. */
26
- result = individualInput;
27
- return;
28
- }
29
- else if (!(0, run_time_assertions_1.isRunTimeType)(result, 'object')) {
30
- /** If result isn't an object then we need to make it into one. */
31
- result = { ...individualInput };
32
- }
33
- Object.entries(individualInput).forEach(([key, value,]) => {
34
- if (!mergeProps[key]) {
35
- mergeProps[key] = [];
36
- }
37
- mergeProps[key].push(value);
38
- });
39
- });
40
- if ((0, run_time_assertions_1.isRunTimeType)(result, 'object')) {
41
- Object.entries(mergeProps).forEach(([key, mergeValues,]) => {
42
- const newValue = mergeDeep(...mergeValues);
43
- if (newValue === undefined && key in result) {
44
- delete result[key];
45
- }
46
- else if (newValue !== undefined) {
47
- result[key] = newValue;
48
- }
49
- });
50
- }
51
- return result;
52
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergePropertyArrays = mergePropertyArrays;
4
- const get_or_set_1 = require("./get-or-set");
5
- function mergePropertyArrays(...inputs) {
6
- const combined = {};
7
- inputs.forEach((input) => {
8
- Object.entries(input).forEach(([key, newArray,]) => {
9
- const currentArray = (0, get_or_set_1.getOrSet)(combined, key, () => []);
10
- currentArray.push(...newArray);
11
- });
12
- });
13
- return combined;
14
- }