@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.
- package/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/README.md +7 -3
- package/dist/augments/array/array-map.d.ts +34 -0
- package/dist/augments/array/array-map.js +32 -0
- package/dist/augments/array/array-to-object.d.ts +53 -0
- package/dist/augments/array/array-to-object.js +67 -0
- package/dist/augments/array/awaited/awaited-filter.d.ts +36 -0
- package/dist/augments/array/awaited/awaited-filter.js +36 -0
- package/dist/augments/array/awaited/awaited-for-each.d.ts +31 -0
- package/dist/augments/array/awaited/awaited-for-each.js +34 -0
- package/dist/augments/array/awaited/awaited-map.d.ts +33 -0
- package/dist/augments/array/awaited/awaited-map.js +40 -0
- package/dist/augments/array/filter.d.ts +32 -0
- package/dist/augments/array/filter.js +74 -0
- package/dist/augments/array/remove-duplicates.d.ts +60 -0
- package/dist/augments/array/remove-duplicates.js +72 -0
- package/dist/augments/array/repeat-array.d.ts +23 -0
- package/dist/augments/array/repeat-array.js +25 -0
- package/dist/augments/array/shuffle-array.d.ts +9 -0
- package/dist/augments/array/shuffle-array.js +17 -0
- package/dist/augments/array/string-array.d.ts +9 -0
- package/dist/augments/array/string-array.js +11 -0
- package/dist/augments/core-exports.d.ts +1 -0
- package/dist/augments/core-exports.js +1 -0
- package/dist/augments/enum/enum-value-check.d.ts +32 -0
- package/dist/augments/enum/enum-value-check.js +34 -0
- package/dist/augments/error/combine-errors.d.ts +24 -0
- package/dist/augments/error/combine-errors.js +34 -0
- package/dist/augments/function/call-asynchronously.d.ts +25 -0
- package/dist/augments/function/call-asynchronously.js +26 -0
- package/dist/augments/function/call-with-retries.d.ts +24 -0
- package/dist/augments/function/call-with-retries.js +50 -0
- package/dist/augments/function/debounce.d.ts +89 -0
- package/dist/augments/function/debounce.js +112 -0
- package/dist/augments/function/execution-duration.d.ts +20 -0
- package/dist/augments/function/execution-duration.js +39 -0
- package/dist/augments/function/if-truthy.d.ts +28 -0
- package/dist/augments/function/if-truthy.js +35 -0
- package/dist/{types/augments → augments/function}/wrap-in-try.d.ts +14 -7
- package/dist/augments/function/wrap-in-try.js +98 -0
- package/dist/augments/json/append-json.d.ts +5 -0
- package/dist/augments/json/append-json.js +59 -0
- package/dist/augments/json/copy-through-json.d.ts +34 -0
- package/dist/augments/json/copy-through-json.js +42 -0
- package/dist/augments/json/json-compatible.d.ts +50 -0
- package/dist/augments/json/jsonify.d.ts +31 -0
- package/dist/augments/json/jsonify.js +33 -0
- package/dist/augments/log/log-colors.d.ts +64 -0
- package/dist/augments/log/log-colors.js +157 -0
- package/dist/augments/log/log-string.d.ts +35 -0
- package/dist/augments/log/log-string.js +73 -0
- package/dist/augments/log/log-writer.d.ts +30 -0
- package/dist/augments/log/log.d.ts +56 -0
- package/dist/augments/log/log.js +85 -0
- package/dist/augments/log/logger.d.ts +60 -0
- package/dist/augments/log/logger.js +59 -0
- package/dist/augments/number/clamp.d.ts +18 -0
- package/dist/augments/number/clamp.js +19 -0
- package/dist/augments/number/coords.d.ts +23 -0
- package/dist/augments/number/digit.d.ts +8 -0
- package/dist/augments/number/dimensions.d.ts +23 -0
- package/dist/augments/number/min-max.d.ts +18 -0
- package/dist/augments/number/min-max.js +16 -0
- package/dist/augments/number/number-conversion.d.ts +29 -0
- package/dist/augments/number/number-conversion.js +56 -0
- package/dist/augments/number/round.d.ts +22 -0
- package/dist/augments/number/round.js +24 -0
- package/dist/augments/number/scientific.d.ts +18 -0
- package/dist/augments/number/scientific.js +20 -0
- package/dist/augments/number/truncate-number.d.ts +40 -0
- package/dist/{esm/augments → augments/number}/truncate-number.js +39 -17
- package/dist/augments/number/wrap-number.d.ts +19 -0
- package/dist/augments/number/wrap-number.js +28 -0
- package/dist/augments/object/diff.d.ts +51 -0
- package/dist/augments/object/diff.js +149 -0
- package/dist/augments/object/empty.d.ts +9 -0
- package/dist/augments/object/get-or-set.d.ts +10 -0
- package/dist/augments/object/get-or-set.js +100 -0
- package/dist/augments/object/key-count.d.ts +21 -0
- package/dist/augments/object/map-entries.d.ts +13 -0
- package/dist/augments/object/map-entries.js +80 -0
- package/dist/augments/object/map-enum.d.ts +11 -0
- package/dist/augments/object/map-enum.js +45 -0
- package/dist/augments/object/map-values.d.ts +35 -0
- package/dist/augments/object/map-values.js +65 -0
- package/dist/{types/augments → augments}/object/merge-deep.d.ts +4 -0
- package/dist/{esm/augments → augments}/object/merge-deep.js +9 -6
- package/dist/augments/object/merge-defined-properties.d.ts +19 -0
- package/dist/augments/object/merge-defined-properties.js +32 -0
- package/dist/augments/object/merge-property-arrays.d.ts +29 -0
- package/dist/augments/object/merge-property-arrays.js +39 -0
- package/dist/augments/object/object-entries.d.ts +31 -0
- package/dist/augments/object/object-entries.js +40 -0
- package/dist/augments/object/object-filter.d.ts +22 -0
- package/dist/augments/object/object-filter.js +27 -0
- package/dist/augments/object/object-keys.d.ts +34 -0
- package/dist/augments/object/object-keys.js +43 -0
- package/dist/augments/object/object-values.d.ts +11 -0
- package/dist/augments/object/object-values.js +13 -0
- package/dist/augments/path/esm-path.d.ts +26 -0
- package/dist/augments/path/esm-path.js +31 -0
- package/dist/augments/prisma/prisma-models.d.ts +143 -0
- package/dist/augments/prisma/prisma-models.js +1 -0
- package/dist/augments/promise/timed-promise.d.ts +22 -0
- package/dist/augments/promise/timed-promise.js +51 -0
- package/dist/augments/random/random-boolean.d.ts +24 -0
- package/dist/augments/random/random-boolean.js +32 -0
- package/dist/augments/random/random-integer.d.ts +14 -0
- package/dist/augments/random/random-integer.js +34 -0
- package/dist/augments/random/random-string.d.ts +18 -0
- package/dist/augments/random/random-string.js +67 -0
- package/dist/augments/regexp/match.d.ts +10 -0
- package/dist/augments/regexp/match.js +13 -0
- package/dist/augments/regexp/regexp-flags.d.ts +56 -0
- package/dist/augments/regexp/regexp-flags.js +75 -0
- package/dist/augments/regexp/regexp-string.d.ts +9 -0
- package/dist/augments/regexp/regexp-string.js +11 -0
- package/dist/augments/selection-set/select-collapsed.d.ts +54 -0
- package/dist/augments/selection-set/select-collapsed.js +63 -0
- package/dist/augments/selection-set/select-from.d.ts +48 -0
- package/dist/augments/selection-set/select-from.js +72 -0
- package/dist/augments/selection-set/selection-set.d.ts +37 -0
- package/dist/augments/selection-set/selection-set.js +1 -0
- package/dist/augments/string/casing/capitalization.d.ts +17 -0
- package/dist/augments/string/casing/capitalization.js +25 -0
- package/dist/augments/string/casing/casing.d.ts +73 -0
- package/dist/augments/string/casing/casing.js +65 -0
- package/dist/augments/string/casing/kebab-and-camel.d.ts +17 -0
- package/dist/augments/string/casing/kebab-and-camel.js +57 -0
- package/dist/augments/string/comma.d.ts +26 -0
- package/dist/augments/string/comma.js +48 -0
- package/dist/augments/string/join.d.ts +21 -0
- package/dist/augments/string/join.js +34 -0
- package/dist/augments/string/prefix.d.ts +30 -0
- package/dist/augments/string/prefix.js +30 -0
- package/dist/augments/string/remove-duplicate-characters.d.ts +17 -0
- package/dist/augments/string/remove-duplicate-characters.js +22 -0
- package/dist/augments/string/replace.d.ts +18 -0
- package/dist/augments/string/replace.js +22 -0
- package/dist/augments/string/split.d.ts +31 -0
- package/dist/augments/string/split.js +53 -0
- package/dist/augments/string/substring-index.d.ts +19 -0
- package/dist/augments/string/substring-index.js +47 -0
- package/dist/augments/string/suffix.d.ts +96 -0
- package/dist/augments/string/suffix.js +89 -0
- package/dist/augments/string/white-space.d.ts +12 -0
- package/dist/augments/string/white-space.js +19 -0
- package/dist/augments/string/wrap-string.d.ts +19 -0
- package/dist/augments/string/wrap-string.js +20 -0
- package/dist/augments/type/ensure-type.d.ts +12 -0
- package/dist/augments/type/ensure-type.js +14 -0
- package/dist/augments/type/readonly.d.ts +9 -0
- package/dist/augments/type/readonly.js +10 -0
- package/dist/augments/type/type-recursion.d.ts +253 -0
- package/dist/augments/type/type-recursion.js +1 -0
- package/dist/augments/type/union.d.ts +1 -0
- package/dist/augments/type/union.js +1 -0
- package/dist/augments/type/void-type.d.ts +9 -0
- package/dist/augments/type/void-type.js +1 -0
- package/dist/augments/type/writable.d.ts +10 -0
- package/dist/augments/type/writable.js +10 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +83 -0
- package/package.json +43 -15
- package/dist/cjs/augments/ansi.js +0 -27
- package/dist/cjs/augments/array/array.js +0 -68
- package/dist/cjs/augments/array/remove-duplicates.js +0 -16
- package/dist/cjs/augments/async.js +0 -28
- package/dist/cjs/augments/boolean.js +0 -19
- package/dist/cjs/augments/common-number.js +0 -112
- package/dist/cjs/augments/common-string.js +0 -245
- package/dist/cjs/augments/debounce.js +0 -38
- package/dist/cjs/augments/environment.js +0 -6
- package/dist/cjs/augments/error.js +0 -52
- package/dist/cjs/augments/esm-path.js +0 -11
- package/dist/cjs/augments/function.js +0 -2
- package/dist/cjs/augments/json-compatible.js +0 -2
- package/dist/cjs/augments/json.js +0 -28
- package/dist/cjs/augments/object/any-object.js +0 -2
- package/dist/cjs/augments/object/enum.js +0 -48
- package/dist/cjs/augments/object/filter-object.js +0 -26
- package/dist/cjs/augments/object/get-or-set.js +0 -40
- package/dist/cjs/augments/object/has-key.js +0 -6
- package/dist/cjs/augments/object/jsonify.js +0 -6
- package/dist/cjs/augments/object/key-count.js +0 -2
- package/dist/cjs/augments/object/map-object.js +0 -61
- package/dist/cjs/augments/object/merge-deep.js +0 -52
- package/dist/cjs/augments/object/merge-property-arrays.js +0 -14
- package/dist/cjs/augments/object/object-entries.js +0 -40
- package/dist/cjs/augments/object/object.js +0 -18
- package/dist/cjs/augments/object/pick-deep.js +0 -2
- package/dist/cjs/augments/object/selection-set.js +0 -56
- package/dist/cjs/augments/object/typed-has-property.js +0 -29
- package/dist/cjs/augments/promise/deferred-promise.js +0 -31
- package/dist/cjs/augments/promise/promise.js +0 -79
- package/dist/cjs/augments/promise/wait.js +0 -66
- package/dist/cjs/augments/random.js +0 -118
- package/dist/cjs/augments/regexp.js +0 -19
- package/dist/cjs/augments/string/prefixes.js +0 -20
- package/dist/cjs/augments/string/suffixes.js +0 -40
- package/dist/cjs/augments/string/uuid.js +0 -13
- package/dist/cjs/augments/time.js +0 -35
- package/dist/cjs/augments/truncate-number.js +0 -153
- package/dist/cjs/augments/tuple.js +0 -20
- package/dist/cjs/augments/type-recursion.js +0 -2
- package/dist/cjs/augments/type.js +0 -36
- package/dist/cjs/augments/union.js +0 -2
- package/dist/cjs/augments/wrap-in-try.js +0 -37
- package/dist/cjs/index.js +0 -60
- package/dist/esm/augments/ansi.js +0 -24
- package/dist/esm/augments/array/array.js +0 -57
- package/dist/esm/augments/array/remove-duplicates.js +0 -13
- package/dist/esm/augments/async.js +0 -23
- package/dist/esm/augments/boolean.js +0 -14
- package/dist/esm/augments/common-number.js +0 -100
- package/dist/esm/augments/common-string.js +0 -227
- package/dist/esm/augments/debounce.js +0 -34
- package/dist/esm/augments/environment.js +0 -3
- package/dist/esm/augments/error.js +0 -45
- package/dist/esm/augments/esm-path.js +0 -8
- package/dist/esm/augments/json.js +0 -24
- package/dist/esm/augments/object/enum.js +0 -41
- package/dist/esm/augments/object/filter-object.js +0 -21
- package/dist/esm/augments/object/get-or-set.js +0 -36
- package/dist/esm/augments/object/has-key.js +0 -3
- package/dist/esm/augments/object/jsonify.js +0 -3
- package/dist/esm/augments/object/map-object.js +0 -57
- package/dist/esm/augments/object/merge-property-arrays.js +0 -11
- package/dist/esm/augments/object/object-entries.js +0 -32
- package/dist/esm/augments/object/object.js +0 -14
- package/dist/esm/augments/object/selection-set.js +0 -52
- package/dist/esm/augments/object/typed-has-property.js +0 -25
- package/dist/esm/augments/promise/deferred-promise.js +0 -28
- package/dist/esm/augments/promise/promise.js +0 -71
- package/dist/esm/augments/promise/wait.js +0 -60
- package/dist/esm/augments/random.js +0 -113
- package/dist/esm/augments/regexp.js +0 -14
- package/dist/esm/augments/string/prefixes.js +0 -16
- package/dist/esm/augments/string/suffixes.js +0 -31
- package/dist/esm/augments/string/uuid.js +0 -9
- package/dist/esm/augments/time.js +0 -31
- package/dist/esm/augments/tuple.js +0 -16
- package/dist/esm/augments/type.js +0 -30
- package/dist/esm/augments/wrap-in-try.js +0 -34
- package/dist/esm/index.js +0 -44
- package/dist/types/augments/ansi.d.ts +0 -1
- package/dist/types/augments/array/array.d.ts +0 -26
- package/dist/types/augments/array/remove-duplicates.d.ts +0 -1
- package/dist/types/augments/async.d.ts +0 -14
- package/dist/types/augments/boolean.d.ts +0 -6
- package/dist/types/augments/common-number.d.ts +0 -52
- package/dist/types/augments/common-string.d.ts +0 -74
- package/dist/types/augments/debounce.d.ts +0 -15
- package/dist/types/augments/environment.d.ts +0 -1
- package/dist/types/augments/error.d.ts +0 -9
- package/dist/types/augments/esm-path.d.ts +0 -4
- package/dist/types/augments/function.d.ts +0 -25
- package/dist/types/augments/json-compatible.d.ts +0 -22
- package/dist/types/augments/json.d.ts +0 -9
- package/dist/types/augments/object/any-object.d.ts +0 -2
- package/dist/types/augments/object/enum.d.ts +0 -8
- package/dist/types/augments/object/filter-object.d.ts +0 -4
- package/dist/types/augments/object/get-or-set.d.ts +0 -26
- package/dist/types/augments/object/has-key.d.ts +0 -1
- package/dist/types/augments/object/jsonify.d.ts +0 -2
- package/dist/types/augments/object/key-count.d.ts +0 -13
- package/dist/types/augments/object/map-object.d.ts +0 -20
- package/dist/types/augments/object/merge-property-arrays.d.ts +0 -1
- package/dist/types/augments/object/object-entries.d.ts +0 -8
- package/dist/types/augments/object/object.d.ts +0 -21
- package/dist/types/augments/object/pick-deep.d.ts +0 -14
- package/dist/types/augments/object/selection-set.d.ts +0 -27
- package/dist/types/augments/object/typed-has-property.d.ts +0 -7
- package/dist/types/augments/promise/deferred-promise.d.ts +0 -8
- package/dist/types/augments/promise/promise.d.ts +0 -15
- package/dist/types/augments/promise/wait.d.ts +0 -18
- package/dist/types/augments/random.d.ts +0 -37
- package/dist/types/augments/regexp.d.ts +0 -3
- package/dist/types/augments/string/prefixes.d.ts +0 -9
- package/dist/types/augments/string/suffixes.d.ts +0 -17
- package/dist/types/augments/string/uuid.d.ts +0 -5
- package/dist/types/augments/time.d.ts +0 -14
- package/dist/types/augments/truncate-number.d.ts +0 -19
- package/dist/types/augments/tuple.d.ts +0 -17
- package/dist/types/augments/type-recursion.d.ts +0 -161
- package/dist/types/augments/type.d.ts +0 -69
- package/dist/types/augments/union.d.ts +0 -5
- package/dist/types/index.d.ts +0 -44
- /package/dist/{esm/augments → augments/json}/json-compatible.js +0 -0
- /package/dist/{esm/augments/function.js → augments/log/log-writer.js} +0 -0
- /package/dist/{esm/augments/object/any-object.js → augments/number/coords.js} +0 -0
- /package/dist/{esm/augments/object/key-count.js → augments/number/digit.js} +0 -0
- /package/dist/{esm/augments/object/pick-deep.js → augments/number/dimensions.js} +0 -0
- /package/dist/{esm/augments/type-recursion.js → augments/object/empty.js} +0 -0
- /package/dist/{esm/augments/union.js → augments/object/key-count.js} +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { toEnsuredNumber } from '../number/number-conversion.js';
|
|
2
|
+
/**
|
|
3
|
+
* Suffix for {@link addPercent} and {@link removePercent}.
|
|
4
|
+
*
|
|
5
|
+
* @category String
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
8
|
+
*/
|
|
9
|
+
export const percentSuffix = '%';
|
|
10
|
+
/**
|
|
11
|
+
* Suffix for {@link addPx} and {@link removePx}.
|
|
12
|
+
*
|
|
13
|
+
* @category String
|
|
14
|
+
* @category Package : @augment-vir/common
|
|
15
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
16
|
+
*/
|
|
17
|
+
export const pxSuffix = 'px';
|
|
18
|
+
/**
|
|
19
|
+
* Adds the `'px'` suffix to a string if it does not already exist.
|
|
20
|
+
*
|
|
21
|
+
* @category String
|
|
22
|
+
* @category Package : @augment-vir/common
|
|
23
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
24
|
+
*/
|
|
25
|
+
export function addPx(input) {
|
|
26
|
+
return addSuffix({ value: input, suffix: pxSuffix });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Removes the `'px'` suffix from a string if it exists.
|
|
30
|
+
*
|
|
31
|
+
* @category String
|
|
32
|
+
* @category Package : @augment-vir/common
|
|
33
|
+
* @throws `TypeError` if the input can't be converted into a number.
|
|
34
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
35
|
+
*/
|
|
36
|
+
export function removePx(input) {
|
|
37
|
+
return toEnsuredNumber(removeSuffix({ value: input, suffix: pxSuffix }));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Adds the `'%'` suffix to a string if it does not already exist.
|
|
41
|
+
*
|
|
42
|
+
* @category String
|
|
43
|
+
* @category Package : @augment-vir/common
|
|
44
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
45
|
+
*/
|
|
46
|
+
export function addPercent(input) {
|
|
47
|
+
return addSuffix({ value: input, suffix: percentSuffix });
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Removes the `'%'` suffix from a string if it exists.
|
|
51
|
+
*
|
|
52
|
+
* @category String
|
|
53
|
+
* @category Package : @augment-vir/common
|
|
54
|
+
* @throws `TypeError` if the input can't be converted into a number.
|
|
55
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
56
|
+
*/
|
|
57
|
+
export function removePercent(input) {
|
|
58
|
+
return toEnsuredNumber(removeSuffix({ value: input, suffix: percentSuffix }));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Adds a suffix to a string if it does not already exist.
|
|
62
|
+
*
|
|
63
|
+
* @category String
|
|
64
|
+
* @category Package : @augment-vir/common
|
|
65
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
66
|
+
*/
|
|
67
|
+
export function addSuffix({ value, suffix, }) {
|
|
68
|
+
if (String(value).endsWith(suffix)) {
|
|
69
|
+
return String(value);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return `${String(value)}${suffix}`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Removes a suffix from a string if it exists.
|
|
77
|
+
*
|
|
78
|
+
* @category String
|
|
79
|
+
* @category Package : @augment-vir/common
|
|
80
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
81
|
+
*/
|
|
82
|
+
export function removeSuffix({ value, suffix, }) {
|
|
83
|
+
if (value.endsWith(suffix)) {
|
|
84
|
+
return value.slice(0, Math.max(0, value.length - suffix.length));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PartialWithUndefined } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Collapse all consecutive white space into just one space and trim surrounding whitespace.
|
|
4
|
+
* Optionally, collapsed newlines can be preserved.
|
|
5
|
+
*
|
|
6
|
+
* @category String
|
|
7
|
+
* @category Package : @augment-vir/common
|
|
8
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
9
|
+
*/
|
|
10
|
+
export declare function collapseWhiteSpace(input: string, { keepNewLines }?: PartialWithUndefined<{
|
|
11
|
+
keepNewLines: boolean;
|
|
12
|
+
}>): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collapse all consecutive white space into just one space and trim surrounding whitespace.
|
|
3
|
+
* Optionally, collapsed newlines can be preserved.
|
|
4
|
+
*
|
|
5
|
+
* @category String
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
8
|
+
*/
|
|
9
|
+
export function collapseWhiteSpace(input, { keepNewLines } = {}) {
|
|
10
|
+
if (keepNewLines) {
|
|
11
|
+
return input
|
|
12
|
+
.trim()
|
|
13
|
+
.replaceAll(/[^\S\r\n]+/g, ' ')
|
|
14
|
+
.replaceAll(/[^\S\r\n]?\n+[^\S\r\n]?/g, '\n');
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return input.trim().replaceAll(/\s+/g, ' ');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a string in another string.
|
|
3
|
+
*
|
|
4
|
+
* @category String
|
|
5
|
+
* @category Package : @augment-vir/common
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import {wrapString} from '@augment-vir/common';
|
|
10
|
+
*
|
|
11
|
+
* wrapString({value: 'some words', wrapper: '"'}); // outputs `'"some words"'`
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
15
|
+
*/
|
|
16
|
+
export declare function wrapString({ value, wrapper }: {
|
|
17
|
+
value: string;
|
|
18
|
+
wrapper: string;
|
|
19
|
+
}): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { addPrefix } from './prefix.js';
|
|
2
|
+
import { addSuffix } from './suffix.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a string in another string.
|
|
5
|
+
*
|
|
6
|
+
* @category String
|
|
7
|
+
* @category Package : @augment-vir/common
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {wrapString} from '@augment-vir/common';
|
|
12
|
+
*
|
|
13
|
+
* wrapString({value: 'some words', wrapper: '"'}); // outputs `'"some words"'`
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
17
|
+
*/
|
|
18
|
+
export function wrapString({ value, wrapper }) {
|
|
19
|
+
return addPrefix({ value: addSuffix({ value, suffix: wrapper }), prefix: wrapper });
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a type helper that ensures the given input matches the given generic type. The generic is
|
|
3
|
+
* setup in such a way that if it is omitted (which is typically allowed in TypeScript, resulting in
|
|
4
|
+
* the generic being inferred from the inputs), there will actually be a type error. This forces
|
|
5
|
+
* each usage of this function to explicitly specify the generic, thus giving us type safety for the
|
|
6
|
+
* input.
|
|
7
|
+
*
|
|
8
|
+
* @category Type
|
|
9
|
+
* @category Package : @augment-vir/common
|
|
10
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
11
|
+
*/
|
|
12
|
+
export declare function ensureType<ExpectedType = never>(input: NoInfer<ExpectedType>): NoInfer<ExpectedType>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a type helper that ensures the given input matches the given generic type. The generic is
|
|
3
|
+
* setup in such a way that if it is omitted (which is typically allowed in TypeScript, resulting in
|
|
4
|
+
* the generic being inferred from the inputs), there will actually be a type error. This forces
|
|
5
|
+
* each usage of this function to explicitly specify the generic, thus giving us type safety for the
|
|
6
|
+
* input.
|
|
7
|
+
*
|
|
8
|
+
* @category Type
|
|
9
|
+
* @category Package : @augment-vir/common
|
|
10
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
11
|
+
*/
|
|
12
|
+
export function ensureType(input) {
|
|
13
|
+
return input;
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { ReadonlyDeep } from 'type-fest';
|
|
2
|
+
/**
|
|
3
|
+
* This function does nothing but return the input as a readonly typed version of itself.
|
|
4
|
+
*
|
|
5
|
+
* @category Type
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
8
|
+
*/
|
|
9
|
+
export declare function makeReadonly<T>(input: T): Readonly<T>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function does nothing but return the input as a readonly typed version of itself.
|
|
3
|
+
*
|
|
4
|
+
* @category Type
|
|
5
|
+
* @category Package : @augment-vir/common
|
|
6
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
7
|
+
*/
|
|
8
|
+
export function makeReadonly(input) {
|
|
9
|
+
return input;
|
|
10
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
type TsRecursionArray = [
|
|
2
|
+
1,
|
|
3
|
+
2,
|
|
4
|
+
3,
|
|
5
|
+
4,
|
|
6
|
+
5,
|
|
7
|
+
6,
|
|
8
|
+
7,
|
|
9
|
+
8,
|
|
10
|
+
9,
|
|
11
|
+
10,
|
|
12
|
+
11,
|
|
13
|
+
12,
|
|
14
|
+
13,
|
|
15
|
+
14,
|
|
16
|
+
15,
|
|
17
|
+
16,
|
|
18
|
+
17,
|
|
19
|
+
18,
|
|
20
|
+
19,
|
|
21
|
+
20,
|
|
22
|
+
21,
|
|
23
|
+
22,
|
|
24
|
+
23,
|
|
25
|
+
24,
|
|
26
|
+
25,
|
|
27
|
+
26,
|
|
28
|
+
27,
|
|
29
|
+
28,
|
|
30
|
+
29,
|
|
31
|
+
30,
|
|
32
|
+
31,
|
|
33
|
+
32,
|
|
34
|
+
33,
|
|
35
|
+
34,
|
|
36
|
+
35,
|
|
37
|
+
36,
|
|
38
|
+
37,
|
|
39
|
+
38,
|
|
40
|
+
39,
|
|
41
|
+
40,
|
|
42
|
+
41,
|
|
43
|
+
42,
|
|
44
|
+
43,
|
|
45
|
+
44,
|
|
46
|
+
45,
|
|
47
|
+
46,
|
|
48
|
+
47,
|
|
49
|
+
48,
|
|
50
|
+
49,
|
|
51
|
+
50,
|
|
52
|
+
51,
|
|
53
|
+
52,
|
|
54
|
+
53,
|
|
55
|
+
54,
|
|
56
|
+
55,
|
|
57
|
+
56,
|
|
58
|
+
57,
|
|
59
|
+
58,
|
|
60
|
+
59,
|
|
61
|
+
60,
|
|
62
|
+
61,
|
|
63
|
+
62,
|
|
64
|
+
63,
|
|
65
|
+
64,
|
|
66
|
+
65,
|
|
67
|
+
66,
|
|
68
|
+
67,
|
|
69
|
+
68,
|
|
70
|
+
69,
|
|
71
|
+
70,
|
|
72
|
+
71,
|
|
73
|
+
72,
|
|
74
|
+
73,
|
|
75
|
+
74,
|
|
76
|
+
75,
|
|
77
|
+
76,
|
|
78
|
+
77,
|
|
79
|
+
78,
|
|
80
|
+
79,
|
|
81
|
+
80,
|
|
82
|
+
81,
|
|
83
|
+
82,
|
|
84
|
+
83,
|
|
85
|
+
84,
|
|
86
|
+
85,
|
|
87
|
+
86,
|
|
88
|
+
87,
|
|
89
|
+
88,
|
|
90
|
+
89,
|
|
91
|
+
90,
|
|
92
|
+
91,
|
|
93
|
+
92,
|
|
94
|
+
93,
|
|
95
|
+
94,
|
|
96
|
+
95,
|
|
97
|
+
96,
|
|
98
|
+
97,
|
|
99
|
+
98,
|
|
100
|
+
99,
|
|
101
|
+
100,
|
|
102
|
+
101,
|
|
103
|
+
102,
|
|
104
|
+
103,
|
|
105
|
+
104,
|
|
106
|
+
105,
|
|
107
|
+
106,
|
|
108
|
+
107,
|
|
109
|
+
108,
|
|
110
|
+
109,
|
|
111
|
+
110,
|
|
112
|
+
111,
|
|
113
|
+
112,
|
|
114
|
+
113,
|
|
115
|
+
114,
|
|
116
|
+
115,
|
|
117
|
+
116,
|
|
118
|
+
117,
|
|
119
|
+
118,
|
|
120
|
+
119,
|
|
121
|
+
120,
|
|
122
|
+
121,
|
|
123
|
+
122,
|
|
124
|
+
123,
|
|
125
|
+
124,
|
|
126
|
+
125,
|
|
127
|
+
126,
|
|
128
|
+
127,
|
|
129
|
+
128,
|
|
130
|
+
129,
|
|
131
|
+
130,
|
|
132
|
+
131,
|
|
133
|
+
132,
|
|
134
|
+
133,
|
|
135
|
+
134,
|
|
136
|
+
135,
|
|
137
|
+
136,
|
|
138
|
+
137,
|
|
139
|
+
138,
|
|
140
|
+
139,
|
|
141
|
+
140,
|
|
142
|
+
141,
|
|
143
|
+
142,
|
|
144
|
+
143,
|
|
145
|
+
144,
|
|
146
|
+
145,
|
|
147
|
+
146,
|
|
148
|
+
147,
|
|
149
|
+
148,
|
|
150
|
+
149,
|
|
151
|
+
150
|
|
152
|
+
];
|
|
153
|
+
/**
|
|
154
|
+
* This is used as the baseline type for TypeScript recursion tracking indexes. Use this to manually
|
|
155
|
+
* abort a type's recursion to prevent it from going too deep and throwing an error in TypeScript's
|
|
156
|
+
* language server.
|
|
157
|
+
*
|
|
158
|
+
* @category Type
|
|
159
|
+
* @category Package : @augment-vir/common
|
|
160
|
+
* @example
|
|
161
|
+
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* import type {
|
|
164
|
+
* TsRecursionTracker,
|
|
165
|
+
* TsRecursionStart,
|
|
166
|
+
* TsRecurse,
|
|
167
|
+
* TsTooMuchRecursion,
|
|
168
|
+
* } from '@augment-vir/common';
|
|
169
|
+
*
|
|
170
|
+
* export type SomeType<Depth extends TsRecursionTracker = TsRecursionStart> =
|
|
171
|
+
* Depth extends TsTooMuchRecursion
|
|
172
|
+
* ? 'Error: recursive object depth is too deep.'
|
|
173
|
+
* : SomeType<TsRecurse<Depth>>;
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
177
|
+
*/
|
|
178
|
+
export type TsRecursionTracker = keyof TsRecursionArray;
|
|
179
|
+
/**
|
|
180
|
+
* Through experimentation on Typescript version 5.4.5, this is the maximum recursion depth we can
|
|
181
|
+
* go to before TypeScript will block recursive types. Use this as the limit to type recursion.
|
|
182
|
+
*
|
|
183
|
+
* @category Type
|
|
184
|
+
* @category Package : @augment-vir/common
|
|
185
|
+
* @example
|
|
186
|
+
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* import type {
|
|
189
|
+
* TsRecursionTracker,
|
|
190
|
+
* TsRecursionStart,
|
|
191
|
+
* TsRecurse,
|
|
192
|
+
* TsTooMuchRecursion,
|
|
193
|
+
* } from '@augment-vir/common';
|
|
194
|
+
*
|
|
195
|
+
* export type SomeType<Depth extends TsRecursionTracker = TsRecursionStart> =
|
|
196
|
+
* Depth extends TsTooMuchRecursion
|
|
197
|
+
* ? 'Error: recursive object depth is too deep.'
|
|
198
|
+
* : SomeType<TsRecurse<Depth>>;
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
202
|
+
*/
|
|
203
|
+
export type TsTooMuchRecursion = 91;
|
|
204
|
+
/**
|
|
205
|
+
* This is the default starting recursion depth needed to get the full tested allowed recursion
|
|
206
|
+
* depth.
|
|
207
|
+
*
|
|
208
|
+
* @category Type
|
|
209
|
+
* @category Package : @augment-vir/common
|
|
210
|
+
* @example
|
|
211
|
+
*
|
|
212
|
+
* ```ts
|
|
213
|
+
* import type {
|
|
214
|
+
* TsRecursionTracker,
|
|
215
|
+
* TsRecursionStart,
|
|
216
|
+
* TsRecurse,
|
|
217
|
+
* TsTooMuchRecursion,
|
|
218
|
+
* } from '@augment-vir/common';
|
|
219
|
+
*
|
|
220
|
+
* export type SomeType<Depth extends TsRecursionTracker = TsRecursionStart> =
|
|
221
|
+
* Depth extends TsTooMuchRecursion
|
|
222
|
+
* ? 'Error: recursive object depth is too deep.'
|
|
223
|
+
* : SomeType<TsRecurse<Depth>>;
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
227
|
+
*/
|
|
228
|
+
export type TsRecursionStart = 0;
|
|
229
|
+
/**
|
|
230
|
+
* Increments a TypeScript recursion depth tracker.
|
|
231
|
+
*
|
|
232
|
+
* @category Type
|
|
233
|
+
* @category Package : @augment-vir/common
|
|
234
|
+
* @example
|
|
235
|
+
*
|
|
236
|
+
* ```ts
|
|
237
|
+
* import type {
|
|
238
|
+
* TsRecursionTracker,
|
|
239
|
+
* TsRecursionStart,
|
|
240
|
+
* TsRecurse,
|
|
241
|
+
* TsTooMuchRecursion,
|
|
242
|
+
* } from '@augment-vir/common';
|
|
243
|
+
*
|
|
244
|
+
* export type SomeType<Depth extends TsRecursionTracker = TsRecursionStart> =
|
|
245
|
+
* Depth extends TsTooMuchRecursion
|
|
246
|
+
* ? 'Error: recursive object depth is too deep.'
|
|
247
|
+
* : SomeType<TsRecurse<Depth>>;
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
251
|
+
*/
|
|
252
|
+
export type TsRecurse<CurrentRecursion extends TsRecursionTracker> = TsRecursionArray[CurrentRecursion] extends TsRecursionTracker ? TsRecursionArray[CurrentRecursion] : TsTooMuchRecursion;
|
|
253
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { UnionToIntersection } from 'type-fest';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Require that the given `NonVoid` parameter is not void. If it is void, the `ErrorType` or an
|
|
3
|
+
* error string type is returned. If it not void, the given `SuccessType` is returned.
|
|
4
|
+
*
|
|
5
|
+
* @category Type
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
8
|
+
*/
|
|
9
|
+
export type RequireNonVoid<NonVoid, SuccessType, ErrorType = 'Input should not be void'> = void extends NonVoid ? (NonVoid extends void ? ErrorType : SuccessType) : SuccessType;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Writable } from 'type-fest';
|
|
2
|
+
export type { Writable, WritableDeep } from 'type-fest';
|
|
3
|
+
/**
|
|
4
|
+
* This function does nothing but return the input as a writable typed version of itself.
|
|
5
|
+
*
|
|
6
|
+
* @category Type
|
|
7
|
+
* @category Package : @augment-vir/common
|
|
8
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
9
|
+
*/
|
|
10
|
+
export declare function makeWritable<T>(input: T): Writable<T>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function does nothing but return the input as a writable typed version of itself.
|
|
3
|
+
*
|
|
4
|
+
* @category Type
|
|
5
|
+
* @category Package : @augment-vir/common
|
|
6
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
7
|
+
*/
|
|
8
|
+
export function makeWritable(input) {
|
|
9
|
+
return input;
|
|
10
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export * from './augments/array/array-map.js';
|
|
2
|
+
export * from './augments/array/array-to-object.js';
|
|
3
|
+
export * from './augments/array/awaited/awaited-filter.js';
|
|
4
|
+
export * from './augments/array/awaited/awaited-for-each.js';
|
|
5
|
+
export * from './augments/array/awaited/awaited-map.js';
|
|
6
|
+
export * from './augments/array/filter.js';
|
|
7
|
+
export * from './augments/array/remove-duplicates.js';
|
|
8
|
+
export * from './augments/array/repeat-array.js';
|
|
9
|
+
export * from './augments/array/shuffle-array.js';
|
|
10
|
+
export * from './augments/array/string-array.js';
|
|
11
|
+
export * from './augments/core-exports.js';
|
|
12
|
+
export * from './augments/enum/enum-value-check.js';
|
|
13
|
+
export * from './augments/error/combine-errors.js';
|
|
14
|
+
export * from './augments/function/call-asynchronously.js';
|
|
15
|
+
export * from './augments/function/call-with-retries.js';
|
|
16
|
+
export * from './augments/function/debounce.js';
|
|
17
|
+
export * from './augments/function/execution-duration.js';
|
|
18
|
+
export * from './augments/function/if-truthy.js';
|
|
19
|
+
export * from './augments/function/wrap-in-try.js';
|
|
20
|
+
export * from './augments/json/append-json.js';
|
|
21
|
+
export * from './augments/json/copy-through-json.js';
|
|
22
|
+
export * from './augments/json/json-compatible.js';
|
|
23
|
+
export * from './augments/json/jsonify.js';
|
|
24
|
+
export * from './augments/log/log-colors.js';
|
|
25
|
+
export * from './augments/log/log-string.js';
|
|
26
|
+
export * from './augments/log/log-writer.js';
|
|
27
|
+
export * from './augments/log/log.js';
|
|
28
|
+
export * from './augments/log/logger.js';
|
|
29
|
+
export * from './augments/number/clamp.js';
|
|
30
|
+
export * from './augments/number/coords.js';
|
|
31
|
+
export * from './augments/number/digit.js';
|
|
32
|
+
export * from './augments/number/dimensions.js';
|
|
33
|
+
export * from './augments/number/min-max.js';
|
|
34
|
+
export * from './augments/number/number-conversion.js';
|
|
35
|
+
export * from './augments/number/round.js';
|
|
36
|
+
export * from './augments/number/scientific.js';
|
|
37
|
+
export * from './augments/number/truncate-number.js';
|
|
38
|
+
export * from './augments/number/wrap-number.js';
|
|
39
|
+
export * from './augments/object/diff.js';
|
|
40
|
+
export * from './augments/object/empty.js';
|
|
41
|
+
export * from './augments/object/get-or-set.js';
|
|
42
|
+
export * from './augments/object/key-count.js';
|
|
43
|
+
export * from './augments/object/map-entries.js';
|
|
44
|
+
export * from './augments/object/map-enum.js';
|
|
45
|
+
export * from './augments/object/map-values.js';
|
|
46
|
+
export * from './augments/object/merge-deep.js';
|
|
47
|
+
export * from './augments/object/merge-defined-properties.js';
|
|
48
|
+
export * from './augments/object/merge-property-arrays.js';
|
|
49
|
+
export * from './augments/object/object-entries.js';
|
|
50
|
+
export * from './augments/object/object-filter.js';
|
|
51
|
+
export * from './augments/object/object-keys.js';
|
|
52
|
+
export * from './augments/object/object-values.js';
|
|
53
|
+
export * from './augments/path/esm-path.js';
|
|
54
|
+
export * from './augments/prisma/prisma-models.js';
|
|
55
|
+
export * from './augments/promise/timed-promise.js';
|
|
56
|
+
export * from './augments/random/random-boolean.js';
|
|
57
|
+
export * from './augments/random/random-integer.js';
|
|
58
|
+
export * from './augments/random/random-string.js';
|
|
59
|
+
export * from './augments/regexp/match.js';
|
|
60
|
+
export * from './augments/regexp/regexp-flags.js';
|
|
61
|
+
export * from './augments/regexp/regexp-string.js';
|
|
62
|
+
export * from './augments/selection-set/select-collapsed.js';
|
|
63
|
+
export * from './augments/selection-set/select-from.js';
|
|
64
|
+
export * from './augments/selection-set/selection-set.js';
|
|
65
|
+
export * from './augments/string/casing/capitalization.js';
|
|
66
|
+
export * from './augments/string/casing/casing.js';
|
|
67
|
+
export * from './augments/string/casing/kebab-and-camel.js';
|
|
68
|
+
export * from './augments/string/comma.js';
|
|
69
|
+
export * from './augments/string/join.js';
|
|
70
|
+
export * from './augments/string/prefix.js';
|
|
71
|
+
export * from './augments/string/remove-duplicate-characters.js';
|
|
72
|
+
export * from './augments/string/replace.js';
|
|
73
|
+
export * from './augments/string/split.js';
|
|
74
|
+
export * from './augments/string/substring-index.js';
|
|
75
|
+
export * from './augments/string/suffix.js';
|
|
76
|
+
export * from './augments/string/white-space.js';
|
|
77
|
+
export * from './augments/string/wrap-string.js';
|
|
78
|
+
export * from './augments/type/ensure-type.js';
|
|
79
|
+
export * from './augments/type/readonly.js';
|
|
80
|
+
export * from './augments/type/type-recursion.js';
|
|
81
|
+
export * from './augments/type/union.js';
|
|
82
|
+
export * from './augments/type/void-type.js';
|
|
83
|
+
export * from './augments/type/writable.js';
|