@augment-vir/common 28.2.4 → 29.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/cjs/augments/array/array.js +9 -10
  2. package/dist/cjs/augments/array/remove-duplicates.js +1 -2
  3. package/dist/cjs/augments/async.js +3 -4
  4. package/dist/cjs/augments/boolean.js +3 -4
  5. package/dist/cjs/augments/common-number.js +10 -10
  6. package/dist/cjs/augments/common-string.js +16 -16
  7. package/dist/cjs/augments/debounce.js +2 -2
  8. package/dist/cjs/augments/environment.js +1 -2
  9. package/dist/cjs/augments/error.js +5 -6
  10. package/dist/cjs/augments/esm-path.js +1 -2
  11. package/dist/cjs/augments/json.js +2 -3
  12. package/dist/cjs/augments/object/enum.js +5 -6
  13. package/dist/cjs/augments/object/filter-object.js +3 -4
  14. package/dist/cjs/augments/object/get-or-set.js +2 -3
  15. package/dist/cjs/augments/object/has-key.js +1 -2
  16. package/dist/cjs/augments/object/jsonify.js +1 -2
  17. package/dist/cjs/augments/object/map-object.js +2 -3
  18. package/dist/cjs/augments/object/merge-deep.js +1 -2
  19. package/dist/cjs/augments/object/merge-property-arrays.js +1 -2
  20. package/dist/cjs/augments/object/object-entries.js +6 -7
  21. package/dist/cjs/augments/object/object.js +2 -3
  22. package/dist/cjs/augments/object/selection-set.js +24 -0
  23. package/dist/cjs/augments/object/typed-has-property.js +2 -3
  24. package/dist/cjs/augments/promise/deferred-promise.js +1 -2
  25. package/dist/cjs/augments/promise/promise.js +5 -5
  26. package/dist/cjs/augments/promise/wait.js +4 -4
  27. package/dist/cjs/augments/random.js +4 -5
  28. package/dist/cjs/augments/regexp.js +3 -4
  29. package/dist/cjs/augments/string/prefixes.js +2 -3
  30. package/dist/cjs/augments/string/suffixes.js +7 -7
  31. package/dist/cjs/augments/string/uuid.js +1 -2
  32. package/dist/cjs/augments/time.js +2 -2
  33. package/dist/cjs/augments/truncate-number.js +1 -2
  34. package/dist/cjs/augments/tuple.js +2 -3
  35. package/dist/cjs/augments/type.js +4 -5
  36. package/dist/cjs/augments/union.js +2 -0
  37. package/dist/cjs/augments/wrap-in-try.js +1 -2
  38. package/dist/cjs/index.js +3 -2
  39. package/dist/esm/augments/object/selection-set.js +21 -0
  40. package/dist/esm/augments/union.js +1 -0
  41. package/dist/esm/index.js +3 -2
  42. package/dist/types/augments/object/key-count.d.ts +13 -0
  43. package/dist/types/augments/object/map-object.d.ts +1 -1
  44. package/dist/types/augments/object/pick-deep.d.ts +0 -6
  45. package/dist/types/augments/object/selection-set.d.ts +26 -0
  46. package/dist/types/index.d.ts +3 -2
  47. package/package.json +2 -2
  48. package/dist/cjs/augments/object/nested-keys.js +0 -61
  49. package/dist/esm/augments/object/nested-keys.js +0 -56
  50. package/dist/types/augments/object/nested-keys.d.ts +0 -18
  51. /package/dist/cjs/augments/object/{old-union-to-intersection.js → key-count.js} +0 -0
  52. /package/dist/esm/augments/object/{old-union-to-intersection.js → key-count.js} +0 -0
  53. /package/dist/types/augments/{object/old-union-to-intersection.d.ts → union.d.ts} +0 -0
