@vinicunca/perkakas 1.4.0 → 1.6.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/dist/array-required-prefix-BW08fIbb.d.cts +35 -0
- package/dist/array-required-prefix-a3sgCkd2.d.ts +35 -0
- package/dist/bounded-partial-CJjczH6j.d.ts +14 -0
- package/dist/bounded-partial-wqR8ceNQ.d.cts +14 -0
- package/dist/{chunk-AJQEGHF5.cjs → chunk-22AQJBPW.cjs} +1 -1
- package/dist/chunk-2HQM73IT.cjs +1 -0
- package/dist/chunk-2XGSSTCA.js +1 -0
- package/dist/{chunk-6ENW2VLC.cjs → chunk-3LC3CLYE.cjs} +1 -1
- package/dist/chunk-44LUF6RO.js +1 -0
- package/dist/{chunk-IXGOK22A.cjs → chunk-5NW4GR2Q.cjs} +1 -1
- package/dist/chunk-5PMGMODH.js +1 -0
- package/dist/{chunk-GVYLRJPB.cjs → chunk-66JP4PUG.cjs} +1 -1
- package/dist/{chunk-6XVLHSPK.js → chunk-673TXH2U.js} +1 -1
- package/dist/chunk-6M4IYQFZ.js +1 -0
- package/dist/chunk-B6SBIS6W.js +1 -0
- package/dist/{chunk-OL2TQDYM.cjs → chunk-BDBX4ZMW.cjs} +1 -1
- package/dist/chunk-BEMQAYI5.cjs +1 -0
- package/dist/chunk-CTGIT5TY.js +1 -0
- package/dist/chunk-FGMSPUSF.cjs +1 -0
- package/dist/{chunk-Z46FX2Y4.js → chunk-FP3LV577.js} +1 -1
- package/dist/{chunk-22IDCBFS.js → chunk-GFXNX2W7.js} +1 -1
- package/dist/chunk-GW4KDK3D.cjs +1 -0
- package/dist/chunk-GWXILWA5.cjs +1 -0
- package/dist/chunk-HSNPZS6R.cjs +1 -0
- package/dist/chunk-ITDJLXHO.js +1 -0
- package/dist/{chunk-QQMFHVPX.cjs → chunk-J3ZXNDMT.cjs} +1 -1
- package/dist/{chunk-FLQYTU5W.cjs → chunk-JHFSYEXB.cjs} +1 -1
- package/dist/{chunk-WCPENZWH.js → chunk-JI5FJX2E.js} +1 -1
- package/dist/chunk-K26HQR4Y.cjs +1 -0
- package/dist/chunk-KYMVIFAW.cjs +1 -0
- package/dist/{chunk-ZQXE6PIV.cjs → chunk-NVCXF5UR.cjs} +1 -1
- package/dist/chunk-O74TUGYF.js +1 -0
- package/dist/{chunk-MHEODCN3.cjs → chunk-OMHZCALN.cjs} +1 -1
- package/dist/chunk-QFJ3I53F.js +0 -0
- package/dist/chunk-R4O7XE2F.cjs +1 -0
- package/dist/chunk-TVMG2NYC.js +1 -0
- package/dist/chunk-UWMBE6BM.js +1 -0
- package/dist/{chunk-VBH6SKKO.js → chunk-VI2QG3FU.js} +1 -1
- package/dist/chunk-YCSQX2SY.js +1 -0
- package/dist/chunk-ZITGCTSW.js +1 -0
- package/dist/chunk.cjs +1 -1
- package/dist/chunk.d.cts +33 -22
- package/dist/chunk.d.ts +33 -22
- package/dist/chunk.js +1 -1
- package/dist/clamped-integer-subtract-DZ7rsJE4.d.cts +15 -0
- package/dist/clamped-integer-subtract-DZ7rsJE4.d.ts +15 -0
- package/dist/coerced-array-DRz3tqda.d.cts +14 -0
- package/dist/coerced-array-DRz3tqda.d.ts +14 -0
- package/dist/count-by.cjs +1 -1
- package/dist/count-by.d.cts +3 -3
- package/dist/count-by.d.ts +3 -3
- package/dist/count-by.js +1 -1
- package/dist/drop-first-by.cjs +1 -1
- package/dist/drop-first-by.js +1 -1
- package/dist/drop.cjs +1 -1
- package/dist/drop.d.cts +17 -30
- package/dist/drop.d.ts +17 -30
- package/dist/drop.js +1 -1
- package/dist/filter.cjs +1 -1
- package/dist/filter.d.cts +12 -4
- package/dist/filter.d.ts +12 -4
- package/dist/filter.js +1 -1
- package/dist/filtered-array-BNHX1Nwj.d.ts +18 -0
- package/dist/filtered-array-DX6NNaBq.d.cts +18 -0
- package/dist/first-by.cjs +1 -1
- package/dist/first-by.js +1 -1
- package/dist/from-keys.cjs +1 -1
- package/dist/from-keys.d.cts +2 -2
- package/dist/from-keys.d.ts +2 -2
- package/dist/from-keys.js +1 -1
- package/dist/funnel.reference-batch.test.cjs +1 -1
- package/dist/funnel.reference-batch.test.js +1 -1
- package/dist/group-by-prop.cjs +1 -0
- package/dist/group-by-prop.d.cts +91 -0
- package/dist/group-by-prop.d.ts +91 -0
- package/dist/group-by-prop.js +1 -0
- package/dist/group-by.cjs +1 -1
- package/dist/group-by.d.cts +13 -3
- package/dist/group-by.d.ts +13 -3
- package/dist/group-by.js +1 -1
- package/dist/has-at-least.cjs +1 -1
- package/dist/has-at-least.d.cts +6 -15
- package/dist/has-at-least.d.ts +6 -15
- package/dist/has-at-least.js +1 -1
- package/dist/index-by.cjs +1 -1
- package/dist/index-by.d.cts +3 -3
- package/dist/index-by.d.ts +3 -3
- package/dist/index-by.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +1 -1
- package/dist/map-keys.cjs +1 -1
- package/dist/map-keys.d.cts +4 -4
- package/dist/map-keys.d.ts +4 -4
- package/dist/map-keys.js +1 -1
- package/dist/merge-all.d.cts +1 -1
- package/dist/merge-all.d.ts +1 -1
- package/dist/omit.cjs +1 -1
- package/dist/omit.js +1 -1
- package/dist/partial-array-Vnf1fBtl.d.cts +10 -0
- package/dist/partial-array-Vnf1fBtl.d.ts +10 -0
- package/dist/pull-object.cjs +1 -1
- package/dist/pull-object.d.cts +3 -3
- package/dist/pull-object.d.ts +3 -3
- package/dist/pull-object.js +1 -1
- package/dist/sort-by.d.cts +1 -1
- package/dist/sort-by.d.ts +1 -1
- package/dist/take-first-by.cjs +1 -1
- package/dist/take-first-by.js +1 -1
- package/dist/take-last-while.cjs +1 -1
- package/dist/take-last-while.d.cts +2 -0
- package/dist/take-last-while.d.ts +2 -0
- package/dist/take-last-while.js +1 -1
- package/dist/take-while.d.cts +2 -0
- package/dist/take-while.d.ts +2 -0
- package/dist/tuple-parts-CrwnkDKX.d.ts +100 -0
- package/dist/tuple-parts-DAqFAJP8.d.cts +100 -0
- package/dist/type.helpers.cjs +1 -0
- package/dist/type.helpers.d.cts +10 -0
- package/dist/type.helpers.d.ts +10 -0
- package/dist/type.helpers.js +1 -0
- package/package.json +1 -1
- package/dist/chunk-2MU3SHCO.js +0 -1
- package/dist/chunk-3CFBQYOQ.js +0 -1
- package/dist/chunk-5VXKW6SI.cjs +0 -1
- package/dist/chunk-APUBIDDU.cjs +0 -1
- package/dist/chunk-B5QDOWVQ.cjs +0 -1
- package/dist/chunk-B7RHAPUE.js +0 -1
- package/dist/chunk-BOOMUHPG.js +0 -1
- package/dist/chunk-DLXKXNZT.js +0 -1
- package/dist/chunk-I7K3Z4BT.js +0 -1
- package/dist/chunk-IJ4I5A3K.js +0 -1
- package/dist/chunk-L4ITKDYB.cjs +0 -1
- package/dist/chunk-OEJ5J23C.js +0 -1
- package/dist/chunk-PIF5X7RQ.cjs +0 -1
- package/dist/chunk-PWHX2554.js +0 -1
- package/dist/chunk-THE6MSJO.cjs +0 -1
- package/dist/chunk-UUYCL4G2.js +0 -1
- package/dist/chunk-XLGD5ZUY.cjs +0 -1
- package/dist/chunk-YCM6N46T.js +0 -1
- package/dist/exact-record-Dhbe_K-E.d.ts +0 -5
- package/dist/exact-record-_isi2JMR.d.cts +0 -5
- package/dist/n-tuple-5jljrt4c.d.cts +0 -10
- package/dist/n-tuple-5jljrt4c.d.ts +0 -10
- package/dist/take-last-while.spec-d-.cjs +0 -1
- package/dist/take-last-while.spec-d-.d.cts +0 -2
- package/dist/take-last-while.spec-d-.d.ts +0 -2
- package/dist/take-last-while.spec-d-.js +0 -1
- package/dist/tuple-parts-CP0H7BrE.d.cts +0 -37
- package/dist/tuple-parts-CP0H7BrE.d.ts +0 -37
package/dist/drop-first-by.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkBDBX4ZMWcjs = require('./chunk-BDBX4ZMW.cjs');require('./chunk-JHFSYEXB.cjs');require('./chunk-Z6OOXW67.cjs');require('./chunk-EROXO3T4.cjs');require('./chunk-66JP4PUG.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.dropFirstBy = _chunkBDBX4ZMWcjs.a;
|
package/dist/drop-first-by.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-GFXNX2W7.js";import"./chunk-JI5FJX2E.js";import"./chunk-YYEJOSR3.js";import"./chunk-7KBK2RWQ.js";import"./chunk-ITDJLXHO.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";export{a as dropFirstBy};
|
package/dist/drop.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkR4O7XE2Fcjs = require('./chunk-R4O7XE2F.cjs');require('./chunk-N5JE6642.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.drop = _chunkR4O7XE2Fcjs.a;
|
package/dist/drop.d.cts
CHANGED
|
@@ -1,37 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsNegative, Writable, IsInteger } from 'type-fest';
|
|
2
|
+
import { C as ClampedIntegerSubtract } from './clamped-integer-subtract-DZ7rsJE4.cjs';
|
|
3
|
+
import { C as CoercedArray } from './coerced-array-DRz3tqda.cjs';
|
|
2
4
|
import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
|
|
3
|
-
import {
|
|
4
|
-
import { T as TupleParts } from './tuple-parts-
|
|
5
|
+
import { P as PartialArray } from './partial-array-Vnf1fBtl.cjs';
|
|
6
|
+
import { T as TupleParts } from './tuple-parts-DAqFAJP8.cjs';
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* This type makes it easier to use the result of TupleParts when the input is a
|
|
11
|
-
* fixed-length tuple but we still want to spread the rest of the array. e.g.
|
|
12
|
-
* `[...CoercedArray<TupleParts<T>["item"]>, ...TupleParts<T>["suffix"]]`.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
type CoercedArray<T> = IfNever<T, [], Array<T>>;
|
|
16
|
-
|
|
17
|
-
type Drop<T extends IterableContainer, N extends number> = IsNegative<N> extends true ? T : IsInteger<N> extends false ? Array<T[number]> : TupleParts<T>['prefix'] extends [
|
|
18
|
-
...NTuple<unknown, N>,
|
|
19
|
-
...infer Remaining
|
|
20
|
-
] ? [
|
|
21
|
-
...Remaining,
|
|
8
|
+
type Drop<T extends IterableContainer, N extends number> = IsNegative<N> extends true ? Writable<T> : IsInteger<N> extends false ? Array<T[number]> : ClampedIntegerSubtract<N, TupleParts<T>['required']['length']> extends infer RemainingPrefix extends number ? RemainingPrefix extends 0 ? [
|
|
9
|
+
...DropFixedTuple<TupleParts<T>['required'], N>,
|
|
10
|
+
...PartialArray<TupleParts<T>['optional']>,
|
|
22
11
|
...CoercedArray<TupleParts<T>['item']>,
|
|
23
12
|
...TupleParts<T>['suffix']
|
|
24
|
-
] :
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
type DropUpTo<T, N, Dropped extends ReadonlyArray<unknown> = []> = Dropped['length'] extends N ? T : T extends [unknown, ...infer Rest] ? // Take the current value, and then recurse with the array where it is
|
|
34
|
-
DropUpTo<Rest, N, [...Dropped, unknown]> | T : T;
|
|
13
|
+
] : ClampedIntegerSubtract<RemainingPrefix, TupleParts<T>['optional']['length']> extends infer RemainingOptional extends number ? RemainingOptional extends 0 ? [
|
|
14
|
+
...PartialArray<DropFixedTuple<TupleParts<T>['optional'], RemainingPrefix>>,
|
|
15
|
+
...CoercedArray<TupleParts<T>['item']>,
|
|
16
|
+
...TupleParts<T>['suffix']
|
|
17
|
+
] : [
|
|
18
|
+
...CoercedArray<TupleParts<T>['item']>,
|
|
19
|
+
...TupleParts<T>['suffix']
|
|
20
|
+
] | Exclude<DropFixedTuple<TupleParts<T>['suffix'], RemainingOptional, true>, TupleParts<T>['suffix']> : never : never;
|
|
21
|
+
type DropFixedTuple<T, N, IncludePrefixes = false, Dropped extends Array<unknown> = []> = Dropped['length'] extends N ? T : T extends readonly [unknown, ...infer Rest] ? DropFixedTuple<Rest, N, IncludePrefixes, [...Dropped, unknown]> | (true extends IncludePrefixes ? T : never) : [];
|
|
35
22
|
/**
|
|
36
23
|
* Removes first `n` elements from the `array`.
|
|
37
24
|
*
|
package/dist/drop.d.ts
CHANGED
|
@@ -1,37 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsNegative, Writable, IsInteger } from 'type-fest';
|
|
2
|
+
import { C as ClampedIntegerSubtract } from './clamped-integer-subtract-DZ7rsJE4.js';
|
|
3
|
+
import { C as CoercedArray } from './coerced-array-DRz3tqda.js';
|
|
2
4
|
import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
|
|
3
|
-
import {
|
|
4
|
-
import { T as TupleParts } from './tuple-parts-
|
|
5
|
+
import { P as PartialArray } from './partial-array-Vnf1fBtl.js';
|
|
6
|
+
import { T as TupleParts } from './tuple-parts-CrwnkDKX.js';
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* This type makes it easier to use the result of TupleParts when the input is a
|
|
11
|
-
* fixed-length tuple but we still want to spread the rest of the array. e.g.
|
|
12
|
-
* `[...CoercedArray<TupleParts<T>["item"]>, ...TupleParts<T>["suffix"]]`.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
type CoercedArray<T> = IfNever<T, [], Array<T>>;
|
|
16
|
-
|
|
17
|
-
type Drop<T extends IterableContainer, N extends number> = IsNegative<N> extends true ? T : IsInteger<N> extends false ? Array<T[number]> : TupleParts<T>['prefix'] extends [
|
|
18
|
-
...NTuple<unknown, N>,
|
|
19
|
-
...infer Remaining
|
|
20
|
-
] ? [
|
|
21
|
-
...Remaining,
|
|
8
|
+
type Drop<T extends IterableContainer, N extends number> = IsNegative<N> extends true ? Writable<T> : IsInteger<N> extends false ? Array<T[number]> : ClampedIntegerSubtract<N, TupleParts<T>['required']['length']> extends infer RemainingPrefix extends number ? RemainingPrefix extends 0 ? [
|
|
9
|
+
...DropFixedTuple<TupleParts<T>['required'], N>,
|
|
10
|
+
...PartialArray<TupleParts<T>['optional']>,
|
|
22
11
|
...CoercedArray<TupleParts<T>['item']>,
|
|
23
12
|
...TupleParts<T>['suffix']
|
|
24
|
-
] :
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
type DropUpTo<T, N, Dropped extends ReadonlyArray<unknown> = []> = Dropped['length'] extends N ? T : T extends [unknown, ...infer Rest] ? // Take the current value, and then recurse with the array where it is
|
|
34
|
-
DropUpTo<Rest, N, [...Dropped, unknown]> | T : T;
|
|
13
|
+
] : ClampedIntegerSubtract<RemainingPrefix, TupleParts<T>['optional']['length']> extends infer RemainingOptional extends number ? RemainingOptional extends 0 ? [
|
|
14
|
+
...PartialArray<DropFixedTuple<TupleParts<T>['optional'], RemainingPrefix>>,
|
|
15
|
+
...CoercedArray<TupleParts<T>['item']>,
|
|
16
|
+
...TupleParts<T>['suffix']
|
|
17
|
+
] : [
|
|
18
|
+
...CoercedArray<TupleParts<T>['item']>,
|
|
19
|
+
...TupleParts<T>['suffix']
|
|
20
|
+
] | Exclude<DropFixedTuple<TupleParts<T>['suffix'], RemainingOptional, true>, TupleParts<T>['suffix']> : never : never;
|
|
21
|
+
type DropFixedTuple<T, N, IncludePrefixes = false, Dropped extends Array<unknown> = []> = Dropped['length'] extends N ? T : T extends readonly [unknown, ...infer Rest] ? DropFixedTuple<Rest, N, IncludePrefixes, [...Dropped, unknown]> | (true extends IncludePrefixes ? T : never) : [];
|
|
35
22
|
/**
|
|
36
23
|
* Removes first `n` elements from the `array`.
|
|
37
24
|
*
|
package/dist/drop.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-YCSQX2SY.js";import"./chunk-EPU4K3DD.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";export{a as drop};
|
package/dist/filter.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk3LC3CLYEcjs = require('./chunk-3LC3CLYE.cjs');require('./chunk-N5JE6642.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.filter = _chunk3LC3CLYEcjs.a;
|
package/dist/filter.d.cts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import { Writable } from 'type-fest';
|
|
2
|
+
import { F as FilteredArray } from './filtered-array-DX6NNaBq.cjs';
|
|
3
|
+
import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
|
|
4
|
+
import './coerced-array-DRz3tqda.cjs';
|
|
5
|
+
import './tuple-parts-DAqFAJP8.cjs';
|
|
6
|
+
|
|
7
|
+
type NonRefinedFilteredArray<T extends IterableContainer, IsItemIncluded extends boolean> = boolean extends IsItemIncluded ? Array<T[number]> : IsItemIncluded extends true ? Writable<T> : [
|
|
8
|
+
];
|
|
1
9
|
/**
|
|
2
10
|
* Creates a shallow copy of a portion of a given array, filtered down to just
|
|
3
11
|
* the elements from the given array that pass the test implemented by the
|
|
@@ -17,8 +25,8 @@
|
|
|
17
25
|
* @lazy
|
|
18
26
|
* @category Array
|
|
19
27
|
*/
|
|
20
|
-
declare function filter<T,
|
|
21
|
-
declare function filter<T>(data:
|
|
28
|
+
declare function filter<T extends IterableContainer, Condition extends T[number]>(data: T, predicate: (value: T[number], index: number, data: T) => value is Condition): FilteredArray<T, Condition>;
|
|
29
|
+
declare function filter<T extends IterableContainer, IsItemIncluded extends boolean>(data: T, predicate: (value: T[number], index: number, data: T) => IsItemIncluded): NonRefinedFilteredArray<T, IsItemIncluded>;
|
|
22
30
|
/**
|
|
23
31
|
* Creates a shallow copy of a portion of a given array, filtered down to just
|
|
24
32
|
* the elements from the given array that pass the test implemented by the
|
|
@@ -37,7 +45,7 @@ declare function filter<T>(data: ReadonlyArray<T>, predicate: (value: T, index:
|
|
|
37
45
|
* @lazy
|
|
38
46
|
* @category Array
|
|
39
47
|
*/
|
|
40
|
-
declare function filter<T,
|
|
41
|
-
declare function filter<T>(predicate: (value: T, index: number, data:
|
|
48
|
+
declare function filter<T extends IterableContainer, Condition extends T[number]>(predicate: (value: T[number], index: number, data: T) => value is Condition): (data: T) => FilteredArray<T, Condition>;
|
|
49
|
+
declare function filter<T extends IterableContainer, IsItemIncluded extends boolean>(predicate: (value: T[number], index: number, data: T) => IsItemIncluded): (data: T) => NonRefinedFilteredArray<T, IsItemIncluded>;
|
|
42
50
|
|
|
43
51
|
export { filter };
|
package/dist/filter.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import { Writable } from 'type-fest';
|
|
2
|
+
import { F as FilteredArray } from './filtered-array-BNHX1Nwj.js';
|
|
3
|
+
import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
|
|
4
|
+
import './coerced-array-DRz3tqda.js';
|
|
5
|
+
import './tuple-parts-CrwnkDKX.js';
|
|
6
|
+
|
|
7
|
+
type NonRefinedFilteredArray<T extends IterableContainer, IsItemIncluded extends boolean> = boolean extends IsItemIncluded ? Array<T[number]> : IsItemIncluded extends true ? Writable<T> : [
|
|
8
|
+
];
|
|
1
9
|
/**
|
|
2
10
|
* Creates a shallow copy of a portion of a given array, filtered down to just
|
|
3
11
|
* the elements from the given array that pass the test implemented by the
|
|
@@ -17,8 +25,8 @@
|
|
|
17
25
|
* @lazy
|
|
18
26
|
* @category Array
|
|
19
27
|
*/
|
|
20
|
-
declare function filter<T,
|
|
21
|
-
declare function filter<T>(data:
|
|
28
|
+
declare function filter<T extends IterableContainer, Condition extends T[number]>(data: T, predicate: (value: T[number], index: number, data: T) => value is Condition): FilteredArray<T, Condition>;
|
|
29
|
+
declare function filter<T extends IterableContainer, IsItemIncluded extends boolean>(data: T, predicate: (value: T[number], index: number, data: T) => IsItemIncluded): NonRefinedFilteredArray<T, IsItemIncluded>;
|
|
22
30
|
/**
|
|
23
31
|
* Creates a shallow copy of a portion of a given array, filtered down to just
|
|
24
32
|
* the elements from the given array that pass the test implemented by the
|
|
@@ -37,7 +45,7 @@ declare function filter<T>(data: ReadonlyArray<T>, predicate: (value: T, index:
|
|
|
37
45
|
* @lazy
|
|
38
46
|
* @category Array
|
|
39
47
|
*/
|
|
40
|
-
declare function filter<T,
|
|
41
|
-
declare function filter<T>(predicate: (value: T, index: number, data:
|
|
48
|
+
declare function filter<T extends IterableContainer, Condition extends T[number]>(predicate: (value: T[number], index: number, data: T) => value is Condition): (data: T) => FilteredArray<T, Condition>;
|
|
49
|
+
declare function filter<T extends IterableContainer, IsItemIncluded extends boolean>(predicate: (value: T[number], index: number, data: T) => IsItemIncluded): (data: T) => NonRefinedFilteredArray<T, IsItemIncluded>;
|
|
42
50
|
|
|
43
51
|
export { filter };
|
package/dist/filter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-ZITGCTSW.js";import"./chunk-EPU4K3DD.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";export{a as filter};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { C as CoercedArray } from './coerced-array-DRz3tqda.js';
|
|
2
|
+
import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
|
|
3
|
+
import { T as TupleParts } from './tuple-parts-CrwnkDKX.js';
|
|
4
|
+
|
|
5
|
+
type FilteredArray<T extends IterableContainer, Condition> = T extends unknown ? [
|
|
6
|
+
...FilteredFixedTuple<TupleParts<T>['required'], Condition>,
|
|
7
|
+
...FilteredFixedTuple<TupleParts<T>['optional'], Condition>,
|
|
8
|
+
...CoercedArray<SymmetricRefine<TupleParts<T>['item'], Condition>>,
|
|
9
|
+
...FilteredFixedTuple<TupleParts<T>['suffix'], Condition>
|
|
10
|
+
] : never;
|
|
11
|
+
type FilteredFixedTuple<T, Condition, Output extends Array<unknown> = []> = T extends readonly [infer Head, ...infer Rest] ? FilteredFixedTuple<Rest, Condition, Head extends Condition ? [
|
|
12
|
+
...Output,
|
|
13
|
+
Head
|
|
14
|
+
] : Head | Condition extends object ? Output : Condition extends Head ? // But for any other type (mostly primitives), if the condition
|
|
15
|
+
Output | [...Output, Condition] : Output> : Output;
|
|
16
|
+
type SymmetricRefine<Item, Condition> = Item extends Condition ? Item : Condition extends Item ? Condition : never;
|
|
17
|
+
|
|
18
|
+
export type { FilteredArray as F };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { C as CoercedArray } from './coerced-array-DRz3tqda.cjs';
|
|
2
|
+
import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
|
|
3
|
+
import { T as TupleParts } from './tuple-parts-DAqFAJP8.cjs';
|
|
4
|
+
|
|
5
|
+
type FilteredArray<T extends IterableContainer, Condition> = T extends unknown ? [
|
|
6
|
+
...FilteredFixedTuple<TupleParts<T>['required'], Condition>,
|
|
7
|
+
...FilteredFixedTuple<TupleParts<T>['optional'], Condition>,
|
|
8
|
+
...CoercedArray<SymmetricRefine<TupleParts<T>['item'], Condition>>,
|
|
9
|
+
...FilteredFixedTuple<TupleParts<T>['suffix'], Condition>
|
|
10
|
+
] : never;
|
|
11
|
+
type FilteredFixedTuple<T, Condition, Output extends Array<unknown> = []> = T extends readonly [infer Head, ...infer Rest] ? FilteredFixedTuple<Rest, Condition, Head extends Condition ? [
|
|
12
|
+
...Output,
|
|
13
|
+
Head
|
|
14
|
+
] : Head | Condition extends object ? Output : Condition extends Head ? // But for any other type (mostly primitives), if the condition
|
|
15
|
+
Output | [...Output, Condition] : Output> : Output;
|
|
16
|
+
type SymmetricRefine<Item, Condition> = Item extends Condition ? Item : Condition extends Item ? Condition : never;
|
|
17
|
+
|
|
18
|
+
export type { FilteredArray as F };
|
package/dist/first-by.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkJ3ZXNDMTcjs = require('./chunk-J3ZXNDMT.cjs');require('./chunk-EROXO3T4.cjs');require('./chunk-66JP4PUG.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.firstBy = _chunkJ3ZXNDMTcjs.a;
|
package/dist/first-by.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-FP3LV577.js";import"./chunk-7KBK2RWQ.js";import"./chunk-ITDJLXHO.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";export{a as firstBy};
|
package/dist/from-keys.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkBEMQAYI5cjs = require('./chunk-BEMQAYI5.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.fromKeys = _chunkBEMQAYI5cjs.a;
|
package/dist/from-keys.d.cts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Simplify } from 'type-fest';
|
|
2
|
-
import {
|
|
2
|
+
import { B as BoundedPartial } from './bounded-partial-wqR8ceNQ.cjs';
|
|
3
3
|
import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
|
|
4
4
|
import './if-bounded-record-Drd4UbBU.cjs';
|
|
5
5
|
|
|
6
6
|
type ExactlyOneKey<T, V> = T extends PropertyKey ? {
|
|
7
7
|
[P in T]: V;
|
|
8
8
|
} : never;
|
|
9
|
-
type FromKeys<T extends IterableContainer, V> = T extends readonly [] ? {} : T extends readonly [infer Head, ...infer Rest] ? ExactlyOneKey<Head, V> & FromKeys<Rest, V> : T[number] extends PropertyKey ?
|
|
9
|
+
type FromKeys<T extends IterableContainer, V> = T extends readonly [] ? {} : T extends readonly [infer Head, ...infer Rest] ? ExactlyOneKey<Head, V> & FromKeys<Rest, V> : T[number] extends PropertyKey ? BoundedPartial<Record<T[number], V>> : never;
|
|
10
10
|
/**
|
|
11
11
|
* Creates an object that maps each key in `data` to the result of `mapper` for
|
|
12
12
|
* that key. Duplicate keys are overwritten, guaranteeing that `mapper` is run
|
package/dist/from-keys.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Simplify } from 'type-fest';
|
|
2
|
-
import {
|
|
2
|
+
import { B as BoundedPartial } from './bounded-partial-CJjczH6j.js';
|
|
3
3
|
import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
|
|
4
4
|
import './if-bounded-record-Drd4UbBU.js';
|
|
5
5
|
|
|
6
6
|
type ExactlyOneKey<T, V> = T extends PropertyKey ? {
|
|
7
7
|
[P in T]: V;
|
|
8
8
|
} : never;
|
|
9
|
-
type FromKeys<T extends IterableContainer, V> = T extends readonly [] ? {} : T extends readonly [infer Head, ...infer Rest] ? ExactlyOneKey<Head, V> & FromKeys<Rest, V> : T[number] extends PropertyKey ?
|
|
9
|
+
type FromKeys<T extends IterableContainer, V> = T extends readonly [] ? {} : T extends readonly [infer Head, ...infer Rest] ? ExactlyOneKey<Head, V> & FromKeys<Rest, V> : T[number] extends PropertyKey ? BoundedPartial<Record<T[number], V>> : never;
|
|
10
10
|
/**
|
|
11
11
|
* Creates an object that maps each key in `data` to the result of `mapper` for
|
|
12
12
|
* that key. Duplicate keys are overwritten, guaranteeing that `mapper` is run
|
package/dist/from-keys.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-TVMG2NYC.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";export{a as fromKeys};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict"; function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var
|
|
1
|
+
"use strict"; function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunkBEMQAYI5cjs = require('./chunk-BEMQAYI5.cjs');var _chunkGOUUMCT7cjs = require('./chunk-GOUUMCT7.cjs');var _chunkWYRK6YJUcjs = require('./chunk-WYRK6YJU.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');function i(e,a,n=0){let l=_chunkGOUUMCT7cjs.a.call(void 0, s=>{e(s.map(({params:t})=>t)).then(t=>{for(let[o,{params:r,promiseCallbacks:[c]}]of s.entries()){let y=a(t,o,...r);c(y)}}).catch(t=>{for(let{promiseCallbacks:[,o]}of s)o(t)})},{reducer:(s,t)=>[..._nullishCoalesce(s, () => ([])),t],maxBurstDurationMs:n,triggerAt:"end"});return{...l,call:async(...s)=>new Promise((...t)=>{l.call({promiseCallbacks:t,params:s})})}}describe("showcase",()=>{it("results as object",async()=>{let e=vi.fn(async o=>_chunkBEMQAYI5cjs.a.call(void 0, o,r=>r.length)),a=i(async o=>await e(o.flat()),(o,r,c)=>o[c]),n=[a.call("short"),a.call("medium"),a.call("loooooooooooooong")];expect(e).toHaveBeenCalledTimes(0);let[l,s,t]=await Promise.all(n);expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenLastCalledWith(["short","medium","loooooooooooooong"]),expect(e).toHaveLastResolvedWith({short:5,medium:6,loooooooooooooong:17}),expect(l).toBe(5),expect(s).toBe(6),expect(t).toBe(17)}),it("results as array",async()=>{let e=vi.fn(async o=>o.map(r=>r.length)),a=i(async o=>await e(o.flat()),(o,r)=>o[r]),n=[a.call("short"),a.call("medium"),a.call("loooooooooooooong")];expect(e).toHaveBeenCalledTimes(0);let[l,s,t]=await Promise.all(n);expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenLastCalledWith(["short","medium","loooooooooooooong"]),expect(e).toHaveLastResolvedWith([5,6,17]),expect(l).toBe(5),expect(s).toBe(6),expect(t).toBe(17)}),it("error handling",async()=>{let e=i(async a=>{if(a.length>1)throw new Error(`Batch too big! ${JSON.stringify(a)}`)},_chunkWYRK6YJUcjs.a.call(void 0, ));await expect(e.call("a")).resolves.toBeUndefined(),await expect(Promise.all([e.call("hello"),e.call("world")])).rejects.toThrow('Batch too big! [["hello"],["world"]]')})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d}from"./chunk-
|
|
1
|
+
import{a as d}from"./chunk-TVMG2NYC.js";import{a as p}from"./chunk-AWXJSK4F.js";import{a as m}from"./chunk-AFO7BV2X.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";function i(e,a,n=0){let l=p(s=>{e(s.map(({params:t})=>t)).then(t=>{for(let[o,{params:r,promiseCallbacks:[c]}]of s.entries()){let y=a(t,o,...r);c(y)}}).catch(t=>{for(let{promiseCallbacks:[,o]}of s)o(t)})},{reducer:(s,t)=>[...s??[],t],maxBurstDurationMs:n,triggerAt:"end"});return{...l,call:async(...s)=>new Promise((...t)=>{l.call({promiseCallbacks:t,params:s})})}}describe("showcase",()=>{it("results as object",async()=>{let e=vi.fn(async o=>d(o,r=>r.length)),a=i(async o=>await e(o.flat()),(o,r,c)=>o[c]),n=[a.call("short"),a.call("medium"),a.call("loooooooooooooong")];expect(e).toHaveBeenCalledTimes(0);let[l,s,t]=await Promise.all(n);expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenLastCalledWith(["short","medium","loooooooooooooong"]),expect(e).toHaveLastResolvedWith({short:5,medium:6,loooooooooooooong:17}),expect(l).toBe(5),expect(s).toBe(6),expect(t).toBe(17)}),it("results as array",async()=>{let e=vi.fn(async o=>o.map(r=>r.length)),a=i(async o=>await e(o.flat()),(o,r)=>o[r]),n=[a.call("short"),a.call("medium"),a.call("loooooooooooooong")];expect(e).toHaveBeenCalledTimes(0);let[l,s,t]=await Promise.all(n);expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenLastCalledWith(["short","medium","loooooooooooooong"]),expect(e).toHaveLastResolvedWith([5,6,17]),expect(l).toBe(5),expect(s).toBe(6),expect(t).toBe(17)}),it("error handling",async()=>{let e=i(async a=>{if(a.length>1)throw new Error(`Batch too big! ${JSON.stringify(a)}`)},m());await expect(e.call("a")).resolves.toBeUndefined(),await expect(Promise.all([e.call("hello"),e.call("world")])).rejects.toThrow('Batch too big! [["hello"],["world"]]')})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkHSNPZS6Rcjs = require('./chunk-HSNPZS6R.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.groupByProp = _chunkHSNPZS6Rcjs.a;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ConditionalKeys, AllUnionFields, IfNever, Merge, And } from 'type-fest';
|
|
2
|
+
import { A as ArrayRequiredPrefix } from './array-required-prefix-BW08fIbb.cjs';
|
|
3
|
+
import { B as BoundedPartial } from './bounded-partial-wqR8ceNQ.cjs';
|
|
4
|
+
import { F as FilteredArray } from './filtered-array-DX6NNaBq.cjs';
|
|
5
|
+
import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
|
|
6
|
+
import { T as TupleParts } from './tuple-parts-DAqFAJP8.cjs';
|
|
7
|
+
import './clamped-integer-subtract-DZ7rsJE4.cjs';
|
|
8
|
+
import './coerced-array-DRz3tqda.cjs';
|
|
9
|
+
import './if-bounded-record-Drd4UbBU.cjs';
|
|
10
|
+
|
|
11
|
+
type GroupByProp<T extends IterableContainer, Prop extends GroupableProps<T>> = T extends unknown ? FixEmptyObject<EnsureValuesAreNonEmpty<{
|
|
12
|
+
[Value in AllPropValues<T, Prop>]: FilteredArray<T, Record<Prop, Value>>;
|
|
13
|
+
}>> : never;
|
|
14
|
+
type GroupableProps<T extends IterableContainer> = ConditionalKeys<ItemsSuperObject<T>, PropertyKey | undefined>;
|
|
15
|
+
type AllPropValues<T extends IterableContainer, Prop extends GroupableProps<T>> = Extract<ItemsSuperObject<T>[Prop], PropertyKey>;
|
|
16
|
+
type ItemsSuperObject<T extends IterableContainer> = AllUnionFields<Exclude<T[number], undefined>>;
|
|
17
|
+
type FixEmptyObject<T> = IfNever<keyof T, Record<PropertyKey, never>, T>;
|
|
18
|
+
type EnsureValuesAreNonEmpty<T extends Record<PropertyKey, IterableContainer>> = Merge<T, BoundedPartial<{
|
|
19
|
+
[P in keyof T as IsPossiblyEmpty<T[P]> extends true ? P : never]: ArrayRequiredPrefix<T[P], 1>;
|
|
20
|
+
}>>;
|
|
21
|
+
type IsPossiblyEmpty<T extends IterableContainer> = And<IsEmpty<TupleParts<T>['required']>, IsEmpty<TupleParts<T>['suffix']>>;
|
|
22
|
+
type IsEmpty<T> = T extends readonly [] ? true : false;
|
|
23
|
+
/**
|
|
24
|
+
* Groups the elements of an array of objects based on the values of a
|
|
25
|
+
* specified property of those objects. The result would contain a property for
|
|
26
|
+
* each unique value of the specific property, with it's value being the input
|
|
27
|
+
* array filtered to only items that have that property set to that value.
|
|
28
|
+
* For any object where the property is missing, or if it's value is
|
|
29
|
+
* `undefined` the item would be filtered out.
|
|
30
|
+
*
|
|
31
|
+
* The grouping property is enforced at the type level to exist in at least one
|
|
32
|
+
* item and to never have a value that cannot be used as an object key (e.g. it
|
|
33
|
+
* must be `PropertyKey | undefined`).
|
|
34
|
+
*
|
|
35
|
+
* The resulting arrays are filtered with the prop and it's value as a
|
|
36
|
+
* type-guard, effectively narrowing the items in each output arrays. This
|
|
37
|
+
* means that when the grouping property is the discriminator of a
|
|
38
|
+
* discriminated union type each output array would contain just the subtype for
|
|
39
|
+
* that value.
|
|
40
|
+
*
|
|
41
|
+
* If you need more control over the grouping you should use `groupBy` instead.
|
|
42
|
+
*
|
|
43
|
+
* @param data - The items to group.
|
|
44
|
+
* @param prop - The property name to group by.
|
|
45
|
+
* @signature
|
|
46
|
+
* P.groupByProp(data, prop)
|
|
47
|
+
* @example
|
|
48
|
+
* const result = P.groupByProp(
|
|
49
|
+
* // ^? { cat: [{ a: 'cat' }], dog: [{ a: 'dog' }] }
|
|
50
|
+
* [{ a: 'cat' }, { a: 'dog' }] as const,
|
|
51
|
+
* 'a',
|
|
52
|
+
* );
|
|
53
|
+
* @dataFirst
|
|
54
|
+
* @category Array
|
|
55
|
+
*/
|
|
56
|
+
declare function groupByProp<T extends IterableContainer, Prop extends GroupableProps<T>>(data: T, prop: Prop): GroupByProp<T, Prop>;
|
|
57
|
+
/**
|
|
58
|
+
* Groups the elements of an array of objects based on the values of a
|
|
59
|
+
* specified property of those objects. The result would contain a property for
|
|
60
|
+
* each unique value of the specific property, with it's value being the input
|
|
61
|
+
* array filtered to only items that have that property set to that value.
|
|
62
|
+
* For any object where the property is missing, or if it's value is
|
|
63
|
+
* `undefined` the item would be filtered out.
|
|
64
|
+
*
|
|
65
|
+
* The grouping property is enforced at the type level to exist in at least one
|
|
66
|
+
* item and to never have a value that cannot be used as an object key (e.g. it
|
|
67
|
+
* must be `PropertyKey | undefined`).
|
|
68
|
+
*
|
|
69
|
+
* The resulting arrays are filtered with the prop and it's value as a
|
|
70
|
+
* type-guard, effectively narrowing the items in each output arrays. This
|
|
71
|
+
* means that when the grouping property is the discriminator of a
|
|
72
|
+
* discriminated union type each output array would contain just the subtype for
|
|
73
|
+
* that value.
|
|
74
|
+
*
|
|
75
|
+
* If you need more control over the grouping you should use `groupBy` instead.
|
|
76
|
+
*
|
|
77
|
+
* @param prop - The property name to group by.
|
|
78
|
+
* @signature
|
|
79
|
+
* P.groupByProp(prop)(data);
|
|
80
|
+
* @example
|
|
81
|
+
* const result = P.pipe(
|
|
82
|
+
* // ^? { cat: [{ a: 'cat' }], dog: [{ a: 'dog' }] }
|
|
83
|
+
* [{ a: 'cat' }, { a: 'dog' }] as const,
|
|
84
|
+
* P.groupByProp('a'),
|
|
85
|
+
* );
|
|
86
|
+
* @dataLast
|
|
87
|
+
* @category Array
|
|
88
|
+
*/
|
|
89
|
+
declare function groupByProp<T extends IterableContainer, Prop extends GroupableProps<T>>(prop: Prop): (data: T) => GroupByProp<T, Prop>;
|
|
90
|
+
|
|
91
|
+
export { groupByProp };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ConditionalKeys, AllUnionFields, IfNever, Merge, And } from 'type-fest';
|
|
2
|
+
import { A as ArrayRequiredPrefix } from './array-required-prefix-a3sgCkd2.js';
|
|
3
|
+
import { B as BoundedPartial } from './bounded-partial-CJjczH6j.js';
|
|
4
|
+
import { F as FilteredArray } from './filtered-array-BNHX1Nwj.js';
|
|
5
|
+
import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
|
|
6
|
+
import { T as TupleParts } from './tuple-parts-CrwnkDKX.js';
|
|
7
|
+
import './clamped-integer-subtract-DZ7rsJE4.js';
|
|
8
|
+
import './coerced-array-DRz3tqda.js';
|
|
9
|
+
import './if-bounded-record-Drd4UbBU.js';
|
|
10
|
+
|
|
11
|
+
type GroupByProp<T extends IterableContainer, Prop extends GroupableProps<T>> = T extends unknown ? FixEmptyObject<EnsureValuesAreNonEmpty<{
|
|
12
|
+
[Value in AllPropValues<T, Prop>]: FilteredArray<T, Record<Prop, Value>>;
|
|
13
|
+
}>> : never;
|
|
14
|
+
type GroupableProps<T extends IterableContainer> = ConditionalKeys<ItemsSuperObject<T>, PropertyKey | undefined>;
|
|
15
|
+
type AllPropValues<T extends IterableContainer, Prop extends GroupableProps<T>> = Extract<ItemsSuperObject<T>[Prop], PropertyKey>;
|
|
16
|
+
type ItemsSuperObject<T extends IterableContainer> = AllUnionFields<Exclude<T[number], undefined>>;
|
|
17
|
+
type FixEmptyObject<T> = IfNever<keyof T, Record<PropertyKey, never>, T>;
|
|
18
|
+
type EnsureValuesAreNonEmpty<T extends Record<PropertyKey, IterableContainer>> = Merge<T, BoundedPartial<{
|
|
19
|
+
[P in keyof T as IsPossiblyEmpty<T[P]> extends true ? P : never]: ArrayRequiredPrefix<T[P], 1>;
|
|
20
|
+
}>>;
|
|
21
|
+
type IsPossiblyEmpty<T extends IterableContainer> = And<IsEmpty<TupleParts<T>['required']>, IsEmpty<TupleParts<T>['suffix']>>;
|
|
22
|
+
type IsEmpty<T> = T extends readonly [] ? true : false;
|
|
23
|
+
/**
|
|
24
|
+
* Groups the elements of an array of objects based on the values of a
|
|
25
|
+
* specified property of those objects. The result would contain a property for
|
|
26
|
+
* each unique value of the specific property, with it's value being the input
|
|
27
|
+
* array filtered to only items that have that property set to that value.
|
|
28
|
+
* For any object where the property is missing, or if it's value is
|
|
29
|
+
* `undefined` the item would be filtered out.
|
|
30
|
+
*
|
|
31
|
+
* The grouping property is enforced at the type level to exist in at least one
|
|
32
|
+
* item and to never have a value that cannot be used as an object key (e.g. it
|
|
33
|
+
* must be `PropertyKey | undefined`).
|
|
34
|
+
*
|
|
35
|
+
* The resulting arrays are filtered with the prop and it's value as a
|
|
36
|
+
* type-guard, effectively narrowing the items in each output arrays. This
|
|
37
|
+
* means that when the grouping property is the discriminator of a
|
|
38
|
+
* discriminated union type each output array would contain just the subtype for
|
|
39
|
+
* that value.
|
|
40
|
+
*
|
|
41
|
+
* If you need more control over the grouping you should use `groupBy` instead.
|
|
42
|
+
*
|
|
43
|
+
* @param data - The items to group.
|
|
44
|
+
* @param prop - The property name to group by.
|
|
45
|
+
* @signature
|
|
46
|
+
* P.groupByProp(data, prop)
|
|
47
|
+
* @example
|
|
48
|
+
* const result = P.groupByProp(
|
|
49
|
+
* // ^? { cat: [{ a: 'cat' }], dog: [{ a: 'dog' }] }
|
|
50
|
+
* [{ a: 'cat' }, { a: 'dog' }] as const,
|
|
51
|
+
* 'a',
|
|
52
|
+
* );
|
|
53
|
+
* @dataFirst
|
|
54
|
+
* @category Array
|
|
55
|
+
*/
|
|
56
|
+
declare function groupByProp<T extends IterableContainer, Prop extends GroupableProps<T>>(data: T, prop: Prop): GroupByProp<T, Prop>;
|
|
57
|
+
/**
|
|
58
|
+
* Groups the elements of an array of objects based on the values of a
|
|
59
|
+
* specified property of those objects. The result would contain a property for
|
|
60
|
+
* each unique value of the specific property, with it's value being the input
|
|
61
|
+
* array filtered to only items that have that property set to that value.
|
|
62
|
+
* For any object where the property is missing, or if it's value is
|
|
63
|
+
* `undefined` the item would be filtered out.
|
|
64
|
+
*
|
|
65
|
+
* The grouping property is enforced at the type level to exist in at least one
|
|
66
|
+
* item and to never have a value that cannot be used as an object key (e.g. it
|
|
67
|
+
* must be `PropertyKey | undefined`).
|
|
68
|
+
*
|
|
69
|
+
* The resulting arrays are filtered with the prop and it's value as a
|
|
70
|
+
* type-guard, effectively narrowing the items in each output arrays. This
|
|
71
|
+
* means that when the grouping property is the discriminator of a
|
|
72
|
+
* discriminated union type each output array would contain just the subtype for
|
|
73
|
+
* that value.
|
|
74
|
+
*
|
|
75
|
+
* If you need more control over the grouping you should use `groupBy` instead.
|
|
76
|
+
*
|
|
77
|
+
* @param prop - The property name to group by.
|
|
78
|
+
* @signature
|
|
79
|
+
* P.groupByProp(prop)(data);
|
|
80
|
+
* @example
|
|
81
|
+
* const result = P.pipe(
|
|
82
|
+
* // ^? { cat: [{ a: 'cat' }], dog: [{ a: 'dog' }] }
|
|
83
|
+
* [{ a: 'cat' }, { a: 'dog' }] as const,
|
|
84
|
+
* P.groupByProp('a'),
|
|
85
|
+
* );
|
|
86
|
+
* @dataLast
|
|
87
|
+
* @category Array
|
|
88
|
+
*/
|
|
89
|
+
declare function groupByProp<T extends IterableContainer, Prop extends GroupableProps<T>>(prop: Prop): (data: T) => GroupByProp<T, Prop>;
|
|
90
|
+
|
|
91
|
+
export { groupByProp };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./chunk-6M4IYQFZ.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";export{a as groupByProp};
|
package/dist/group-by.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGW4KDK3Dcjs = require('./chunk-GW4KDK3D.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.groupBy = _chunkGW4KDK3Dcjs.a;
|
package/dist/group-by.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as BoundedPartial } from './bounded-partial-wqR8ceNQ.cjs';
|
|
2
2
|
import { N as NonEmptyArray } from './non-empty-array-C9Od1wmF.cjs';
|
|
3
3
|
import './if-bounded-record-Drd4UbBU.cjs';
|
|
4
4
|
import 'type-fest';
|
|
@@ -11,6 +11,11 @@ import 'type-fest';
|
|
|
11
11
|
* return `undefined` in order to exclude the item from being added to any
|
|
12
12
|
* group.
|
|
13
13
|
*
|
|
14
|
+
* If you are grouping objects by a property of theirs (e.g.
|
|
15
|
+
* `groupBy(data, ({ myProp }) => myProp)` or `groupBy(data, prop('myProp'))`)
|
|
16
|
+
* consider using `groupByProp` (e.g. `groupByProp(data, 'myProp')`) instead,
|
|
17
|
+
* as it would provide better typing.
|
|
18
|
+
*
|
|
14
19
|
* @param data - The items to group.
|
|
15
20
|
* @param callbackfn - A function to execute for each element in the iterable.
|
|
16
21
|
* It should return a value indicating the group of the current element, or
|
|
@@ -25,7 +30,7 @@ import 'type-fest';
|
|
|
25
30
|
* @dataFirst
|
|
26
31
|
* @category Array
|
|
27
32
|
*/
|
|
28
|
-
declare function groupBy<T, Key extends PropertyKey = PropertyKey>(data: ReadonlyArray<T>, callbackfn: (value: T, index: number, data: ReadonlyArray<T>) => Key | undefined):
|
|
33
|
+
declare function groupBy<T, Key extends PropertyKey = PropertyKey>(data: ReadonlyArray<T>, callbackfn: (value: T, index: number, data: ReadonlyArray<T>) => Key | undefined): BoundedPartial<Record<Key, NonEmptyArray<T>>>;
|
|
29
34
|
/**
|
|
30
35
|
* Groups the elements of a given iterable according to the string values
|
|
31
36
|
* returned by a provided callback function. The returned object has separate
|
|
@@ -34,6 +39,11 @@ declare function groupBy<T, Key extends PropertyKey = PropertyKey>(data: Readonl
|
|
|
34
39
|
* return `undefined` in order to exclude the item from being added to any
|
|
35
40
|
* group.
|
|
36
41
|
*
|
|
42
|
+
* If you are grouping objects by a property of theirs (e.g.
|
|
43
|
+
* `groupBy(data, ({ myProp }) => myProp)` or `groupBy(data, prop('myProp'))`)
|
|
44
|
+
* consider using `groupByProp` (e.g. `groupByProp(data, 'myProp')`) instead,
|
|
45
|
+
* as it would provide better typing.
|
|
46
|
+
*
|
|
37
47
|
* @param callbackfn - A function to execute for each element in the iterable.
|
|
38
48
|
* It should return a value indicating the group of the current element, or
|
|
39
49
|
* `undefined` when the item should be excluded from any group.
|
|
@@ -53,6 +63,6 @@ declare function groupBy<T, Key extends PropertyKey = PropertyKey>(data: Readonl
|
|
|
53
63
|
* @dataLast
|
|
54
64
|
* @category Array
|
|
55
65
|
*/
|
|
56
|
-
declare function groupBy<T, Key extends PropertyKey = PropertyKey>(callbackfn: (value: T, index: number, data: ReadonlyArray<T>) => Key | undefined): (items: ReadonlyArray<T>) =>
|
|
66
|
+
declare function groupBy<T, Key extends PropertyKey = PropertyKey>(callbackfn: (value: T, index: number, data: ReadonlyArray<T>) => Key | undefined): (items: ReadonlyArray<T>) => BoundedPartial<Record<Key, NonEmptyArray<T>>>;
|
|
57
67
|
|
|
58
68
|
export { groupBy };
|