@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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PartialDeep } from 'type-fest';
|
|
2
|
+
/**
|
|
3
|
+
* Extract all nested object keys and values that are different between the two given objects.
|
|
4
|
+
*
|
|
5
|
+
* @returns An empty tuple if the values are equal.
|
|
6
|
+
*/
|
|
7
|
+
export declare function diffObjects<T0 extends Readonly<Record<PropertyKey, unknown>>, T1 extends Readonly<Record<PropertyKey, unknown>>>(object0: T0, object1: T1): [PartialDeep<T0>, PartialDeep<T1>] | [];
|
|
8
|
+
/**
|
|
9
|
+
* Extract all entries in the given arrays that are not equal.
|
|
10
|
+
*
|
|
11
|
+
* @returns An empty tuple if the values are equal.
|
|
12
|
+
*/
|
|
13
|
+
export declare function diffArrays<T0, T1>(array0: ReadonlyArray<T0>, array1: ReadonlyArray<T1>): [Array<T0>, Array<T1>] | [];
|
|
14
|
+
/** Callback for checking equality between two values that can be of different types. */
|
|
15
|
+
export type AreEqualCallback<T0, T1> = (value0: T0, value1: T1) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Simple diff check that is useful simply to return the same format as the other diff functions.
|
|
18
|
+
*
|
|
19
|
+
* @returns An empty tuple if the values are equal.
|
|
20
|
+
*/
|
|
21
|
+
export declare function diffBasic<T0, T1>(value0: T0, value1: T1,
|
|
22
|
+
/** A custom equality checker. Defaults to a strict equality check (`===`). */
|
|
23
|
+
areEqual?: AreEqualCallback<T0, T1>): [T0, T1] | [];
|
|
24
|
+
/**
|
|
25
|
+
* Diff any values. For diffing objects, use `diffObjects` to get better types.
|
|
26
|
+
*
|
|
27
|
+
* @returns An empty tuple if the values are equal.
|
|
28
|
+
*/
|
|
29
|
+
export declare function diffValues<T0, T1>(value0: T0, value1: T1): [T0, T1] | [];
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { getObjectTypedKeys } from '@augment-vir/core';
|
|
3
|
+
/**
|
|
4
|
+
* Extract all nested object keys and values that are different between the two given objects.
|
|
5
|
+
*
|
|
6
|
+
* @returns An empty tuple if the values are equal.
|
|
7
|
+
*/
|
|
8
|
+
export function diffObjects(object0, object1) {
|
|
9
|
+
const allObjectKeys = Array.from(new Set([
|
|
10
|
+
...getObjectTypedKeys(object0),
|
|
11
|
+
...getObjectTypedKeys(object1),
|
|
12
|
+
]));
|
|
13
|
+
const diffOutput = allObjectKeys.reduce((accum, objectKey) => {
|
|
14
|
+
const value0 = object0[objectKey];
|
|
15
|
+
const value1 = object1[objectKey];
|
|
16
|
+
const diffOutput = diffValues(value0, value1);
|
|
17
|
+
if (!diffOutput.length) {
|
|
18
|
+
return accum;
|
|
19
|
+
}
|
|
20
|
+
if (!(objectKey in object0)) {
|
|
21
|
+
accum[1][objectKey] = diffOutput[1];
|
|
22
|
+
}
|
|
23
|
+
else if (objectKey in object1) {
|
|
24
|
+
accum[0][objectKey] = diffOutput[0];
|
|
25
|
+
accum[1][objectKey] = diffOutput[1];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
accum[0][objectKey] = diffOutput[0];
|
|
29
|
+
}
|
|
30
|
+
return accum;
|
|
31
|
+
}, [
|
|
32
|
+
{},
|
|
33
|
+
{},
|
|
34
|
+
]);
|
|
35
|
+
if (!Object.keys(diffOutput[0]).length && !Object.keys(diffOutput[1]).length) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return diffOutput;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extract all entries in the given arrays that are not equal.
|
|
44
|
+
*
|
|
45
|
+
* @returns An empty tuple if the values are equal.
|
|
46
|
+
*/
|
|
47
|
+
export function diffArrays(array0, array1) {
|
|
48
|
+
const allArrayIndexes = Array.from(new Set([
|
|
49
|
+
...Object.keys(array0),
|
|
50
|
+
...Object.keys(array1),
|
|
51
|
+
].map((index) => Number(index)))).sort();
|
|
52
|
+
const diffArrays = allArrayIndexes.reduce((accum, arrayIndex) => {
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
54
|
+
const value0 = array0[arrayIndex];
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
56
|
+
const value1 = array1[arrayIndex];
|
|
57
|
+
const diffOutput = diffValues(value0, value1);
|
|
58
|
+
if (diffOutput.length) {
|
|
59
|
+
if (arrayIndex in array0) {
|
|
60
|
+
accum[0].push(diffOutput[0]);
|
|
61
|
+
}
|
|
62
|
+
if (arrayIndex in array1) {
|
|
63
|
+
accum[1].push(diffOutput[1]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return accum;
|
|
67
|
+
}, [
|
|
68
|
+
[],
|
|
69
|
+
[],
|
|
70
|
+
]);
|
|
71
|
+
if (!diffArrays[0].length && !diffArrays[1].length) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return diffArrays;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Simple diff check that is useful simply to return the same format as the other diff functions.
|
|
80
|
+
*
|
|
81
|
+
* @returns An empty tuple if the values are equal.
|
|
82
|
+
*/
|
|
83
|
+
export function diffBasic(value0, value1,
|
|
84
|
+
/** A custom equality checker. Defaults to a strict equality check (`===`). */
|
|
85
|
+
areEqual = (value0, value1) => value0 === value1) {
|
|
86
|
+
if (areEqual(value0, value1)) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
return [
|
|
91
|
+
value0,
|
|
92
|
+
value1,
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const orderedValueDiffs = [
|
|
97
|
+
(value0, value1) => {
|
|
98
|
+
if (!check.isArray(value0) || !check.isArray(value1)) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return diffArrays(value0, value1);
|
|
102
|
+
},
|
|
103
|
+
(value0, value1) => {
|
|
104
|
+
if (!check.instanceOf(value0, RegExp) || !check.instanceOf(value1, RegExp)) {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
/** Special case RegExps because they should be checked for equality as strings. */
|
|
108
|
+
return diffBasic(value0, value1, (a, b) => String(a) === String(b));
|
|
109
|
+
},
|
|
110
|
+
(value0, value1) => {
|
|
111
|
+
if (!check.isObject(value0) || !check.isObject(value1)) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
return diffObjects(value0, value1);
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
/**
|
|
118
|
+
* Diff any values. For diffing objects, use `diffObjects` to get better types.
|
|
119
|
+
*
|
|
120
|
+
* @returns An empty tuple if the values are equal.
|
|
121
|
+
*/
|
|
122
|
+
export function diffValues(value0, value1) {
|
|
123
|
+
let diffOutput = undefined;
|
|
124
|
+
orderedValueDiffs.some((differ) => {
|
|
125
|
+
diffOutput = differ(value0, value1);
|
|
126
|
+
return !!diffOutput;
|
|
127
|
+
});
|
|
128
|
+
if (diffOutput) {
|
|
129
|
+
return diffOutput;
|
|
130
|
+
}
|
|
131
|
+
/** Fallback to the basic diff. */
|
|
132
|
+
return diffBasic(value0, value1);
|
|
133
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MaybePromise, type AnyObject } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Get a value from a map or call the callback and return its result and store the result in the
|
|
4
|
+
* map.
|
|
5
|
+
*
|
|
6
|
+
* @category Object:Common
|
|
7
|
+
*/
|
|
8
|
+
export declare function getOrSetFromMap<MapKey extends object, MapValue>(map: WeakMap<MapKey, MapValue>, key: MapKey, createNewValueCallback: () => MapValue): MapValue;
|
|
9
|
+
export declare function getOrSetFromMap<MapKey, MapValue>(map: Map<MapKey, MapValue>, key: MapKey, createNewValueCallback: () => MapValue): MapValue;
|
|
10
|
+
/**
|
|
11
|
+
* Given an object, tries to get the given key in that object. If the key is not in that object,
|
|
12
|
+
* then the given `createCallback` is used to create a new value which is then stored in the given
|
|
13
|
+
* object and returned. Automatically handles `createCallback` returning a promise, if it does.
|
|
14
|
+
*
|
|
15
|
+
* @category Object:Common
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* // instead of doing this
|
|
20
|
+
* if (!myObject[myKey]) {
|
|
21
|
+
* myObject[myKey] = {};
|
|
22
|
+
* }
|
|
23
|
+
* myObject[myKey]![nextKey] = 'some value';
|
|
24
|
+
*
|
|
25
|
+
* // do this
|
|
26
|
+
* getOrSetInObject(myObject, myKey, () => {});
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function getOrSet<OriginalObject extends AnyObject, Key extends keyof OriginalObject>(originalObject: OriginalObject, key: Key, createCallback: () => OriginalObject[Key]): Required<OriginalObject>[Key];
|
|
30
|
+
export declare function getOrSet<OriginalObject extends AnyObject, Key extends keyof OriginalObject>(originalObject: OriginalObject, key: Key, createCallback: () => Promise<OriginalObject[Key]>): Promise<Required<OriginalObject>[Key]>;
|
|
31
|
+
export declare function getOrSet<OriginalObject extends AnyObject, Key extends keyof OriginalObject>(originalObject: OriginalObject, key: Key, createCallback: () => MaybePromise<OriginalObject[Key]>): MaybePromise<Required<OriginalObject>[Key]>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { ensureError } from '@augment-vir/core';
|
|
2
3
|
export function getOrSetFromMap(map, key, createNewValueCallback) {
|
|
3
4
|
const mapKey = key;
|
|
4
5
|
if (map.has(mapKey)) {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
5
7
|
return map.get(mapKey);
|
|
6
8
|
}
|
|
7
9
|
else {
|
|
@@ -16,7 +18,7 @@ export function getOrSet(originalObject, key, createCallback) {
|
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
18
20
|
const createdValue = createCallback();
|
|
19
|
-
if (isPromise(createdValue)) {
|
|
21
|
+
if (check.isPromise(createdValue)) {
|
|
20
22
|
return new Promise(async (resolve, reject) => {
|
|
21
23
|
try {
|
|
22
24
|
const awaitedValue = await createdValue;
|
|
@@ -24,7 +26,7 @@ export function getOrSet(originalObject, key, createCallback) {
|
|
|
24
26
|
resolve(awaitedValue);
|
|
25
27
|
}
|
|
26
28
|
catch (error) {
|
|
27
|
-
reject(error);
|
|
29
|
+
reject(ensureError(error));
|
|
28
30
|
}
|
|
29
31
|
});
|
|
30
32
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { AnyObject } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Counts the number of unique keys in an object type. Note that a key of just `string` will count
|
|
4
|
+
* as 1.
|
|
5
|
+
*/
|
|
6
|
+
export type KeyCount<T extends AnyObject> = UnionToTuple<keyof T>['length'];
|
|
3
7
|
/**
|
|
4
8
|
* This is not exported because its order is not stable but it's okay for our simple use case where
|
|
5
9
|
* we simply want to count the size of the union.
|
|
6
10
|
*/
|
|
7
11
|
type UnionToTuple<T> = UnionToIntersection<T extends any ? (t: T) => T : never> extends (args: any) => infer W ? [...UnionToTuple<Exclude<T, W>>, W] : [];
|
|
8
12
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
13
|
+
* This is the version of UnionToIntersection from type-fest v4.3.3. In version 4.4.0 type-fest
|
|
14
|
+
* changed this type helper and it broke how we're using it.
|
|
11
15
|
*/
|
|
12
|
-
|
|
16
|
+
type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection : never;
|
|
13
17
|
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Values, type MaybePromise } from '@augment-vir/core';
|
|
2
|
+
export declare function mapObject<const OriginalObject, const NewKey extends PropertyKey, const NewValue>(inputObject: OriginalObject, mapCallback: (originalKey: keyof OriginalObject, originalValue: Values<OriginalObject>, originalObject: OriginalObject) => Promise<{
|
|
3
|
+
key: NewKey;
|
|
4
|
+
value: NewValue;
|
|
5
|
+
} | undefined>): Promise<Record<NewKey, NewValue>>;
|
|
6
|
+
export declare function mapObject<const OriginalObject, const NewKey extends PropertyKey, const NewValue>(inputObject: OriginalObject, mapCallback: (originalKey: keyof OriginalObject, originalValue: Values<OriginalObject>, originalObject: OriginalObject) => {
|
|
7
|
+
key: NewKey;
|
|
8
|
+
value: NewValue;
|
|
9
|
+
} | undefined): Record<NewKey, NewValue>;
|
|
10
|
+
export declare function mapObject<const OriginalObject, const NewKey extends PropertyKey, const NewValue>(inputObject: OriginalObject, mapCallback: (originalKey: keyof OriginalObject, originalValue: Values<OriginalObject>, originalObject: OriginalObject) => MaybePromise<{
|
|
11
|
+
key: NewKey;
|
|
12
|
+
value: NewValue;
|
|
13
|
+
} | undefined>): MaybePromise<Record<NewKey, NewValue>>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { ensureError } from '@augment-vir/core';
|
|
3
|
+
import { filterMap } from '../array/filter.js';
|
|
4
|
+
import { getObjectTypedEntries, typedObjectFromEntries } from './object-entries.js';
|
|
5
|
+
export function mapObject(originalObject, mapCallback) {
|
|
6
|
+
try {
|
|
7
|
+
let gotAPromise = false;
|
|
8
|
+
const mappedEntries = getObjectTypedEntries(originalObject)
|
|
9
|
+
.map(([originalKey, originalValue,]) => {
|
|
10
|
+
const output = mapCallback(originalKey, originalValue, originalObject);
|
|
11
|
+
if (output instanceof Promise) {
|
|
12
|
+
gotAPromise = true;
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
else if (output) {
|
|
16
|
+
return [
|
|
17
|
+
output.key,
|
|
18
|
+
output.value,
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
.filter(check.isTruthy);
|
|
26
|
+
if (gotAPromise) {
|
|
27
|
+
return new Promise(async (resolve, reject) => {
|
|
28
|
+
try {
|
|
29
|
+
const entries = filterMap(await Promise.all(mappedEntries), (entry) => {
|
|
30
|
+
if (!entry) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
else if (Array.isArray(entry)) {
|
|
34
|
+
return entry;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return [
|
|
38
|
+
entry.key,
|
|
39
|
+
entry.value,
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
}, check.isTruthy);
|
|
43
|
+
resolve(typedObjectFromEntries(entries));
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
reject(ensureError(error));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return typedObjectFromEntries(mappedEntries);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
throw ensureError(error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EnumBaseType, MaybePromise, Values } from '@augment-vir/core';
|
|
2
|
+
export type EnumMap<Enum extends EnumBaseType, Value> = Values<Enum> extends PropertyKey ? Record<Values<Enum>, Value> : 'ERROR: invalid enum';
|
|
3
|
+
export declare function mapEnumToObject<const Enum extends EnumBaseType, const Value>(enumInput: Enum, callback: (enumValue: Values<Enum>) => Promise<Value>): Promise<EnumMap<Enum, Value>>;
|
|
4
|
+
export declare function mapEnumToObject<const Enum extends EnumBaseType, const Value>(enumInput: Enum, callback: (enumValue: Values<Enum>, wholeEnum: Enum) => Value): Value extends Promise<any> ? Promise<any> extends Value ? Promise<EnumMap<Enum, Awaited<Value>>> : MaybePromise<EnumMap<Enum, Awaited<Value>>> : EnumMap<Enum, Value>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { mapObject } from './map-entries.js';
|
|
2
|
+
export function mapEnumToObject(enumInput, callback) {
|
|
3
|
+
return mapObject(enumInput, (enumKey, enumValue) => {
|
|
4
|
+
const key = enumValue;
|
|
5
|
+
const value = callback(enumValue, enumInput);
|
|
6
|
+
if (value instanceof Promise) {
|
|
7
|
+
return value.then((resolvedValue) => {
|
|
8
|
+
return {
|
|
9
|
+
key,
|
|
10
|
+
value: resolvedValue,
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return {
|
|
16
|
+
key,
|
|
17
|
+
value,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Values } from '@augment-vir/core';
|
|
2
2
|
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
|
|
3
3
|
[MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
|
|
4
4
|
};
|
|
@@ -10,9 +10,12 @@ export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric>
|
|
|
10
10
|
* to explicitly state the return type.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback);
|
|
16
|
+
* ```
|
|
14
17
|
*/
|
|
15
|
-
export declare function mapObjectValuesSync<EntireInputGeneric extends object>(inputObject: EntireInputGeneric): <OutputObjectGeneric extends object>(mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: Required<EntireInputGeneric>[typeof inputKey], fullObject: EntireInputGeneric) => never extends
|
|
18
|
+
export declare function mapObjectValuesSync<EntireInputGeneric extends object>(inputObject: EntireInputGeneric): <OutputObjectGeneric extends object>(mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: Required<EntireInputGeneric>[typeof inputKey], fullObject: EntireInputGeneric) => never extends Values<OutputObjectGeneric> ? any : Values<OutputObjectGeneric>) => OutputObjectGeneric;
|
|
16
19
|
/**
|
|
17
20
|
* Creates a new object with the same properties as the input object, but with values set to the
|
|
18
21
|
* result of mapCallback for each property.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getObjectTypedKeys } from '
|
|
1
|
+
import { ensureError, getObjectTypedKeys } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
4
4
|
* that this will not wrap the return value in a promise if any of the new object values are
|
|
@@ -6,18 +6,20 @@ import { getObjectTypedKeys } from './object-entries';
|
|
|
6
6
|
* to explicitly state the return type.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback);
|
|
12
|
+
* ```
|
|
10
13
|
*/
|
|
11
14
|
export function mapObjectValuesSync(inputObject) {
|
|
12
15
|
function innerMap(mapCallback) {
|
|
13
|
-
|
|
16
|
+
return getObjectTypedKeys(inputObject).reduce((accum, currentKey) => {
|
|
14
17
|
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
|
|
15
18
|
return {
|
|
16
19
|
...accum,
|
|
17
20
|
[currentKey]: mappedValue,
|
|
18
21
|
};
|
|
19
22
|
}, {});
|
|
20
|
-
return mappedObject;
|
|
21
23
|
}
|
|
22
24
|
return innerMap;
|
|
23
25
|
}
|
|
@@ -32,10 +34,8 @@ export function mapObjectValues(inputObject, mapCallback) {
|
|
|
32
34
|
if (mappedValue instanceof Promise) {
|
|
33
35
|
gotAPromise = true;
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
[currentKey]: mappedValue,
|
|
38
|
-
};
|
|
37
|
+
accum[currentKey] = mappedValue;
|
|
38
|
+
return accum;
|
|
39
39
|
}, {});
|
|
40
40
|
if (gotAPromise) {
|
|
41
41
|
return new Promise(async (resolve, reject) => {
|
|
@@ -47,7 +47,7 @@ export function mapObjectValues(inputObject, mapCallback) {
|
|
|
47
47
|
resolve(mappedObject);
|
|
48
48
|
}
|
|
49
49
|
catch (error) {
|
|
50
|
-
reject(error);
|
|
50
|
+
reject(ensureError(error));
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isLengthAtLeast } from '../tuple';
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
3
2
|
/**
|
|
4
3
|
* Accepts multiple objects and merges their key-value pairs recursively. Any values set to
|
|
5
4
|
* undefined will be removed.
|
|
@@ -7,7 +6,7 @@ import { isLengthAtLeast } from '../tuple';
|
|
|
7
6
|
* Note that order matters! Each input object will overwrite the properties of the previous objects.
|
|
8
7
|
*/
|
|
9
8
|
export function mergeDeep(...inputs) {
|
|
10
|
-
if (!isLengthAtLeast(inputs, 1)) {
|
|
9
|
+
if (!check.isLengthAtLeast(inputs, 1)) {
|
|
11
10
|
// nothing to merge if no inputs
|
|
12
11
|
return {};
|
|
13
12
|
}
|
|
@@ -18,12 +17,12 @@ export function mergeDeep(...inputs) {
|
|
|
18
17
|
let result = undefined;
|
|
19
18
|
const mergeProps = {};
|
|
20
19
|
inputs.forEach((individualInput) => {
|
|
21
|
-
if (!
|
|
20
|
+
if (!check.isObject(individualInput)) {
|
|
22
21
|
/** If not an object, we can't merge. So overwrite instead. */
|
|
23
22
|
result = individualInput;
|
|
24
23
|
return;
|
|
25
24
|
}
|
|
26
|
-
else if (!
|
|
25
|
+
else if (!check.isObject(result)) {
|
|
27
26
|
/** If result isn't an object then we need to make it into one. */
|
|
28
27
|
result = { ...individualInput };
|
|
29
28
|
}
|
|
@@ -34,7 +33,7 @@ export function mergeDeep(...inputs) {
|
|
|
34
33
|
mergeProps[key].push(value);
|
|
35
34
|
});
|
|
36
35
|
});
|
|
37
|
-
if (
|
|
36
|
+
if (check.isObject(result)) {
|
|
38
37
|
Object.entries(mergeProps).forEach(([key, mergeValues,]) => {
|
|
39
38
|
const newValue = mergeDeep(...mergeValues);
|
|
40
39
|
if (newValue === undefined && key in result) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AnyObject, PartialWithNullable } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Merge all objects together but ignore any override values that are `undefined` or `null` or
|
|
4
|
+
* missing. This only merges objects at the top level, it is not a deep merge.
|
|
5
|
+
*/
|
|
6
|
+
export declare function mergeDefinedProperties<const T extends AnyObject>(original: T, ...overrides: ReadonlyArray<PartialWithNullable<NoInfer<T>> | undefined>): T;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getObjectTypedEntries } from './object-entries.js';
|
|
2
|
+
/**
|
|
3
|
+
* Merge all objects together but ignore any override values that are `undefined` or `null` or
|
|
4
|
+
* missing. This only merges objects at the top level, it is not a deep merge.
|
|
5
|
+
*/
|
|
6
|
+
export function mergeDefinedProperties(original, ...overrides) {
|
|
7
|
+
const finalObject = { ...original };
|
|
8
|
+
overrides.forEach((entry) => {
|
|
9
|
+
if (!entry) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
getObjectTypedEntries(entry).forEach(([key, value,]) => {
|
|
13
|
+
if (value != undefined) {
|
|
14
|
+
finalObject[key] = value;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
return finalObject;
|
|
19
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CompleteRequire } from '@augment-vir/core';
|
|
2
|
+
export declare function getObjectTypedEntries<const ObjectGeneric>(input: ObjectGeneric): [keyof ObjectGeneric, CompleteRequire<ObjectGeneric>[keyof CompleteRequire<ObjectGeneric>]][];
|
|
3
|
+
export declare function typedObjectFromEntries<const KeyType extends PropertyKey, const ValueType>(entries: ReadonlyArray<Readonly<[KeyType, ValueType]>>): Record<KeyType, ValueType>;
|
|
4
|
+
export declare function getEntriesSortedByKey<const ObjectGeneric>(input: ObjectGeneric): [keyof ObjectGeneric, CompleteRequire<ObjectGeneric>[keyof CompleteRequire<ObjectGeneric>]][];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getObjectTypedKeys } from '@augment-vir/core';
|
|
2
|
+
export function getObjectTypedEntries(input) {
|
|
3
|
+
return getObjectTypedKeys(input).map((key) => [
|
|
4
|
+
key,
|
|
5
|
+
input[key],
|
|
6
|
+
]);
|
|
7
|
+
}
|
|
8
|
+
export function typedObjectFromEntries(entries) {
|
|
9
|
+
return Object.fromEntries(entries);
|
|
10
|
+
}
|
|
11
|
+
export function getEntriesSortedByKey(input) {
|
|
12
|
+
return getObjectTypedEntries(input).sort((tupleA, tupleB) => String(tupleA[0]).localeCompare(String(tupleB[0])));
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getObjectTypedEntries, typedObjectFromEntries } from './object-entries.js';
|
|
2
|
+
export function filterObject(inputObject, callback) {
|
|
3
|
+
const filteredEntries = getObjectTypedEntries(inputObject).filter(([key, value,]) => {
|
|
4
|
+
return callback(key, value, inputObject);
|
|
5
|
+
});
|
|
6
|
+
return typedObjectFromEntries(filteredEntries);
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function omitObjectKeys<const ObjectGeneric, const KeyGeneric extends keyof ObjectGeneric>(inputObject: Readonly<ObjectGeneric>, omitTheseKeys: ReadonlyArray<KeyGeneric>): Omit<ObjectGeneric, KeyGeneric>;
|
|
2
|
+
export declare function pickObjectKeys<const ObjectGeneric, const KeyGeneric extends keyof ObjectGeneric>(inputObject: Readonly<ObjectGeneric>, pickTheseKeys: ReadonlyArray<KeyGeneric>): Pick<ObjectGeneric, KeyGeneric>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { filterObject } from './object-filter.js';
|
|
2
|
+
export function omitObjectKeys(inputObject, omitTheseKeys) {
|
|
3
|
+
return filterObject(inputObject, (currentKey) => {
|
|
4
|
+
return !omitTheseKeys.includes(currentKey);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
export function pickObjectKeys(inputObject, pickTheseKeys) {
|
|
8
|
+
return filterObject(inputObject, (currentKey) => {
|
|
9
|
+
return pickTheseKeys.includes(currentKey);
|
|
10
|
+
});
|
|
11
|
+
}
|