@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
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultWaitUntilDefinedOptions = void 0;
4
- exports.wait = wait;
5
- exports.waitValue = waitValue;
6
- exports.waitUntilTruthy = waitUntilTruthy;
7
- const error_1 = require("../error");
8
- const deferred_promise_1 = require("./deferred-promise");
9
- function wait(delayMs) {
10
- const deferredPromiseWrapper = (0, deferred_promise_1.createDeferredPromiseWrapper)();
11
- if (delayMs !== Infinity) {
12
- setTimeout(() => {
13
- deferredPromiseWrapper.resolve();
14
- }, delayMs <= 0 ? 0 : delayMs);
15
- }
16
- return deferredPromiseWrapper.promise;
17
- }
18
- async function waitValue(delayMs, returnValue) {
19
- return wait(delayMs).then(() => returnValue);
20
- }
21
- exports.defaultWaitUntilDefinedOptions = {
22
- interval: {
23
- milliseconds: 100,
24
- },
25
- timeout: {
26
- milliseconds: 10_000,
27
- },
28
- };
29
- /**
30
- * Runs the predicate until it returns a truthy value, then returns that value. Use the options
31
- * input to modify the timeout and interval durations. Automatically catches errors and handles
32
- * async predicates.
33
- */
34
- async function waitUntilTruthy(predicate, failureMessage, optionsInput = {}) {
35
- const options = {
36
- ...exports.defaultWaitUntilDefinedOptions,
37
- ...optionsInput,
38
- };
39
- let lastValue = undefined;
40
- let lastError;
41
- async function checkCondition() {
42
- try {
43
- lastValue = await predicate();
44
- }
45
- catch (error) {
46
- lastValue = undefined;
47
- lastError = error;
48
- }
49
- }
50
- const startTime = Date.now();
51
- while (!lastValue) {
52
- await checkCondition();
53
- await wait(options.interval.milliseconds);
54
- if (Date.now() - startTime >= options.timeout.milliseconds) {
55
- const message = failureMessage ? `${failureMessage}: ` : '';
56
- const preMessage = `${message}Timeout of "${options.timeout.milliseconds}" exceeded waiting for value to be defined`;
57
- if (lastError) {
58
- throw (0, error_1.ensureErrorAndPrependMessage)(lastError, preMessage);
59
- }
60
- else {
61
- throw new Error(preMessage);
62
- }
63
- }
64
- }
65
- return lastValue;
66
- }
@@ -1,123 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomInteger = randomInteger;
4
- exports.randomBoolean = randomBoolean;
5
- exports.createUuid = createUuid;
6
- exports.randomString = randomString;
7
- const common_number_1 = require("./common-number");
8
- function accessCrypto() {
9
- if (globalThis.crypto) {
10
- return globalThis.crypto;
11
- }
12
- else {
13
- return require('crypto').webcrypto;
14
- }
15
- }
16
- const crypto = accessCrypto();
17
- /**
18
- * Creates a random integer (decimal points are all cut off) between the given min and max
19
- * (inclusive).
20
- *
21
- * This function uses cryptographically secure randomness.
22
- */
23
- function randomInteger({ min: rawMin, max: rawMax }) {
24
- const { min, max } = (0, common_number_1.ensureMinAndMax)({ min: Math.floor(rawMin), max: Math.floor(rawMax) });
25
- const range = max - min + 1;
26
- const neededByteCount = Math.ceil(Math.log2(range) / 8);
27
- const cutoff = Math.floor(256 ** neededByteCount / range) * range;
28
- const currentBytes = new Uint8Array(neededByteCount);
29
- let value;
30
- do {
31
- crypto.getRandomValues(currentBytes);
32
- value = currentBytes.reduce((accum, byte, index) => {
33
- return accum + byte * 256 ** index;
34
- }, 0);
35
- } while (value >= cutoff);
36
- return min + (value % range);
37
- }
38
- /**
39
- * Returns true at rate of the percentLikelyToBeTrue input. Inputs should be whole numbers which
40
- * will be treated like percents. Anything outside of 0-100 inclusively will be clamped. An input 0
41
- * will always return true. An input of 100 will always return true. Decimals on the input will be
42
- * chopped off, use whole numbers.
43
- *
44
- * This function uses cryptographically secure randomness.
45
- *
46
- * @example
47
- * randomBoolean(50); // 50% chance to return true
48
- *
49
- * @example
50
- * randomBoolean(0); // always false, 0% chance of being true
51
- *
52
- * @example
53
- * randomBoolean(100); // always true, 100% chance of being true
54
- *
55
- * @example
56
- * randomBoolean(59.67; // 59% chance of being true
57
- */
58
- function randomBoolean(percentLikelyToBeTrue = 50) {
59
- return (randomInteger({ min: 0, max: 99 }) <
60
- (0, common_number_1.clamp)({
61
- value: Math.floor(percentLikelyToBeTrue),
62
- min: 0,
63
- max: 100,
64
- }));
65
- }
66
- /** Creates a cryptographically secure uuid. */
67
- function createUuid() {
68
- return crypto.randomUUID();
69
- }
70
- const validStringCharacters = [
71
- 'a',
72
- 'b',
73
- 'c',
74
- 'd',
75
- 'e',
76
- 'f',
77
- 'g',
78
- 'h',
79
- 'i',
80
- 'j',
81
- 'k',
82
- 'l',
83
- 'm',
84
- 'n',
85
- 'o',
86
- 'p',
87
- 'q',
88
- 'r',
89
- 's',
90
- 't',
91
- 'u',
92
- 'v',
93
- 'w',
94
- 'x',
95
- 'y',
96
- 'z',
97
- 0,
98
- 1,
99
- 2,
100
- 3,
101
- 4,
102
- 5,
103
- 6,
104
- 7,
105
- 8,
106
- 9,
107
- ];
108
- /**
109
- * Creates a random string (including letters and numbers) of a given length.
110
- *
111
- * This function uses cryptographically secure randomness.
112
- */
113
- function randomString(inputLength = 16) {
114
- let stringBuilder = '';
115
- for (let i = 0; i < inputLength; i++) {
116
- const index = randomInteger({
117
- min: 0,
118
- max: validStringCharacters.length - 1,
119
- });
120
- stringBuilder += validStringCharacters[index];
121
- }
122
- return stringBuilder;
123
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deDupeRegExFlags = deDupeRegExFlags;
4
- exports.addRegExpFlags = addRegExpFlags;
5
- exports.safeMatch = safeMatch;
6
- function deDupeRegExFlags(flags) {
7
- const deDuped = new Set(Array.from(flags.toLowerCase()));
8
- return Array.from(deDuped).join('');
9
- }
10
- function addRegExpFlags(originalRegExp, flags) {
11
- return new RegExp(originalRegExp.source, deDupeRegExFlags([
12
- originalRegExp.flags,
13
- flags,
14
- ].join('')));
15
- }
16
- function safeMatch(input, regExp) {
17
- const match = input.match(regExp);
18
- return match ?? [];
19
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addPrefix = addPrefix;
4
- exports.removePrefix = removePrefix;
5
- function addPrefix({ value, prefix, }) {
6
- if (String(value).startsWith(prefix)) {
7
- return String(value);
8
- }
9
- else {
10
- return `${prefix}${String(value)}`;
11
- }
12
- }
13
- function removePrefix({ value, prefix, }) {
14
- if (value.startsWith(prefix)) {
15
- return value.substring(prefix.length);
16
- }
17
- else {
18
- return value;
19
- }
20
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pxSuffix = exports.percentSuffix = void 0;
4
- exports.addPx = addPx;
5
- exports.removePx = removePx;
6
- exports.addPercent = addPercent;
7
- exports.removePercent = removePercent;
8
- exports.addSuffix = addSuffix;
9
- exports.removeSuffix = removeSuffix;
10
- const common_number_1 = require("../common-number");
11
- exports.percentSuffix = '%';
12
- exports.pxSuffix = 'px';
13
- function addPx(input) {
14
- return addSuffix({ value: input, suffix: exports.pxSuffix });
15
- }
16
- function removePx(input) {
17
- return (0, common_number_1.toEnsuredNumber)(removeSuffix({ value: input, suffix: exports.pxSuffix }));
18
- }
19
- function addPercent(input) {
20
- return addSuffix({ value: input, suffix: exports.percentSuffix });
21
- }
22
- function removePercent(input) {
23
- return (0, common_number_1.toEnsuredNumber)(removeSuffix({ value: input, suffix: exports.percentSuffix }));
24
- }
25
- function addSuffix({ value, suffix, }) {
26
- if (String(value).endsWith(suffix)) {
27
- return String(value);
28
- }
29
- else {
30
- return `${String(value)}${suffix}`;
31
- }
32
- }
33
- function removeSuffix({ value, suffix, }) {
34
- if (value.endsWith(suffix)) {
35
- return value.substring(0, value.length - suffix.length);
36
- }
37
- else {
38
- return value;
39
- }
40
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUuid = isUuid;
4
- const uuidRegExp = /[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}/;
5
- function isUuid(maybeUuid) {
6
- return !!maybeUuid.match(uuidRegExp);
7
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.measureCallbackDuration = void 0;
4
- exports.timeCallback = timeCallback;
5
- /**
6
- * Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
7
- * switches to async mode and awaits callbacks if they return a promise (otherwise this function is
8
- * purely synchronous).
9
- */
10
- function timeCallback(callback) {
11
- const startTime = Date.now();
12
- const result = callback();
13
- if (result instanceof Promise) {
14
- return new Promise(async (resolve, reject) => {
15
- try {
16
- await result;
17
- const endTime = Date.now();
18
- resolve(endTime - startTime);
19
- }
20
- catch (caught) {
21
- reject(caught);
22
- }
23
- });
24
- }
25
- const endTime = Date.now();
26
- return (endTime - startTime);
27
- }
28
- /**
29
- * Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
30
- * switches to async mode and awaits callbacks if they return a promise (otherwise this function is
31
- * purely synchronous).
32
- *
33
- * Alias of timeCallback.
34
- */
35
- exports.measureCallbackDuration = timeCallback;
@@ -1,153 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.truncateNumber = truncateNumber;
4
- const common_number_1 = require("./common-number");
5
- const common_string_1 = require("./common-string");
6
- const regexp_1 = require("./regexp");
7
- const defaultTruncationSuffixes = [
8
- 'k', // thousand
9
- 'M', // million
10
- 'B', // billion
11
- 'T', // trillion
12
- 'P', // peta-, quadrillion
13
- 'E', // exa- quintillion
14
- 'Z', // zetta- sextillion
15
- 'Y', // yotta- septillion
16
- ];
17
- function combineBeforeAndAfterDot({ beforeDot, afterDot = '', maxLength, }) {
18
- if (afterDot.length) {
19
- const allowedAfterDotLength = maxLength -
20
- beforeDot.length -
21
- // 1 for the period
22
- 1;
23
- if (allowedAfterDotLength > 0) {
24
- const slicedAfterDot = afterDot.slice(0, allowedAfterDotLength);
25
- // if slicedAfterDot is just a bunch of 0
26
- if (!Number(slicedAfterDot)) {
27
- return beforeDot;
28
- }
29
- return [
30
- beforeDot,
31
- slicedAfterDot,
32
- ].join('.');
33
- }
34
- }
35
- return beforeDot;
36
- }
37
- function truncateBigNumber(numberAsString, suffixes, maxLength) {
38
- const [beforeDot, afterDot,] = (0, common_string_1.typedSplit)(numberAsString, '.');
39
- const withCommas = (0, common_number_1.addCommasToNumber)(beforeDot);
40
- const truncationDepth = (0, regexp_1.safeMatch)(withCommas, /,/g).length;
41
- const suffix = suffixes[truncationDepth - 1];
42
- const [beforeComma, afterComma,] = (0, common_string_1.typedSplit)(withCommas, ',');
43
- const trailing = [
44
- afterComma,
45
- afterDot,
46
- ].join('');
47
- if (beforeComma.length + 1 > maxLength) {
48
- // will look like 0.9M
49
- const minimumString = [
50
- '0.',
51
- beforeComma[0],
52
- suffixes[truncationDepth],
53
- ].join('');
54
- return minimumString;
55
- }
56
- else {
57
- const combined = combineBeforeAndAfterDot({
58
- beforeDot: beforeComma,
59
- afterDot: trailing,
60
- maxLength: maxLength - 1 /* -1 to account for the suffix*/,
61
- });
62
- return [
63
- combined,
64
- suffix,
65
- ].join('');
66
- }
67
- }
68
- const minScientificNotationLength = '1e+'.length;
69
- function truncateScientificNotation({ input, maxLength, }) {
70
- const valueString = String(input);
71
- const [beforeExponent, rawExponent,] = (0, common_string_1.typedSplit)(valueString, 'e');
72
- const exponent = rawExponent.replace(/^[\-\+]/, '');
73
- const plusOrMinus = rawExponent[0];
74
- const eSuffix = [
75
- 'e',
76
- plusOrMinus,
77
- exponent,
78
- ].join('');
79
- const [beforeDot, afterDot,] = (0, common_string_1.typedSplit)(beforeExponent, '.');
80
- const minLength = exponent.length + minScientificNotationLength;
81
- if (minLength === maxLength) {
82
- // this will look like "4e+4" or "5e-234"
83
- return [
84
- beforeDot,
85
- eSuffix,
86
- ].join('');
87
- }
88
- else if (minLength > maxLength) {
89
- // in this case the number is either way too big or way to small for its exponent to fit within the max length so we just jump to 0 or Infinity
90
- if (plusOrMinus === '-') {
91
- return '0';
92
- }
93
- else {
94
- return String(Infinity);
95
- }
96
- }
97
- else {
98
- // in this case we have room to add some decimal values to the number
99
- const beforeE = combineBeforeAndAfterDot({
100
- afterDot,
101
- beforeDot,
102
- maxLength: maxLength - exponent.length + minScientificNotationLength,
103
- });
104
- return [
105
- beforeE,
106
- eSuffix,
107
- ].join('');
108
- }
109
- }
110
- function handleSmallNumbers(numberAsString, maxLength) {
111
- const [beforeDot, afterDot,] = (0, common_string_1.typedSplit)((0, common_number_1.addCommasToNumber)(numberAsString), '.');
112
- if (beforeDot.length <= maxLength) {
113
- return combineBeforeAndAfterDot({
114
- beforeDot,
115
- afterDot,
116
- maxLength,
117
- });
118
- }
119
- // in this case, the number is not small enough to be handled by this function
120
- return undefined;
121
- }
122
- /**
123
- * This truncates a number such that is will at a max have 6 characters including suffix, decimal
124
- * point, or comma.
125
- *
126
- * Default suffixes are:
127
- *
128
- * 'k', // thousand
129
- * 'M', // million
130
- * 'B', // billion
131
- * 'T', // trillion
132
- * 'P', // peta-, quadrillion
133
- * 'E', // exa- quintillion
134
- * 'Z', // zetta- sextillion
135
- * 'Y', // yotta- septillion
136
- */
137
- function truncateNumber(originalValue, { customSuffixes = defaultTruncationSuffixes, maxLength = 6, } = {}) {
138
- const inputNumber = (0, common_number_1.convertIntoNumber)(originalValue);
139
- // handle edge cases
140
- if (isNaN(inputNumber) || inputNumber === Infinity) {
141
- return String(inputNumber);
142
- }
143
- // handle too big or too small edge cases
144
- if ((0, common_number_1.doesRequireScientificNotation)(inputNumber)) {
145
- return truncateScientificNotation({ input: inputNumber, maxLength });
146
- }
147
- const numberAsString = String(inputNumber);
148
- const smallResult = handleSmallNumbers(numberAsString, maxLength);
149
- if (smallResult != undefined) {
150
- return smallResult;
151
- }
152
- return truncateBigNumber(numberAsString, customSuffixes, maxLength);
153
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isLengthAtLeast = isLengthAtLeast;
4
- exports.assertLengthAtLeast = assertLengthAtLeast;
5
- function isLengthAtLeast(array, length) {
6
- try {
7
- assertLengthAtLeast(array, length);
8
- return true;
9
- }
10
- catch (error) {
11
- return false;
12
- }
13
- }
14
- function assertLengthAtLeast(array, length, arrayName) {
15
- if (array.length < length) {
16
- throw new Error(arrayName
17
- ? `'${arrayName}' is not at least '${length}' in length.`
18
- : `Array is not at least '${length}' in length.`);
19
- }
20
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeWritable = makeWritable;
4
- exports.makeReadonly = makeReadonly;
5
- exports.wrapNarrowTypeWithTypeCheck = wrapNarrowTypeWithTypeCheck;
6
- exports.ensureType = ensureType;
7
- function makeWritable(input) {
8
- return input;
9
- }
10
- function makeReadonly(input) {
11
- return input;
12
- }
13
- /**
14
- * This function returns another function that simply returns whatever input it's given. However, it
15
- * also checks that the input matches the original wrapNarrowTypeWithTypeCheck's generic, while
16
- * maintaining strict "const" like typing.
17
- *
18
- * Use like this: wrapNarrowTypeWithTypeCheck<EnforcedTypeHere>()(valueToEnforceTypeOn as const)
19
- *
20
- * Sometimes "as const" isn't required, usually it is for any object or array though.
21
- */
22
- function wrapNarrowTypeWithTypeCheck() {
23
- return (input) => {
24
- return input;
25
- };
26
- }
27
- /**
28
- * This is a type helper that ensures the given input matches the given generic type. The generic is
29
- * setup in such a way that if it is omitted (which is typically allowed in TypeScript, resulting in
30
- * the generic being inferred from the inputs), there will actually be a type error. This forces
31
- * each usage of this function to explicitly specify the generic, thus giving us type safety for the
32
- * input.
33
- */
34
- function ensureType(input) {
35
- return input;
36
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapInTry = wrapInTry;
4
- const run_time_assertions_1 = require("run-time-assertions");
5
- const error_1 = require("./error");
6
- function wrapInTry(callback, options = {}) {
7
- try {
8
- const value = callback();
9
- if (value instanceof Promise) {
10
- return value.catch((error) => {
11
- if (options.handleError) {
12
- return options.handleError(error);
13
- }
14
- else if ((0, run_time_assertions_1.hasProperty)(options, 'fallbackValue')) {
15
- return options.fallbackValue;
16
- }
17
- else {
18
- return (0, error_1.ensureError)(error);
19
- }
20
- });
21
- }
22
- else {
23
- return value;
24
- }
25
- }
26
- catch (error) {
27
- if (options.handleError) {
28
- return options.handleError(error);
29
- }
30
- else if ((0, run_time_assertions_1.hasProperty)(options, 'fallbackValue')) {
31
- return options.fallbackValue;
32
- }
33
- else {
34
- return (0, error_1.ensureError)(error);
35
- }
36
- }
37
- }
package/dist/cjs/index.js DELETED
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./augments/ansi"), exports);
18
- __exportStar(require("./augments/array/array"), exports);
19
- __exportStar(require("./augments/array/remove-duplicates"), exports);
20
- __exportStar(require("./augments/async"), exports);
21
- __exportStar(require("./augments/boolean"), exports);
22
- __exportStar(require("./augments/common-number"), exports);
23
- __exportStar(require("./augments/common-string"), exports);
24
- __exportStar(require("./augments/debounce"), exports);
25
- __exportStar(require("./augments/environment"), exports);
26
- __exportStar(require("./augments/error"), exports);
27
- __exportStar(require("./augments/esm-path"), exports);
28
- __exportStar(require("./augments/function"), exports);
29
- __exportStar(require("./augments/json"), exports);
30
- __exportStar(require("./augments/json-compatible"), exports);
31
- __exportStar(require("./augments/object/any-object"), exports);
32
- __exportStar(require("./augments/object/enum"), exports);
33
- __exportStar(require("./augments/object/filter-object"), exports);
34
- __exportStar(require("./augments/object/get-or-set"), exports);
35
- __exportStar(require("./augments/object/has-key"), exports);
36
- __exportStar(require("./augments/object/jsonify"), exports);
37
- __exportStar(require("./augments/object/key-count"), exports);
38
- __exportStar(require("./augments/object/map-object"), exports);
39
- __exportStar(require("./augments/object/merge-deep"), exports);
40
- __exportStar(require("./augments/object/merge-property-arrays"), exports);
41
- __exportStar(require("./augments/object/object"), exports);
42
- __exportStar(require("./augments/object/object-entries"), exports);
43
- __exportStar(require("./augments/object/pick-deep"), exports);
44
- __exportStar(require("./augments/object/selection-set"), exports);
45
- __exportStar(require("./augments/object/typed-has-property"), exports);
46
- __exportStar(require("./augments/promise/deferred-promise"), exports);
47
- __exportStar(require("./augments/promise/promise"), exports);
48
- __exportStar(require("./augments/promise/wait"), exports);
49
- __exportStar(require("./augments/random"), exports);
50
- __exportStar(require("./augments/regexp"), exports);
51
- __exportStar(require("./augments/string/prefixes"), exports);
52
- __exportStar(require("./augments/string/suffixes"), exports);
53
- __exportStar(require("./augments/string/uuid"), exports);
54
- __exportStar(require("./augments/time"), exports);
55
- __exportStar(require("./augments/truncate-number"), exports);
56
- __exportStar(require("./augments/tuple"), exports);
57
- __exportStar(require("./augments/type"), exports);
58
- __exportStar(require("./augments/type-recursion"), exports);
59
- __exportStar(require("./augments/union"), exports);
60
- __exportStar(require("./augments/wrap-in-try"), exports);
@@ -1,24 +0,0 @@
1
- // cspell:disable
2
- /*
3
- Copied from
4
- https://github.com/chalk/ansi-regex/blob/1b337add136eb520764634a328e2f6354398eee5/index.js
5
- because the published ansi-regex package exports this in a manner that Jest can't handle and the
6
- latest version of the package that doesn't do that has a security vulnerability. The package has
7
- the following license from
8
- https://github.com/chalk/ansi-regex/blob/1b337add136eb520764634a328e2f6354398eee5/license
9
-
10
- MIT License
11
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
12
-
13
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
- */
19
- // cspell:enable
20
- const patterns = [
21
- '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
22
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
23
- ];
24
- export const ansiRegex = new RegExp(patterns.join('|'), 'g');