@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.
- package/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/dist/augments/array/array-map.d.ts +6 -0
- package/dist/augments/array/array-map.js +4 -0
- package/dist/augments/array/array-to-object.d.ts +17 -0
- package/dist/augments/array/array-to-object.js +31 -0
- package/dist/augments/array/awaited/awaited-filter.d.ts +7 -0
- package/dist/augments/array/awaited/awaited-filter.js +7 -0
- package/dist/augments/array/awaited/awaited-for-each.d.ts +6 -0
- package/dist/augments/array/awaited/awaited-for-each.js +9 -0
- package/dist/augments/array/awaited/awaited-map.d.ts +1 -0
- package/dist/augments/array/awaited/awaited-map.js +8 -0
- package/dist/augments/array/filter.d.ts +3 -0
- package/dist/augments/array/filter.js +13 -0
- package/dist/augments/array/repeat-array.d.ts +1 -0
- package/dist/augments/array/repeat-array.js +3 -0
- package/dist/augments/array/shuffle-array.d.ts +2 -0
- package/dist/augments/array/shuffle-array.js +10 -0
- package/dist/augments/array/string-array.d.ts +1 -0
- package/dist/augments/array/string-array.js +3 -0
- package/dist/augments/boolean/if-truthy.d.ts +2 -0
- package/dist/{esm/augments/boolean.js → augments/boolean/if-truthy.js} +2 -7
- 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 +2 -0
- package/dist/augments/enum/enum-value-check.js +4 -0
- package/dist/augments/error/combine-errors.d.ts +3 -0
- package/dist/augments/error/combine-errors.js +12 -0
- package/dist/augments/function/call-asynchronously.d.ts +6 -0
- package/dist/augments/function/call-asynchronously.js +7 -0
- package/dist/augments/function/call-with-retries.d.ts +4 -0
- package/dist/augments/function/call-with-retries.js +27 -0
- package/dist/augments/function/debounce.d.ts +22 -0
- package/dist/augments/function/debounce.js +50 -0
- package/dist/augments/function/execution-duration.d.ts +8 -0
- package/dist/{esm/augments/time.js → augments/function/execution-duration.js} +7 -12
- package/dist/{types/augments → augments/function}/wrap-in-try.d.ts +2 -3
- package/dist/{esm/augments → augments/function}/wrap-in-try.js +4 -4
- package/dist/augments/json/append-json.d.ts +5 -0
- package/dist/augments/json/append-json.js +26 -0
- package/dist/augments/json/copy-through-json.d.ts +3 -0
- package/dist/augments/json/copy-through-json.js +11 -0
- package/dist/augments/json/jsonify.d.ts +2 -0
- package/dist/augments/json/jsonify.js +4 -0
- package/dist/augments/log/log-colors.d.ts +23 -0
- package/dist/augments/log/log-colors.js +116 -0
- package/dist/augments/log/log-string.d.ts +14 -0
- package/dist/augments/log/log-string.js +66 -0
- package/dist/augments/log/log-writer.d.ts +8 -0
- package/dist/augments/log/log.d.ts +13 -0
- package/dist/augments/log/log.js +42 -0
- package/dist/augments/log/logger.d.ts +11 -0
- package/dist/augments/log/logger.js +38 -0
- package/dist/augments/number/clamp.d.ts +7 -0
- package/dist/augments/number/clamp.js +8 -0
- package/dist/augments/number/coords.d.ts +19 -0
- package/dist/augments/number/digit.d.ts +1 -0
- package/dist/augments/number/dimensions.d.ts +19 -0
- package/dist/augments/number/min-max.d.ts +11 -0
- package/dist/augments/number/min-max.js +14 -0
- package/dist/augments/number/number-conversion.d.ts +23 -0
- package/dist/augments/number/number-conversion.js +50 -0
- package/dist/augments/number/round.d.ts +3 -0
- package/dist/augments/number/round.js +5 -0
- package/dist/augments/number/scientific.d.ts +1 -0
- package/dist/augments/number/scientific.js +3 -0
- package/dist/{esm/augments → augments/number}/truncate-number.js +14 -12
- package/dist/augments/number/wrap-number.d.ts +13 -0
- package/dist/augments/number/wrap-number.js +22 -0
- package/dist/augments/object/diff.d.ts +29 -0
- package/dist/augments/object/diff.js +133 -0
- package/dist/augments/object/empty.d.ts +3 -0
- package/dist/augments/object/get-or-set.d.ts +31 -0
- package/dist/{esm/augments → augments}/object/get-or-set.js +5 -3
- package/dist/{types/augments → augments}/object/key-count.d.ts +9 -5
- package/dist/augments/object/map-entries.d.ts +13 -0
- package/dist/augments/object/map-entries.js +57 -0
- package/dist/augments/object/map-enum.d.ts +4 -0
- package/dist/augments/object/map-enum.js +21 -0
- package/dist/{types/augments/object/map-object.d.ts → augments/object/map-values.d.ts} +6 -3
- package/dist/{esm/augments/object/map-object.js → augments/object/map-values.js} +9 -9
- package/dist/{esm/augments → augments}/object/merge-deep.js +5 -6
- package/dist/augments/object/merge-defined-properties.d.ts +6 -0
- package/dist/augments/object/merge-defined-properties.js +19 -0
- package/dist/{esm/augments → augments}/object/merge-property-arrays.js +1 -1
- package/dist/augments/object/object-entries.d.ts +4 -0
- package/dist/augments/object/object-entries.js +13 -0
- package/dist/augments/object/object-filter.d.ts +2 -0
- package/dist/augments/object/object-filter.js +7 -0
- package/dist/augments/object/object-keys.d.ts +2 -0
- package/dist/augments/object/object-keys.js +11 -0
- package/dist/augments/object/object-values.d.ts +2 -0
- package/dist/augments/object/object-values.js +4 -0
- package/dist/augments/prisma/prisma-models.d.ts +106 -0
- package/dist/augments/prisma/prisma-models.js +1 -0
- package/dist/augments/promise/timed-promise.d.ts +7 -0
- package/dist/augments/promise/timed-promise.js +36 -0
- package/dist/augments/random/random-boolean.d.ts +18 -0
- package/dist/augments/random/random-boolean.js +26 -0
- package/dist/augments/random/random-integer.d.ts +12 -0
- package/dist/augments/random/random-integer.js +32 -0
- package/dist/augments/random/random-string.d.ts +14 -0
- package/dist/augments/random/random-string.js +63 -0
- package/dist/{types/augments/regexp.d.ts → augments/regexp/regexp-flags.d.ts} +1 -1
- package/dist/augments/regexp/regexp-flags.js +18 -0
- package/dist/augments/regexp/regexp-string.d.ts +5 -0
- package/dist/augments/regexp/regexp-string.js +7 -0
- package/dist/augments/regexp/safe-match.d.ts +1 -0
- package/dist/augments/regexp/safe-match.js +4 -0
- package/dist/augments/selection-set/select-collapsed.d.ts +11 -0
- package/dist/augments/selection-set/select-collapsed.js +25 -0
- package/dist/augments/selection-set/select-from.d.ts +3 -0
- package/dist/augments/selection-set/select-from.js +25 -0
- package/dist/augments/selection-set/selection-set.d.ts +18 -0
- package/dist/augments/selection-set/selection-set.js +4 -0
- package/dist/augments/string/casing/capitalization.d.ts +3 -0
- package/dist/augments/string/casing/capitalization.js +11 -0
- package/dist/augments/string/casing/casing.d.ts +27 -0
- package/dist/augments/string/casing/casing.js +40 -0
- package/dist/augments/string/casing/kebab-and-camel.d.ts +3 -0
- package/dist/augments/string/casing/kebab-and-camel.js +42 -0
- package/dist/augments/string/commas.d.ts +7 -0
- package/dist/augments/string/commas.js +29 -0
- package/dist/augments/string/join.d.ts +10 -0
- package/dist/augments/string/join.js +23 -0
- package/dist/{types/augments/string/prefixes.d.ts → augments/string/prefix.d.ts} +16 -1
- package/dist/{esm/augments/string/prefixes.js → augments/string/prefix.js} +11 -1
- package/dist/augments/string/replace.d.ts +1 -0
- package/dist/augments/string/replace.js +5 -0
- package/dist/augments/string/split.d.ts +4 -0
- package/dist/augments/string/split.js +28 -0
- package/dist/augments/string/substring-index.d.ts +13 -0
- package/dist/augments/string/substring-index.js +38 -0
- package/dist/augments/string/suffix.d.ts +74 -0
- package/dist/augments/string/suffix.js +73 -0
- package/dist/augments/string/white-space.d.ts +5 -0
- package/dist/augments/string/white-space.js +12 -0
- package/dist/augments/string/wrap-string.d.ts +4 -0
- package/dist/augments/string/wrap-string.js +5 -0
- package/dist/augments/type/ensure-type.d.ts +8 -0
- package/dist/augments/type/ensure-type.js +10 -0
- package/dist/augments/type/readonly.d.ts +2 -0
- package/dist/augments/type/readonly.js +3 -0
- package/dist/augments/type/type-recursion.js +1 -0
- package/dist/augments/type/void-type.d.ts +5 -0
- package/dist/augments/type/void-type.js +1 -0
- package/dist/augments/type/writable.d.ts +3 -0
- package/dist/augments/type/writable.js +3 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +81 -0
- package/package.json +33 -15
- package/README.md +0 -7
- 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 -123
- 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 -7
- 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/async.js +0 -23
- 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/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/has-key.js +0 -3
- package/dist/esm/augments/object/jsonify.js +0 -3
- 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 -117
- package/dist/esm/augments/regexp.js +0 -14
- package/dist/esm/augments/string/suffixes.js +0 -31
- package/dist/esm/augments/string/uuid.js +0 -4
- package/dist/esm/augments/tuple.js +0 -16
- package/dist/esm/augments/type.js +0 -30
- 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/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/function.d.ts +0 -25
- 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/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 -39
- package/dist/types/augments/string/suffixes.d.ts +0 -17
- package/dist/types/augments/string/uuid.d.ts +0 -1
- package/dist/types/augments/time.d.ts +0 -14
- package/dist/types/augments/tuple.d.ts +0 -17
- 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/{types/augments → augments}/array/remove-duplicates.d.ts +0 -0
- /package/dist/{esm/augments → augments}/array/remove-duplicates.js +0 -0
- /package/dist/{types/augments → augments/file}/esm-path.d.ts +0 -0
- /package/dist/{esm/augments → augments/file}/esm-path.js +0 -0
- /package/dist/{types/augments → augments/json}/json-compatible.d.ts +0 -0
- /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/{types/augments → augments/number}/truncate-number.d.ts +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
- /package/dist/{types/augments → augments}/object/merge-deep.d.ts +0 -0
- /package/dist/{types/augments → augments}/object/merge-property-arrays.d.ts +0 -0
- /package/dist/{types/augments → augments/type}/type-recursion.d.ts +0 -0
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { getOrSet } from '../object/get-or-set';
|
|
2
|
-
import { typedObjectFromEntries } from '../object/object-entries';
|
|
3
|
-
export function filterOutIndexes(array, indexes) {
|
|
4
|
-
return array.filter((_, index) => !indexes.includes(index));
|
|
5
|
-
}
|
|
6
|
-
export function flatten2dArray(array2d) {
|
|
7
|
-
const flattened = array2d.reduce((accum, row) => accum.concat(row), []);
|
|
8
|
-
return flattened;
|
|
9
|
-
}
|
|
10
|
-
export function trimArrayStrings(input) {
|
|
11
|
-
return input.map((line) => line.trim()).filter((line) => line !== '');
|
|
12
|
-
}
|
|
13
|
-
export function typedArrayIncludes(array, input) {
|
|
14
|
-
return array.includes(input);
|
|
15
|
-
}
|
|
16
|
-
/** Preserves tuple types. */
|
|
17
|
-
export function typedMap(arrayToMap, mapCallback) {
|
|
18
|
-
return arrayToMap.map(mapCallback);
|
|
19
|
-
}
|
|
20
|
-
export function repeatArray(repeatCount, array) {
|
|
21
|
-
return Array.from({ length: repeatCount }, () => [...array]).flat();
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Polyfill for `Object.groupBy`:
|
|
25
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy
|
|
26
|
-
*/
|
|
27
|
-
export function groupArrayBy(inputArray, callback) {
|
|
28
|
-
return inputArray.reduce((accum, entry, index, originalArray) => {
|
|
29
|
-
const key = callback(entry, index, originalArray);
|
|
30
|
-
const entryArray = getOrSet(accum, key, () => []);
|
|
31
|
-
entryArray.push(entry);
|
|
32
|
-
return accum;
|
|
33
|
-
}, {});
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Like `groupArrayBy` but maps array entries to a single key. Meaning, the resulting object does
|
|
37
|
-
* not have an array of elements (unless the original array itself contains arrays).
|
|
38
|
-
*/
|
|
39
|
-
export function arrayToObject(inputArray, callback) {
|
|
40
|
-
return typedObjectFromEntries(inputArray.map((entry, index, originalArray) => {
|
|
41
|
-
const key = callback(entry, index, originalArray);
|
|
42
|
-
return [
|
|
43
|
-
key,
|
|
44
|
-
entry,
|
|
45
|
-
];
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
export function filterMap(inputArray, mapCallback, filterCallback) {
|
|
49
|
-
return inputArray.reduce((accum, entry, index, originalArray) => {
|
|
50
|
-
const mapOutput = mapCallback(entry, index, originalArray);
|
|
51
|
-
const filterOutput = filterCallback(mapOutput, entry, index, originalArray);
|
|
52
|
-
if (filterOutput) {
|
|
53
|
-
accum.push(mapOutput);
|
|
54
|
-
}
|
|
55
|
-
return accum;
|
|
56
|
-
}, []);
|
|
57
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Acts like calling Array.prototype.forEach in that all elements are executed upon in order, and
|
|
3
|
-
* each execution is blocking. Meaning, the callback won't be called on element 2 until the callback
|
|
4
|
-
* has finished its call on element 1.
|
|
5
|
-
*/
|
|
6
|
-
export async function awaitedForEach(input, callback) {
|
|
7
|
-
await awaitedBlockingMap(input, callback);
|
|
8
|
-
}
|
|
9
|
-
export async function awaitedBlockingMap(input, callback) {
|
|
10
|
-
const mappedValues = await input.reduce(async (accumPromise, currentElement, index, wholeArray) => {
|
|
11
|
-
const accum = await accumPromise;
|
|
12
|
-
const mappedValue = await callback(currentElement, index, wholeArray);
|
|
13
|
-
accum.push(mappedValue);
|
|
14
|
-
return accum;
|
|
15
|
-
}, Promise.resolve([]));
|
|
16
|
-
return mappedValues;
|
|
17
|
-
}
|
|
18
|
-
export async function awaitedFilter(arrayInput, filterCallback, options) {
|
|
19
|
-
const callbackResults = options?.blocking
|
|
20
|
-
? await awaitedBlockingMap(arrayInput, filterCallback)
|
|
21
|
-
: await Promise.all(arrayInput.map(filterCallback));
|
|
22
|
-
return arrayInput.filter((originalValue, index) => !!callbackResults[index]);
|
|
23
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { removeCommasFromNumberString } from './common-string';
|
|
2
|
-
import { safeMatch } from './regexp';
|
|
3
|
-
export const NaNString = String(NaN);
|
|
4
|
-
export function addCommasToNumber(input) {
|
|
5
|
-
if (typeof input === 'string' && isNaN(Number(input))) {
|
|
6
|
-
return NaNString;
|
|
7
|
-
}
|
|
8
|
-
const numericValue = Number(input);
|
|
9
|
-
const isNegative = numericValue < 0;
|
|
10
|
-
const stringValue = String(Math.abs(numericValue));
|
|
11
|
-
const [digits, decimalValues,] = stringValue.split('.');
|
|
12
|
-
const decimalString = decimalValues ? `.${decimalValues}` : '';
|
|
13
|
-
const separated = safeMatch(digits.split('').reverse().join(''), /.{1,3}/g)
|
|
14
|
-
.reverse()
|
|
15
|
-
.map((entry) => entry.split('').reverse().join(''));
|
|
16
|
-
const valueWithCommas = separated.join(',');
|
|
17
|
-
const negativeMarker = isNegative ? '-' : '';
|
|
18
|
-
return [
|
|
19
|
-
negativeMarker,
|
|
20
|
-
valueWithCommas,
|
|
21
|
-
decimalString,
|
|
22
|
-
].join('');
|
|
23
|
-
}
|
|
24
|
-
export function doesRequireScientificNotation(input) {
|
|
25
|
-
return String(input).includes('e');
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
29
|
-
* that is not the case, the returned value is the given min and max values swapped.
|
|
30
|
-
*/
|
|
31
|
-
export function ensureMinAndMax({ min, max }) {
|
|
32
|
-
if (min > max) {
|
|
33
|
-
return { min: max, max: min };
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return { min, max };
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Tries to convert the input into a number. Handles strings with commas. Note: this might return
|
|
41
|
-
* `NaN`.
|
|
42
|
-
*/
|
|
43
|
-
export function toNumber(input) {
|
|
44
|
-
if (typeof input === 'number') {
|
|
45
|
-
return input;
|
|
46
|
-
}
|
|
47
|
-
else if (typeof input === 'string') {
|
|
48
|
-
return Number(removeCommasFromNumberString(input));
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
return Number(input);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/** @deprecated Use {@link toNumber} instead. */
|
|
55
|
-
export const convertIntoNumber = toNumber;
|
|
56
|
-
/** Tries to convert the input into a number and throws an error if `NaN` is created. */
|
|
57
|
-
export function toEnsuredNumber(input) {
|
|
58
|
-
const numeric = toMaybeNumber(input);
|
|
59
|
-
if (numeric == undefined) {
|
|
60
|
-
throw new Error(`Cannot convert to a number: ${input}`);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
return numeric;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/** Tries to convert the input into a number and returns `undefined` if `NaN` is created. */
|
|
67
|
-
export function toMaybeNumber(input) {
|
|
68
|
-
const numeric = toNumber(input);
|
|
69
|
-
if (isNaN(numeric)) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return numeric;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* If the given value is outside the given min/max bounds, instead of clamping the number (as the
|
|
78
|
-
* `clamp` function does), this function wraps the value around to the next bound.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* wrapNumber({min: 0, max: 100, value: 101}) == 0;
|
|
82
|
-
*/
|
|
83
|
-
export function wrapNumber({ max, min, value }) {
|
|
84
|
-
if (value > max) {
|
|
85
|
-
return min;
|
|
86
|
-
}
|
|
87
|
-
else if (value < min) {
|
|
88
|
-
return max;
|
|
89
|
-
}
|
|
90
|
-
return value;
|
|
91
|
-
}
|
|
92
|
-
export function round(inputs) {
|
|
93
|
-
const digitFactor = Math.pow(10, inputs.digits);
|
|
94
|
-
const multiplied = inputs.number * digitFactor;
|
|
95
|
-
return Number((Math.round(multiplied) / digitFactor).toFixed(inputs.digits));
|
|
96
|
-
}
|
|
97
|
-
/** Clamp's the given value to within the min and max bounds, inclusive. */
|
|
98
|
-
export function clamp({ value, min, max }) {
|
|
99
|
-
return Math.min(Math.max(value, min), max);
|
|
100
|
-
}
|
|
@@ -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,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,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,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
|
-
}
|