@@ -1,56 +0,0 @@
1
- import { isRunTimeType } from 'run-time-assertions';
2
- import { isLengthAtLeast } from '../tuple';
3
- import { isObject } from './object';
4
- import { typedHasProperty } from './typed-has-property';
5
- /** This mutates the {@link originalObject} input. */
6
- export function setValueWithNestedKeys(originalObject, nestedKeys, value) {
7
- /**
8
- * Lots of as any casts in here because these types are, under the hood, pretty complex. Since
9
- * the inputs and outputs of this function are well typed, these internal as any casts do not
10
- * affect the external API of this function.
11
- */
12
- const nestedKeysInput = nestedKeys;
13
- const inputObject = originalObject;
14
- if (isRunTimeType(inputObject, 'array')) {
15
- inputObject.forEach((entry) => {
16
- if (isObject(entry)) {
17
- setValueWithNestedKeys(entry, nestedKeysInput, value);
18
- }
19
- });
20
- }
21
- else if (isLengthAtLeast(nestedKeysInput, 2)) {
22
- /** If there are more keys to traverse into. */
23
- const nextKey = nestedKeysInput[0];
24
- if (!(nextKey in inputObject)) {
25
- inputObject[nextKey] = {};
26
- }
27
- const nextParent = inputObject[nextKey];
28
- setValueWithNestedKeys(nextParent, nestedKeysInput.slice(1), value);
29
- }
30
- else if (isLengthAtLeast(nestedKeysInput, 1)) {
31
- inputObject[nestedKeysInput[0]] = value;
32
- }
33
- }
34
- export function getValueFromNestedKeys(originalObject, nestedKeys) {
35
- /**
36
- * Lots of as any casts in here because these types are, under the hood, pretty complex. Since
37
- * the inputs and outputs of this function are well typed, these internal as any casts do not
38
- * affect the external API of this function.
39
- */
40
- const nestedKeysInput = nestedKeys;
41
- const inputObject = originalObject;
42
- if (isRunTimeType(inputObject, 'array')) {
43
- return inputObject.map((entry) => getValueFromNestedKeys(entry, nestedKeys));
44
- }
45
- const keyToAccess = nestedKeysInput[0];
46
- if (!typedHasProperty(inputObject, keyToAccess)) {
47
- return undefined;
48
- }
49
- const currentValue = inputObject[keyToAccess];
50
- if (nestedKeysInput.length > 1) {
51
- return getValueFromNestedKeys(currentValue, nestedKeysInput.slice(1));
52
- }
53
- else {
54
- return currentValue;
55
- }
56
- }
@@ -1,18 +0,0 @@
1
- import { ArrayElement } from '../type';
2
- import { TsRecurse, TsRecursionStart, TsRecursionTracker, TsTooMuchRecursion } from '../type-recursion';
3
- import { PropertyValueType } from './object';
4
- import { UnionToIntersection } from './old-union-to-intersection';
5
- export type NestedSequentialKeys<ObjectGeneric extends object, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? ['Error: recursive object depth is too deep.'] : NonNullable<ObjectGeneric> extends ReadonlyArray<any> ? Extract<NonNullable<ObjectGeneric>[number], object> extends never ? [number] : NestedSequentialKeys<Extract<NonNullable<ObjectGeneric>[number], object>, TsRecurse<Depth>> : PropertyValueType<{
6
- [Prop in keyof ObjectGeneric]: NonNullable<ObjectGeneric[Prop]> extends object ? Readonly<[
7
- Prop,
8
- ...(NestedSequentialKeys<NonNullable<ObjectGeneric[Prop]>, TsRecurse<Depth>> | [])
9
- ]> : Readonly<[Prop]>;
10
- }>;
11
- export type NestedKeys<ObjectGeneric extends object, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? ['Error: recursive object depth is too deep.'] : ObjectGeneric extends ReadonlyArray<any> ? NestedKeys<ArrayElement<ObjectGeneric>, TsRecurse<Depth>> : UnionToIntersection<Extract<PropertyValueType<ObjectGeneric>, object>> extends object ? [
12
- keyof ObjectGeneric,
13
- ...(NestedKeys<UnionToIntersection<Extract<PropertyValueType<ObjectGeneric>, object>>, TsRecurse<Depth>> | [])
14
- ] : [keyof ObjectGeneric];
15
- export type NestedValue<ObjectGeneric extends object, NestedKeysGeneric extends NestedSequentialKeys<ObjectGeneric>, Depth extends TsRecursionTracker = TsRecursionStart> = ObjectGeneric extends ReadonlyArray<any> ? NestedValue<Extract<ObjectGeneric[number], object>, NestedKeysGeneric, TsRecurse<Depth>>[] : NestedKeysGeneric extends readonly [infer FirstEntry, ...infer FollowingEntries] ? FirstEntry extends keyof ObjectGeneric ? FollowingEntries extends never[] ? ObjectGeneric[FirstEntry] : ObjectGeneric[FirstEntry] extends object ? FollowingEntries extends NestedSequentialKeys<ObjectGeneric[FirstEntry]> ? NestedValue<ObjectGeneric[FirstEntry], FollowingEntries, TsRecurse<Depth>> : never : never : never : never;
16
- /** This mutates the {@link originalObject} input. */
17
- export declare function setValueWithNestedKeys<const ObjectGeneric extends object, const KeysGeneric extends NestedSequentialKeys<ObjectGeneric>>(originalObject: ObjectGeneric, nestedKeys: Readonly<KeysGeneric>, value: Readonly<NestedValue<ObjectGeneric, KeysGeneric>>): void;
18
- export declare function getValueFromNestedKeys<const ObjectGeneric extends object, const KeysGeneric extends NestedSequentialKeys<ObjectGeneric>>(originalObject: ObjectGeneric, nestedKeys: KeysGeneric): NestedValue<ObjectGeneric, KeysGeneric>;