@vinicunca/perkakas 1.7.0 → 1.7.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/dist/{bounded-partial-BzynYDVs.d.ts → bounded-partial-B15MLSAS.d.ts} +1 -2
- package/dist/{bounded-partial-BqwRN49U.d.cts → bounded-partial-BhnecV3P.d.cts} +1 -2
- package/dist/chunk-4Y6VRHEP.js +1 -0
- package/dist/chunk-ALP5JUXX.cjs +1 -0
- package/dist/{chunk-Z7D7Q6U3.js → chunk-DXA7AZUA.js} +1 -1
- package/dist/chunk-HHNHTPVO.cjs +1 -0
- package/dist/{chunk-FOUZI2Q3.cjs → chunk-QPMGUF2V.cjs} +1 -1
- package/dist/chunk-RZBBV6PK.js +1 -0
- package/dist/chunk.d.cts +1 -9
- package/dist/chunk.d.ts +1 -9
- package/dist/constant.d.cts +1 -1
- package/dist/constant.d.ts +1 -1
- package/dist/count-by.d.cts +2 -3
- package/dist/count-by.d.ts +2 -3
- package/dist/from-keys.d.cts +1 -2
- package/dist/from-keys.d.ts +1 -2
- package/dist/funnel.lodash-debounce-with-cached-value.test.cjs +1 -1
- package/dist/funnel.lodash-debounce-with-cached-value.test.js +1 -1
- package/dist/funnel.lodash-debounce.test.cjs +1 -1
- package/dist/funnel.lodash-debounce.test.js +1 -1
- package/dist/funnel.lodash-throttle-with-cached-value.test.cjs +1 -1
- package/dist/funnel.lodash-throttle-with-cached-value.test.js +1 -1
- package/dist/funnel.lodash-throttle.test.cjs +1 -1
- package/dist/funnel.lodash-throttle.test.js +1 -1
- package/dist/funnel.perkakas-debounce.test.cjs +1 -1
- package/dist/funnel.perkakas-debounce.test.js +1 -1
- package/dist/funnel.reference-batch.test.cjs +1 -1
- package/dist/funnel.reference-batch.test.js +1 -1
- package/dist/funnel.test-d.cjs +1 -1
- package/dist/funnel.test-d.js +1 -1
- package/dist/funnel.test.cjs +1 -1
- package/dist/funnel.test.js +1 -1
- package/dist/group-by-prop.d.cts +1 -2
- package/dist/group-by-prop.d.ts +1 -2
- package/dist/group-by.d.cts +2 -3
- package/dist/group-by.d.ts +2 -3
- package/dist/index-by.d.cts +2 -3
- package/dist/index-by.d.ts +2 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/map-keys.d.cts +2 -3
- package/dist/map-keys.d.ts +2 -3
- package/dist/map-values.d.cts +1 -1
- package/dist/map-values.d.ts +1 -1
- package/dist/n-tuple-5jljrt4c.d.cts +10 -0
- package/dist/n-tuple-5jljrt4c.d.ts +10 -0
- package/dist/omit-by.d.cts +2 -3
- package/dist/omit-by.d.ts +2 -3
- package/dist/path-or.d.cts +10 -0
- package/dist/path-or.d.ts +10 -0
- package/dist/pick-by.d.cts +3 -4
- package/dist/pick-by.d.ts +3 -4
- package/dist/pick.cjs +1 -1
- package/dist/pick.d.cts +3 -4
- package/dist/pick.d.ts +3 -4
- package/dist/pick.js +1 -1
- package/dist/prop.cjs +1 -1
- package/dist/prop.d.cts +118 -13
- package/dist/prop.d.ts +118 -13
- package/dist/prop.js +1 -1
- package/dist/pull-object.d.cts +2 -3
- package/dist/pull-object.d.ts +2 -3
- package/dist/sample.cjs +1 -1
- package/dist/sample.d.cts +32 -8
- package/dist/sample.d.ts +32 -8
- package/dist/sample.js +1 -1
- package/dist/string-to-path.d.cts +2 -3
- package/dist/string-to-path.d.ts +2 -3
- package/package.json +6 -6
- package/dist/chunk-2MHE6M7V.cjs +0 -1
- package/dist/chunk-NEIICTWC.js +0 -1
- package/dist/chunk-SOPOELNU.cjs +0 -1
- package/dist/chunk-XEAAXO7F.js +0 -1
- package/dist/if-D4QIikQ1.d.cts +0 -5
- package/dist/if-D4QIikQ1.d.ts +0 -5
- /package/dist/{chunk-P7RCAO7P.cjs → chunk-I5B54QDJ.cjs} +0 -0
- /package/dist/{chunk-Z23BZCCD.js → chunk-VVGDSDKI.js} +0 -0
package/dist/path-or.d.cts
CHANGED
|
@@ -47,6 +47,11 @@ type PathValue3<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>,
|
|
|
47
47
|
/**
|
|
48
48
|
* Gets the value at `path` of `object`. If the resolved value is `null` or `undefined`, the `defaultValue` is returned in its place.
|
|
49
49
|
*
|
|
50
|
+
* Prefer `prop` over this function as it provides better typing and is more
|
|
51
|
+
* flexible when building solutions. To provide a default value using `prop`
|
|
52
|
+
* use a [Nullish coalescing operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing)
|
|
53
|
+
* after the call.
|
|
54
|
+
*
|
|
50
55
|
* @param object - The target object.
|
|
51
56
|
* @param path - The path of the property to get.
|
|
52
57
|
* @param defaultValue - The default value.
|
|
@@ -63,6 +68,11 @@ declare function pathOr<T, A extends keyof Pathable<T>, B extends keyof Pathable
|
|
|
63
68
|
/**
|
|
64
69
|
* Gets the value at `path` of `object`. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
|
|
65
70
|
*
|
|
71
|
+
* Prefer `prop` over this function as it provides better typing and is more
|
|
72
|
+
* flexible when building solutions. To provide a default value using `prop`
|
|
73
|
+
* use a [Nullish coalescing operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing)
|
|
74
|
+
* after the call.
|
|
75
|
+
*
|
|
66
76
|
* @param path - The path of the property to get.
|
|
67
77
|
* @param defaultValue - The default value.
|
|
68
78
|
* @signature P.pathOr(array, defaultValue)(object)
|
package/dist/path-or.d.ts
CHANGED
|
@@ -47,6 +47,11 @@ type PathValue3<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>,
|
|
|
47
47
|
/**
|
|
48
48
|
* Gets the value at `path` of `object`. If the resolved value is `null` or `undefined`, the `defaultValue` is returned in its place.
|
|
49
49
|
*
|
|
50
|
+
* Prefer `prop` over this function as it provides better typing and is more
|
|
51
|
+
* flexible when building solutions. To provide a default value using `prop`
|
|
52
|
+
* use a [Nullish coalescing operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing)
|
|
53
|
+
* after the call.
|
|
54
|
+
*
|
|
50
55
|
* @param object - The target object.
|
|
51
56
|
* @param path - The path of the property to get.
|
|
52
57
|
* @param defaultValue - The default value.
|
|
@@ -63,6 +68,11 @@ declare function pathOr<T, A extends keyof Pathable<T>, B extends keyof Pathable
|
|
|
63
68
|
/**
|
|
64
69
|
* Gets the value at `path` of `object`. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
|
|
65
70
|
*
|
|
71
|
+
* Prefer `prop` over this function as it provides better typing and is more
|
|
72
|
+
* flexible when building solutions. To provide a default value using `prop`
|
|
73
|
+
* use a [Nullish coalescing operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing)
|
|
74
|
+
* after the call.
|
|
75
|
+
*
|
|
66
76
|
* @param path - The path of the property to get.
|
|
67
77
|
* @param defaultValue - The default value.
|
|
68
78
|
* @signature P.pathOr(array, defaultValue)(object)
|
package/dist/pick-by.d.cts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Simplify, IfNever } from 'type-fest';
|
|
2
2
|
import { E as EnumerableStringKeyOf } from './enumerable-string-key-of-D8w_3Yg8.cjs';
|
|
3
3
|
import { E as EnumerableStringKeyedValueOf } from './enumerable-string-keyed-value-of-BU9R_cEk.cjs';
|
|
4
|
-
import { I as If } from './if-D4QIikQ1.cjs';
|
|
5
4
|
import { I as IsBoundedRecord } from './is-bounded-record-C9WAwfA8.cjs';
|
|
6
5
|
import { T as ToString } from './to-string-DO8zw6jS.cjs';
|
|
7
6
|
|
|
8
|
-
type EnumeratedPartial<T> = T extends unknown ? Simplify<
|
|
7
|
+
type EnumeratedPartial<T> = T extends unknown ? Simplify<IsBoundedRecord<T> extends true ? {
|
|
9
8
|
-readonly [P in keyof T as ToString<P>]?: Required<T>[P];
|
|
10
|
-
}
|
|
11
|
-
type EnumeratedPartialNarrowed<T, S> = T extends unknown ? Simplify<
|
|
9
|
+
} : Record<EnumerableStringKeyOf<T>, EnumerableStringKeyedValueOf<T>>> : never;
|
|
10
|
+
type EnumeratedPartialNarrowed<T, S> = T extends unknown ? Simplify<IsBoundedRecord<T> extends true ? ExactProps<T, S> & PartialProps<T, S> : Record<EnumerableStringKeyOf<T>, Extract<EnumerableStringKeyedValueOf<T>, S>>> : never;
|
|
12
11
|
type ExactProps<T, S> = {
|
|
13
12
|
-readonly [P in keyof T as ToString<IsExactProp<T, P, S> extends true ? P : never>]: Extract<Required<T>[P], S>;
|
|
14
13
|
};
|
package/dist/pick-by.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Simplify, IfNever } from 'type-fest';
|
|
2
2
|
import { E as EnumerableStringKeyOf } from './enumerable-string-key-of-C4gsorXe.js';
|
|
3
3
|
import { E as EnumerableStringKeyedValueOf } from './enumerable-string-keyed-value-of-BU9R_cEk.js';
|
|
4
|
-
import { I as If } from './if-D4QIikQ1.js';
|
|
5
4
|
import { I as IsBoundedRecord } from './is-bounded-record-C9WAwfA8.js';
|
|
6
5
|
import { T as ToString } from './to-string-DO8zw6jS.js';
|
|
7
6
|
|
|
8
|
-
type EnumeratedPartial<T> = T extends unknown ? Simplify<
|
|
7
|
+
type EnumeratedPartial<T> = T extends unknown ? Simplify<IsBoundedRecord<T> extends true ? {
|
|
9
8
|
-readonly [P in keyof T as ToString<P>]?: Required<T>[P];
|
|
10
|
-
}
|
|
11
|
-
type EnumeratedPartialNarrowed<T, S> = T extends unknown ? Simplify<
|
|
9
|
+
} : Record<EnumerableStringKeyOf<T>, EnumerableStringKeyedValueOf<T>>> : never;
|
|
10
|
+
type EnumeratedPartialNarrowed<T, S> = T extends unknown ? Simplify<IsBoundedRecord<T> extends true ? ExactProps<T, S> & PartialProps<T, S> : Record<EnumerableStringKeyOf<T>, Extract<EnumerableStringKeyedValueOf<T>, S>>> : never;
|
|
12
11
|
type ExactProps<T, S> = {
|
|
13
12
|
-readonly [P in keyof T as ToString<IsExactProp<T, P, S> extends true ? P : never>]: Extract<Required<T>[P], S>;
|
|
14
13
|
};
|
package/dist/pick.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkQPMGUF2Vcjs = require('./chunk-QPMGUF2V.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');require('./chunk-MBGSSEZN.cjs');exports.pick = _chunkQPMGUF2Vcjs.a;
|
package/dist/pick.d.cts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { KeysOfUnion, IsNever, EmptyObject, Writable } from 'type-fest';
|
|
2
|
-
import { I as If } from './if-D4QIikQ1.cjs';
|
|
3
2
|
import { I as IsBoundedRecord, a as IsBounded } from './is-bounded-record-C9WAwfA8.cjs';
|
|
4
3
|
import { I as IsUnion } from './is-union-Bx34mF34.cjs';
|
|
5
4
|
import { T as TupleParts } from './tuple-parts-v6av7LMU.cjs';
|
|
6
5
|
import './iterable-container-BTpDVdNc.cjs';
|
|
7
6
|
import './perkakas-type-error-8wPb8T2y.cjs';
|
|
8
7
|
|
|
9
|
-
type PickFromArray<T, Keys extends ReadonlyArray<KeysOfUnion<T>>> = T extends unknown ? Keys extends unknown ?
|
|
8
|
+
type PickFromArray<T, Keys extends ReadonlyArray<KeysOfUnion<T>>> = T extends unknown ? Keys extends unknown ? IsNever<Extract<Keys[number], keyof T>> extends true ? EmptyObject : Writable<IsBoundedRecord<T> extends true ? PickBoundedFromArray<T, Keys> : PickUnbounded<T, Extract<Keys[number], keyof T>>> : never : never;
|
|
10
9
|
/**
|
|
11
10
|
* Bounded records have bounded keys and result in a bounded output. The only
|
|
12
11
|
* question left is whether to add the prop as-is, or make it optional. This
|
|
@@ -27,7 +26,7 @@ type PickBoundedFromArray<T, Keys extends ReadonlyArray<KeysOfUnion<T>>> = Pick<
|
|
|
27
26
|
type ItemsByUnion<T, Singular = never, Union = never> = T extends readonly [
|
|
28
27
|
infer Head,
|
|
29
28
|
...infer Rest
|
|
30
|
-
] ?
|
|
29
|
+
] ? IsUnion<Head> extends true ? ItemsByUnion<Rest, Singular, Union | Head> : ItemsByUnion<Rest, Singular | Head, Union> : {
|
|
31
30
|
singular: Singular;
|
|
32
31
|
union: Union;
|
|
33
32
|
};
|
|
@@ -42,7 +41,7 @@ type ItemsByUnion<T, Singular = never, Union = never> = T extends readonly [
|
|
|
42
41
|
*
|
|
43
42
|
* See: https://www.typescriptlang.org/play/?#code/PTAEE0HsFcHIBNQFMAeAHJBjALqAGqNpKAEZKigAGA3qABZIA2jkA-AFygBEA7pAE6N4XUAF9KAGlLRcAQ0ayAzgChsATwz5QAXlAAFAJaYA1gB4ASlgHxTi7PwMA7AOZTeAoVwB8bhs0jeANzKIBSgAHqsykA.
|
|
44
43
|
*/
|
|
45
|
-
type PickUnbounded<T, Keys extends keyof T> =
|
|
44
|
+
type PickUnbounded<T, Keys extends keyof T> = IsBounded<Keys> extends true ? Partial<Pick<T, Keys>> : Pick<T, Keys>;
|
|
46
45
|
/**
|
|
47
46
|
* Creates an object composed of the picked `data` properties.
|
|
48
47
|
*
|
package/dist/pick.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { KeysOfUnion, IsNever, EmptyObject, Writable } from 'type-fest';
|
|
2
|
-
import { I as If } from './if-D4QIikQ1.js';
|
|
3
2
|
import { I as IsBoundedRecord, a as IsBounded } from './is-bounded-record-C9WAwfA8.js';
|
|
4
3
|
import { I as IsUnion } from './is-union-Bx34mF34.js';
|
|
5
4
|
import { T as TupleParts } from './tuple-parts-BTivqbtT.js';
|
|
6
5
|
import './iterable-container-BTpDVdNc.js';
|
|
7
6
|
import './perkakas-type-error-8wPb8T2y.js';
|
|
8
7
|
|
|
9
|
-
type PickFromArray<T, Keys extends ReadonlyArray<KeysOfUnion<T>>> = T extends unknown ? Keys extends unknown ?
|
|
8
|
+
type PickFromArray<T, Keys extends ReadonlyArray<KeysOfUnion<T>>> = T extends unknown ? Keys extends unknown ? IsNever<Extract<Keys[number], keyof T>> extends true ? EmptyObject : Writable<IsBoundedRecord<T> extends true ? PickBoundedFromArray<T, Keys> : PickUnbounded<T, Extract<Keys[number], keyof T>>> : never : never;
|
|
10
9
|
/**
|
|
11
10
|
* Bounded records have bounded keys and result in a bounded output. The only
|
|
12
11
|
* question left is whether to add the prop as-is, or make it optional. This
|
|
@@ -27,7 +26,7 @@ type PickBoundedFromArray<T, Keys extends ReadonlyArray<KeysOfUnion<T>>> = Pick<
|
|
|
27
26
|
type ItemsByUnion<T, Singular = never, Union = never> = T extends readonly [
|
|
28
27
|
infer Head,
|
|
29
28
|
...infer Rest
|
|
30
|
-
] ?
|
|
29
|
+
] ? IsUnion<Head> extends true ? ItemsByUnion<Rest, Singular, Union | Head> : ItemsByUnion<Rest, Singular | Head, Union> : {
|
|
31
30
|
singular: Singular;
|
|
32
31
|
union: Union;
|
|
33
32
|
};
|
|
@@ -42,7 +41,7 @@ type ItemsByUnion<T, Singular = never, Union = never> = T extends readonly [
|
|
|
42
41
|
*
|
|
43
42
|
* See: https://www.typescriptlang.org/play/?#code/PTAEE0HsFcHIBNQFMAeAHJBjALqAGqNpKAEZKigAGA3qABZIA2jkA-AFygBEA7pAE6N4XUAF9KAGlLRcAQ0ayAzgChsATwz5QAXlAAFAJaYA1gB4ASlgHxTi7PwMA7AOZTeAoVwB8bhs0jeANzKIBSgAHqsykA.
|
|
44
43
|
*/
|
|
45
|
-
type PickUnbounded<T, Keys extends keyof T> =
|
|
44
|
+
type PickUnbounded<T, Keys extends keyof T> = IsBounded<Keys> extends true ? Partial<Pick<T, Keys>> : Pick<T, Keys>;
|
|
46
45
|
/**
|
|
47
46
|
* Creates an object composed of the picked `data` properties.
|
|
48
47
|
*
|
package/dist/pick.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-DXA7AZUA.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";import"./chunk-EK7ODJWE.js";export{a as pick};
|
package/dist/prop.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkHHNHTPVOcjs = require('./chunk-HHNHTPVO.cjs');require('./chunk-MBGSSEZN.cjs');exports.prop = _chunkHHNHTPVOcjs.a;
|
package/dist/prop.d.cts
CHANGED
|
@@ -1,29 +1,134 @@
|
|
|
1
|
+
import { IsNumericLiteral, ArrayIndices, KeysOfUnion } from 'type-fest';
|
|
2
|
+
import { C as ClampedIntegerSubtract } from './clamped-integer-subtract-DZ7rsJE4.cjs';
|
|
3
|
+
import { I as IntRangeInclusive } from './int-range-inclusive-Cn-qsrAN.cjs';
|
|
4
|
+
import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
|
|
5
|
+
import { T as TupleParts } from './tuple-parts-v6av7LMU.cjs';
|
|
6
|
+
import './perkakas-type-error-8wPb8T2y.cjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The type for the I'th element in the tuple T. This type corrects some of the
|
|
10
|
+
* issues with TypeScript's built-in tuple accessor inference `T[I]` for arrays
|
|
11
|
+
* and tuples with fixed suffixes, and for primitive indices where we don't know
|
|
12
|
+
* if the index is out of bounds.
|
|
13
|
+
*/
|
|
14
|
+
type ArrayAt<T extends IterableContainer, I extends keyof T> = IsNumericLiteral<I> extends true ? I extends unknown ? [
|
|
15
|
+
...TupleParts<T>['required'],
|
|
16
|
+
...TupleParts<T>['optional']
|
|
17
|
+
] extends infer Prefix extends ReadonlyArray<unknown> ? HasIndex<Prefix, I> extends true ? T[I] : TupleParts<T>['item'] | (ClampedIntegerSubtract<I, Prefix['length']> extends infer SuffixIndex extends number ? HasIndex<TupleParts<T>['suffix'], SuffixIndex> extends true ? TupleParts<T>['suffix'][IntRangeInclusive<0, SuffixIndex>] : TupleParts<T>['suffix'][number] | undefined : never) : never : never : T[number] | undefined;
|
|
18
|
+
type HasIndex<T extends ReadonlyArray<unknown>, I> = I extends ArrayIndices<T> ? true : false;
|
|
19
|
+
|
|
20
|
+
type NoInfer<T> = T extends infer U ? U : never;
|
|
21
|
+
|
|
22
|
+
type KeysDeep<T, Path extends ReadonlyArray<unknown>> = KeysOfUnion<PropDeep<T, Path>>;
|
|
23
|
+
type PropDeep<T, Path extends ReadonlyArray<unknown>> = Path extends readonly [
|
|
24
|
+
infer Key,
|
|
25
|
+
...infer Rest
|
|
26
|
+
] ? PropDeep<Prop<T, Key>, Rest> : T;
|
|
27
|
+
type Prop<T, Key> = T extends unknown ? Key extends keyof T ? T extends ReadonlyArray<unknown> ? ArrayAt<T, Key> : T[Key] : undefined : never;
|
|
28
|
+
type NonPropertyKey = object | null | undefined;
|
|
1
29
|
/**
|
|
2
|
-
* Gets the value of the given property.
|
|
30
|
+
* Gets the value of the given property from an object. Nested properties can
|
|
31
|
+
* be accessed by providing a variadic array of keys that define the path from
|
|
32
|
+
* the root to the desired property. Arrays can be accessed by using numeric
|
|
33
|
+
* keys. Unions and optional properties are handled gracefully by returning
|
|
34
|
+
* `undefined` early for any non-existing property on the path. Paths are
|
|
35
|
+
* validated against the object type to provide stronger type safety, better
|
|
36
|
+
* compile-time errors, and to enable autocompletion in IDEs.
|
|
3
37
|
*
|
|
4
|
-
* @param data - The object
|
|
5
|
-
* @param key - The key
|
|
38
|
+
* @param data - The object or array to access.
|
|
39
|
+
* @param key - The key(s) for the property to extract.
|
|
6
40
|
* @signature
|
|
7
|
-
* P.prop(data,
|
|
41
|
+
* P.prop(data, ...keys);
|
|
8
42
|
* @example
|
|
9
|
-
* P.prop({ foo:
|
|
43
|
+
* P.prop({ foo: { bar: 'baz' } }, 'foo'); //=> { bar: 'baz' }
|
|
44
|
+
* P.prop({ foo: { bar: 'baz' } }, 'foo', 'bar'); //=> 'baz'
|
|
45
|
+
* P.prop(["cat", "dog"], 1); //=> 'dog'
|
|
10
46
|
* @dataFirst
|
|
11
47
|
* @category Object
|
|
12
48
|
*/
|
|
13
|
-
declare function prop<T,
|
|
49
|
+
declare function prop<T extends NonPropertyKey, Key extends KeysDeep<T, []>>(data: T, key: Key): NoInfer<Prop<T, Key>>;
|
|
50
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>>(data: T, key0: Key0, key1: Key1): NoInfer<PropDeep<T, [Key0, Key1]>>;
|
|
51
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>>(data: T, key0: Key0, key1: Key1, key2: Key2): NoInfer<PropDeep<T, [Key0, Key1, Key2]>>;
|
|
52
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3]>>;
|
|
53
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4]>>;
|
|
54
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>;
|
|
55
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>;
|
|
56
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>;
|
|
57
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>, Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7, key8: Key8): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]>>;
|
|
58
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>, Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>, Key9 extends KeysDeep<T, [
|
|
59
|
+
Key0,
|
|
60
|
+
Key1,
|
|
61
|
+
Key2,
|
|
62
|
+
Key3,
|
|
63
|
+
Key4,
|
|
64
|
+
Key5,
|
|
65
|
+
Key6,
|
|
66
|
+
Key7,
|
|
67
|
+
Key8
|
|
68
|
+
]>, AdditionalKeys extends ReadonlyArray<PropertyKey> = []>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7, key8: Key8, key9: Key9, ...additionalKeys: AdditionalKeys): NoInfer<PropDeep<T, [
|
|
69
|
+
Key0,
|
|
70
|
+
Key1,
|
|
71
|
+
Key2,
|
|
72
|
+
Key3,
|
|
73
|
+
Key4,
|
|
74
|
+
Key5,
|
|
75
|
+
Key6,
|
|
76
|
+
Key7,
|
|
77
|
+
Key8,
|
|
78
|
+
Key9,
|
|
79
|
+
...AdditionalKeys
|
|
80
|
+
]>>;
|
|
14
81
|
/**
|
|
15
|
-
* Gets the value of the given property.
|
|
82
|
+
* Gets the value of the given property from an object. Nested properties can
|
|
83
|
+
* be accessed by providing a variadic array of keys that define the path from
|
|
84
|
+
* the root to the desired property. Arrays can be accessed by using numeric
|
|
85
|
+
* keys. Unions and optional properties are handled gracefully by returning
|
|
86
|
+
* `undefined` early for any non-existing property on the path. Paths are
|
|
87
|
+
* validated against the object type to provide stronger type safety, better
|
|
88
|
+
* compile-time errors, and to enable autocompletion in IDEs.
|
|
16
89
|
*
|
|
17
|
-
* @param key - The key
|
|
90
|
+
* @param key - The key(s) for the property to extract.
|
|
18
91
|
* @signature
|
|
19
|
-
* P.prop(
|
|
92
|
+
* P.prop(...keys)(data);
|
|
20
93
|
* @example
|
|
21
|
-
*
|
|
94
|
+
* P.pipe({ foo: { bar: 'baz' } }, P.prop('foo')); //=> { bar: 'baz' }
|
|
95
|
+
* P.pipe({ foo: { bar: 'baz' } }, P.prop('foo', 'bar')); //=> 'baz'
|
|
96
|
+
* P.pipe(["cat", "dog"], P.prop(1)); //=> 'dog'
|
|
22
97
|
* @dataLast
|
|
23
98
|
* @category Object
|
|
24
99
|
*/
|
|
25
|
-
declare function prop<T,
|
|
100
|
+
declare function prop<T extends NonPropertyKey, Key extends KeysOfUnion<T>>(key: Key): (data: T) => NoInfer<Prop<T, Key>>;
|
|
101
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>>(key0: Key0, key1: Key1): (data: T) => NoInfer<PropDeep<T, [Key0, Key1]>>;
|
|
102
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>>(key0: Key0, key1: Key1, key2: Key2): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2]>>;
|
|
103
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3]>>;
|
|
104
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4]>>;
|
|
105
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>;
|
|
106
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>;
|
|
107
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>;
|
|
108
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>, Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7, key8: Key8): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]>>;
|
|
109
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>, Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>, Key9 extends KeysDeep<T, [
|
|
110
|
+
Key0,
|
|
111
|
+
Key1,
|
|
112
|
+
Key2,
|
|
113
|
+
Key3,
|
|
114
|
+
Key4,
|
|
115
|
+
Key5,
|
|
116
|
+
Key6,
|
|
117
|
+
Key7,
|
|
118
|
+
Key8
|
|
119
|
+
]>, AdditionalKeys extends ReadonlyArray<PropertyKey> = []>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7, key8: Key8, key9: Key9, ...additionalKeys: AdditionalKeys): (data: T) => NoInfer<PropDeep<T, [
|
|
120
|
+
Key0,
|
|
121
|
+
Key1,
|
|
122
|
+
Key2,
|
|
123
|
+
Key3,
|
|
124
|
+
Key4,
|
|
125
|
+
Key5,
|
|
126
|
+
Key6,
|
|
127
|
+
Key7,
|
|
128
|
+
Key8,
|
|
129
|
+
Key9,
|
|
130
|
+
...AdditionalKeys
|
|
131
|
+
]>>;
|
|
26
132
|
declare function prop<K extends PropertyKey>(key: K): <T extends Partial<Record<K, unknown>>>(data: T) => T[K];
|
|
27
|
-
declare function propImplementation<T, K extends keyof T>(data: T, key: K): T[K];
|
|
28
133
|
|
|
29
|
-
export { prop
|
|
134
|
+
export { prop };
|
package/dist/prop.d.ts
CHANGED
|
@@ -1,29 +1,134 @@
|
|
|
1
|
+
import { IsNumericLiteral, ArrayIndices, KeysOfUnion } from 'type-fest';
|
|
2
|
+
import { C as ClampedIntegerSubtract } from './clamped-integer-subtract-DZ7rsJE4.js';
|
|
3
|
+
import { I as IntRangeInclusive } from './int-range-inclusive-Cn-qsrAN.js';
|
|
4
|
+
import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
|
|
5
|
+
import { T as TupleParts } from './tuple-parts-BTivqbtT.js';
|
|
6
|
+
import './perkakas-type-error-8wPb8T2y.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The type for the I'th element in the tuple T. This type corrects some of the
|
|
10
|
+
* issues with TypeScript's built-in tuple accessor inference `T[I]` for arrays
|
|
11
|
+
* and tuples with fixed suffixes, and for primitive indices where we don't know
|
|
12
|
+
* if the index is out of bounds.
|
|
13
|
+
*/
|
|
14
|
+
type ArrayAt<T extends IterableContainer, I extends keyof T> = IsNumericLiteral<I> extends true ? I extends unknown ? [
|
|
15
|
+
...TupleParts<T>['required'],
|
|
16
|
+
...TupleParts<T>['optional']
|
|
17
|
+
] extends infer Prefix extends ReadonlyArray<unknown> ? HasIndex<Prefix, I> extends true ? T[I] : TupleParts<T>['item'] | (ClampedIntegerSubtract<I, Prefix['length']> extends infer SuffixIndex extends number ? HasIndex<TupleParts<T>['suffix'], SuffixIndex> extends true ? TupleParts<T>['suffix'][IntRangeInclusive<0, SuffixIndex>] : TupleParts<T>['suffix'][number] | undefined : never) : never : never : T[number] | undefined;
|
|
18
|
+
type HasIndex<T extends ReadonlyArray<unknown>, I> = I extends ArrayIndices<T> ? true : false;
|
|
19
|
+
|
|
20
|
+
type NoInfer<T> = T extends infer U ? U : never;
|
|
21
|
+
|
|
22
|
+
type KeysDeep<T, Path extends ReadonlyArray<unknown>> = KeysOfUnion<PropDeep<T, Path>>;
|
|
23
|
+
type PropDeep<T, Path extends ReadonlyArray<unknown>> = Path extends readonly [
|
|
24
|
+
infer Key,
|
|
25
|
+
...infer Rest
|
|
26
|
+
] ? PropDeep<Prop<T, Key>, Rest> : T;
|
|
27
|
+
type Prop<T, Key> = T extends unknown ? Key extends keyof T ? T extends ReadonlyArray<unknown> ? ArrayAt<T, Key> : T[Key] : undefined : never;
|
|
28
|
+
type NonPropertyKey = object | null | undefined;
|
|
1
29
|
/**
|
|
2
|
-
* Gets the value of the given property.
|
|
30
|
+
* Gets the value of the given property from an object. Nested properties can
|
|
31
|
+
* be accessed by providing a variadic array of keys that define the path from
|
|
32
|
+
* the root to the desired property. Arrays can be accessed by using numeric
|
|
33
|
+
* keys. Unions and optional properties are handled gracefully by returning
|
|
34
|
+
* `undefined` early for any non-existing property on the path. Paths are
|
|
35
|
+
* validated against the object type to provide stronger type safety, better
|
|
36
|
+
* compile-time errors, and to enable autocompletion in IDEs.
|
|
3
37
|
*
|
|
4
|
-
* @param data - The object
|
|
5
|
-
* @param key - The key
|
|
38
|
+
* @param data - The object or array to access.
|
|
39
|
+
* @param key - The key(s) for the property to extract.
|
|
6
40
|
* @signature
|
|
7
|
-
* P.prop(data,
|
|
41
|
+
* P.prop(data, ...keys);
|
|
8
42
|
* @example
|
|
9
|
-
* P.prop({ foo:
|
|
43
|
+
* P.prop({ foo: { bar: 'baz' } }, 'foo'); //=> { bar: 'baz' }
|
|
44
|
+
* P.prop({ foo: { bar: 'baz' } }, 'foo', 'bar'); //=> 'baz'
|
|
45
|
+
* P.prop(["cat", "dog"], 1); //=> 'dog'
|
|
10
46
|
* @dataFirst
|
|
11
47
|
* @category Object
|
|
12
48
|
*/
|
|
13
|
-
declare function prop<T,
|
|
49
|
+
declare function prop<T extends NonPropertyKey, Key extends KeysDeep<T, []>>(data: T, key: Key): NoInfer<Prop<T, Key>>;
|
|
50
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>>(data: T, key0: Key0, key1: Key1): NoInfer<PropDeep<T, [Key0, Key1]>>;
|
|
51
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>>(data: T, key0: Key0, key1: Key1, key2: Key2): NoInfer<PropDeep<T, [Key0, Key1, Key2]>>;
|
|
52
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3]>>;
|
|
53
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4]>>;
|
|
54
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>;
|
|
55
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>;
|
|
56
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>;
|
|
57
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>, Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7, key8: Key8): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]>>;
|
|
58
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>, Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>, Key9 extends KeysDeep<T, [
|
|
59
|
+
Key0,
|
|
60
|
+
Key1,
|
|
61
|
+
Key2,
|
|
62
|
+
Key3,
|
|
63
|
+
Key4,
|
|
64
|
+
Key5,
|
|
65
|
+
Key6,
|
|
66
|
+
Key7,
|
|
67
|
+
Key8
|
|
68
|
+
]>, AdditionalKeys extends ReadonlyArray<PropertyKey> = []>(data: T, key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7, key8: Key8, key9: Key9, ...additionalKeys: AdditionalKeys): NoInfer<PropDeep<T, [
|
|
69
|
+
Key0,
|
|
70
|
+
Key1,
|
|
71
|
+
Key2,
|
|
72
|
+
Key3,
|
|
73
|
+
Key4,
|
|
74
|
+
Key5,
|
|
75
|
+
Key6,
|
|
76
|
+
Key7,
|
|
77
|
+
Key8,
|
|
78
|
+
Key9,
|
|
79
|
+
...AdditionalKeys
|
|
80
|
+
]>>;
|
|
14
81
|
/**
|
|
15
|
-
* Gets the value of the given property.
|
|
82
|
+
* Gets the value of the given property from an object. Nested properties can
|
|
83
|
+
* be accessed by providing a variadic array of keys that define the path from
|
|
84
|
+
* the root to the desired property. Arrays can be accessed by using numeric
|
|
85
|
+
* keys. Unions and optional properties are handled gracefully by returning
|
|
86
|
+
* `undefined` early for any non-existing property on the path. Paths are
|
|
87
|
+
* validated against the object type to provide stronger type safety, better
|
|
88
|
+
* compile-time errors, and to enable autocompletion in IDEs.
|
|
16
89
|
*
|
|
17
|
-
* @param key - The key
|
|
90
|
+
* @param key - The key(s) for the property to extract.
|
|
18
91
|
* @signature
|
|
19
|
-
* P.prop(
|
|
92
|
+
* P.prop(...keys)(data);
|
|
20
93
|
* @example
|
|
21
|
-
*
|
|
94
|
+
* P.pipe({ foo: { bar: 'baz' } }, P.prop('foo')); //=> { bar: 'baz' }
|
|
95
|
+
* P.pipe({ foo: { bar: 'baz' } }, P.prop('foo', 'bar')); //=> 'baz'
|
|
96
|
+
* P.pipe(["cat", "dog"], P.prop(1)); //=> 'dog'
|
|
22
97
|
* @dataLast
|
|
23
98
|
* @category Object
|
|
24
99
|
*/
|
|
25
|
-
declare function prop<T,
|
|
100
|
+
declare function prop<T extends NonPropertyKey, Key extends KeysOfUnion<T>>(key: Key): (data: T) => NoInfer<Prop<T, Key>>;
|
|
101
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>>(key0: Key0, key1: Key1): (data: T) => NoInfer<PropDeep<T, [Key0, Key1]>>;
|
|
102
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>>(key0: Key0, key1: Key1, key2: Key2): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2]>>;
|
|
103
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3]>>;
|
|
104
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4]>>;
|
|
105
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>;
|
|
106
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>;
|
|
107
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>;
|
|
108
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>, Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7, key8: Key8): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]>>;
|
|
109
|
+
declare function prop<T extends NonPropertyKey, Key0 extends KeysDeep<T, []>, Key1 extends KeysDeep<T, [Key0]>, Key2 extends KeysDeep<T, [Key0, Key1]>, Key3 extends KeysDeep<T, [Key0, Key1, Key2]>, Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>, Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>, Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>, Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>, Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>, Key9 extends KeysDeep<T, [
|
|
110
|
+
Key0,
|
|
111
|
+
Key1,
|
|
112
|
+
Key2,
|
|
113
|
+
Key3,
|
|
114
|
+
Key4,
|
|
115
|
+
Key5,
|
|
116
|
+
Key6,
|
|
117
|
+
Key7,
|
|
118
|
+
Key8
|
|
119
|
+
]>, AdditionalKeys extends ReadonlyArray<PropertyKey> = []>(key0: Key0, key1: Key1, key2: Key2, key3: Key3, key4: Key4, key5: Key5, key6: Key6, key7: Key7, key8: Key8, key9: Key9, ...additionalKeys: AdditionalKeys): (data: T) => NoInfer<PropDeep<T, [
|
|
120
|
+
Key0,
|
|
121
|
+
Key1,
|
|
122
|
+
Key2,
|
|
123
|
+
Key3,
|
|
124
|
+
Key4,
|
|
125
|
+
Key5,
|
|
126
|
+
Key6,
|
|
127
|
+
Key7,
|
|
128
|
+
Key8,
|
|
129
|
+
Key9,
|
|
130
|
+
...AdditionalKeys
|
|
131
|
+
]>>;
|
|
26
132
|
declare function prop<K extends PropertyKey>(key: K): <T extends Partial<Record<K, unknown>>>(data: T) => T[K];
|
|
27
|
-
declare function propImplementation<T, K extends keyof T>(data: T, key: K): T[K];
|
|
28
133
|
|
|
29
|
-
export { prop
|
|
134
|
+
export { prop };
|
package/dist/prop.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a
|
|
1
|
+
import{a}from"./chunk-RZBBV6PK.js";import"./chunk-EK7ODJWE.js";export{a as prop};
|
package/dist/pull-object.d.cts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { B as BoundedPartial } from './bounded-partial-
|
|
1
|
+
import { B as BoundedPartial } from './bounded-partial-BhnecV3P.cjs';
|
|
2
2
|
import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
|
|
3
|
-
import './if-D4QIikQ1.cjs';
|
|
4
|
-
import 'type-fest';
|
|
5
3
|
import './is-bounded-record-C9WAwfA8.cjs';
|
|
4
|
+
import 'type-fest';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Creates an object that maps the result of `valueExtractor` with a key
|
package/dist/pull-object.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { B as BoundedPartial } from './bounded-partial-
|
|
1
|
+
import { B as BoundedPartial } from './bounded-partial-B15MLSAS.js';
|
|
2
2
|
import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
|
|
3
|
-
import './if-D4QIikQ1.js';
|
|
4
|
-
import 'type-fest';
|
|
5
3
|
import './is-bounded-record-C9WAwfA8.js';
|
|
4
|
+
import 'type-fest';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Creates an object that maps the result of `valueExtractor` with a key
|
package/dist/sample.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkALP5JUXXcjs = require('./chunk-ALP5JUXX.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');require('./chunk-MBGSSEZN.cjs');exports.sample = _chunkALP5JUXXcjs.a;
|
package/dist/sample.d.cts
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
|
+
import { Or, IsEqual, IsNever, NonNegativeInteger, FixedLengthArray, Writable } from 'type-fest';
|
|
2
|
+
import { C as CoercedArray } from './coerced-array-DRz3tqda.cjs';
|
|
1
3
|
import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
|
|
4
|
+
import { N as NTuple } from './n-tuple-5jljrt4c.cjs';
|
|
5
|
+
import { P as PartialArray } from './partial-array-Vnf1fBtl.cjs';
|
|
6
|
+
import { T as TupleParts } from './tuple-parts-v6av7LMU.cjs';
|
|
7
|
+
import './perkakas-type-error-8wPb8T2y.cjs';
|
|
2
8
|
|
|
3
|
-
type Sampled<T extends IterableContainer, N extends number> =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
type Sampled<T extends IterableContainer, N extends number> = Or<IsEqual<N, 0>, IsEqual<T['length'], 0>> extends true ? [] : IsNever<NonNegativeInteger<N>> extends true ? SampledPrimitive<T> : IsLongerThan<T, N> extends true ? SampledLiteral<T, N> : Writable<T>;
|
|
10
|
+
/**
|
|
11
|
+
* When N is not a non-negative integer **literal** we can't use it in our
|
|
12
|
+
* reconstructing logic so we fallback to a simpler definition of the output of
|
|
13
|
+
* sample, which is any sub-tuple shape of T, of **any length**.
|
|
14
|
+
*/
|
|
15
|
+
type SampledPrimitive<T extends IterableContainer> = [
|
|
16
|
+
...FixedSubTuples<TupleParts<T>['required']>,
|
|
17
|
+
...PartialArray<FixedSubTuples<TupleParts<T>['optional']>>,
|
|
18
|
+
...CoercedArray<TupleParts<T>['item']>,
|
|
19
|
+
...FixedSubTuples<TupleParts<T>['suffix']>
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Knowing N is a non-negative literal integer we can construct all sub-tuples
|
|
23
|
+
* of T that are exactly N elements long.
|
|
24
|
+
*/
|
|
25
|
+
type SampledLiteral<T extends IterableContainer, N extends number> = Extract<FixedSubTuples<[
|
|
26
|
+
...TupleParts<T>['required'],
|
|
27
|
+
...(IsNever<TupleParts<T>['item']> extends true ? [] : NTuple<TupleParts<T>['item'], N>),
|
|
28
|
+
...TupleParts<T>['suffix']
|
|
29
|
+
]>, FixedLengthArray<unknown, N>> | SubSampled<TupleParts<T>['required'], TupleParts<T>['item'], TupleParts<T>['suffix'], N>;
|
|
30
|
+
type SubSampled<Prefix extends ReadonlyArray<unknown>, Item, Suffix extends ReadonlyArray<unknown>, N extends number> = IsLongerThan<[...Prefix, ...Suffix], N> extends true ? never : [...Prefix, ...Suffix]['length'] extends N ? never : [...Prefix, ...Suffix] | SubSampled<[...Prefix, Item], Item, Suffix, N>;
|
|
31
|
+
type IsLongerThan<T extends ReadonlyArray<unknown>, N extends number> = IsEqual<T[N], undefined> extends true ? false : true;
|
|
32
|
+
type FixedSubTuples<T> = T extends readonly [infer Head, ...infer Rest] ? FixedSubTuples<Rest> | [Head, ...FixedSubTuples<Rest>] : [];
|
|
9
33
|
/**
|
|
10
34
|
* Returns a random subset of size `sampleSize` from `array`.
|
|
11
35
|
*
|
|
@@ -27,7 +51,7 @@ type SampledLiteral<T extends IterableContainer, N extends number, Iteration ext
|
|
|
27
51
|
* @dataFirst
|
|
28
52
|
* @category Array
|
|
29
53
|
*/
|
|
30
|
-
declare function sample<T extends IterableContainer, N extends number = number>(data: T, sampleSize: N): Sampled<T, N>;
|
|
54
|
+
declare function sample<const T extends IterableContainer, N extends number = number>(data: T, sampleSize: N): Sampled<T, N>;
|
|
31
55
|
/**
|
|
32
56
|
* Returns a random subset of size `sampleSize` from `array`.
|
|
33
57
|
*
|
|
@@ -48,6 +72,6 @@ declare function sample<T extends IterableContainer, N extends number = number>(
|
|
|
48
72
|
* @dataLast
|
|
49
73
|
* @category Array
|
|
50
74
|
*/
|
|
51
|
-
declare function sample<T extends IterableContainer, N extends number = number>(sampleSize: N): (data: T) => Sampled<T, N>;
|
|
75
|
+
declare function sample<const T extends IterableContainer, N extends number = number>(sampleSize: N): (data: T) => Sampled<T, N>;
|
|
52
76
|
|
|
53
77
|
export { sample };
|