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