@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.
Files changed (79) hide show
  1. package/dist/{bounded-partial-BzynYDVs.d.ts → bounded-partial-B15MLSAS.d.ts} +1 -2
  2. package/dist/{bounded-partial-BqwRN49U.d.cts → bounded-partial-BhnecV3P.d.cts} +1 -2
  3. package/dist/chunk-4Y6VRHEP.js +1 -0
  4. package/dist/chunk-ALP5JUXX.cjs +1 -0
  5. package/dist/{chunk-Z7D7Q6U3.js → chunk-DXA7AZUA.js} +1 -1
  6. package/dist/chunk-HHNHTPVO.cjs +1 -0
  7. package/dist/{chunk-FOUZI2Q3.cjs → chunk-QPMGUF2V.cjs} +1 -1
  8. package/dist/chunk-RZBBV6PK.js +1 -0
  9. package/dist/chunk.d.cts +1 -9
  10. package/dist/chunk.d.ts +1 -9
  11. package/dist/constant.d.cts +1 -1
  12. package/dist/constant.d.ts +1 -1
  13. package/dist/count-by.d.cts +2 -3
  14. package/dist/count-by.d.ts +2 -3
  15. package/dist/from-keys.d.cts +1 -2
  16. package/dist/from-keys.d.ts +1 -2
  17. package/dist/funnel.lodash-debounce-with-cached-value.test.cjs +1 -1
  18. package/dist/funnel.lodash-debounce-with-cached-value.test.js +1 -1
  19. package/dist/funnel.lodash-debounce.test.cjs +1 -1
  20. package/dist/funnel.lodash-debounce.test.js +1 -1
  21. package/dist/funnel.lodash-throttle-with-cached-value.test.cjs +1 -1
  22. package/dist/funnel.lodash-throttle-with-cached-value.test.js +1 -1
  23. package/dist/funnel.lodash-throttle.test.cjs +1 -1
  24. package/dist/funnel.lodash-throttle.test.js +1 -1
  25. package/dist/funnel.perkakas-debounce.test.cjs +1 -1
  26. package/dist/funnel.perkakas-debounce.test.js +1 -1
  27. package/dist/funnel.reference-batch.test.cjs +1 -1
  28. package/dist/funnel.reference-batch.test.js +1 -1
  29. package/dist/funnel.test-d.cjs +1 -1
  30. package/dist/funnel.test-d.js +1 -1
  31. package/dist/funnel.test.cjs +1 -1
  32. package/dist/funnel.test.js +1 -1
  33. package/dist/group-by-prop.d.cts +1 -2
  34. package/dist/group-by-prop.d.ts +1 -2
  35. package/dist/group-by.d.cts +2 -3
  36. package/dist/group-by.d.ts +2 -3
  37. package/dist/index-by.d.cts +2 -3
  38. package/dist/index-by.d.ts +2 -3
  39. package/dist/index.cjs +1 -1
  40. package/dist/index.d.cts +3 -3
  41. package/dist/index.d.ts +3 -3
  42. package/dist/index.js +1 -1
  43. package/dist/map-keys.d.cts +2 -3
  44. package/dist/map-keys.d.ts +2 -3
  45. package/dist/map-values.d.cts +1 -1
  46. package/dist/map-values.d.ts +1 -1
  47. package/dist/n-tuple-5jljrt4c.d.cts +10 -0
  48. package/dist/n-tuple-5jljrt4c.d.ts +10 -0
  49. package/dist/omit-by.d.cts +2 -3
  50. package/dist/omit-by.d.ts +2 -3
  51. package/dist/path-or.d.cts +10 -0
  52. package/dist/path-or.d.ts +10 -0
  53. package/dist/pick-by.d.cts +3 -4
  54. package/dist/pick-by.d.ts +3 -4
  55. package/dist/pick.cjs +1 -1
  56. package/dist/pick.d.cts +3 -4
  57. package/dist/pick.d.ts +3 -4
  58. package/dist/pick.js +1 -1
  59. package/dist/prop.cjs +1 -1
  60. package/dist/prop.d.cts +118 -13
  61. package/dist/prop.d.ts +118 -13
  62. package/dist/prop.js +1 -1
  63. package/dist/pull-object.d.cts +2 -3
  64. package/dist/pull-object.d.ts +2 -3
  65. package/dist/sample.cjs +1 -1
  66. package/dist/sample.d.cts +32 -8
  67. package/dist/sample.d.ts +32 -8
  68. package/dist/sample.js +1 -1
  69. package/dist/string-to-path.d.cts +2 -3
  70. package/dist/string-to-path.d.ts +2 -3
  71. package/package.json +6 -6
  72. package/dist/chunk-2MHE6M7V.cjs +0 -1
  73. package/dist/chunk-NEIICTWC.js +0 -1
  74. package/dist/chunk-SOPOELNU.cjs +0 -1
  75. package/dist/chunk-XEAAXO7F.js +0 -1
  76. package/dist/if-D4QIikQ1.d.cts +0 -5
  77. package/dist/if-D4QIikQ1.d.ts +0 -5
  78. /package/dist/{chunk-P7RCAO7P.cjs → chunk-I5B54QDJ.cjs} +0 -0
  79. /package/dist/{chunk-Z23BZCCD.js → chunk-VVGDSDKI.js} +0 -0
package/dist/sample.d.ts 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.js';
1
3
  import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
4
+ import { N as NTuple } from './n-tuple-5jljrt4c.js';
5
+ import { P as PartialArray } from './partial-array-Vnf1fBtl.js';
6
+ import { T as TupleParts } from './tuple-parts-BTivqbtT.js';
7
+ import './perkakas-type-error-8wPb8T2y.js';
2
8
 
3
- type Sampled<T extends IterableContainer, N extends number> = number extends N ? SampledGeneric<T> : undefined extends T[N] ? T : SampledLiteral<T, N>;
4
- type SampledGeneric<T extends IterableContainer> = T[number] extends never ? T : T extends readonly [infer First, ...infer Rest] ? [First, ...SampledGeneric<Rest>] | SampledGeneric<Rest> : Array<T[number]>;
5
- type SampledLiteral<T extends IterableContainer, N extends number, Iteration extends Array<unknown> = []> = Iteration['length'] extends N ? [] : T extends readonly [infer First, ...infer Tail] ? [
6
- First | Tail[number],
7
- ...SampledLiteral<Tail, N, [unknown, ...Iteration]>
8
- ] : T extends readonly [...infer Head, infer Last] ? [...SampledLiteral<Head, N, [unknown, ...Iteration]>, Last] : [T[number], ...SampledLiteral<T, N, [unknown, ...Iteration]>] | SampledLiteral<T, N, [unknown, ...Iteration]>;
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 };
package/dist/sample.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-XEAAXO7F.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";import"./chunk-EK7ODJWE.js";export{a as sample};
1
+ import{a}from"./chunk-4Y6VRHEP.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";import"./chunk-EK7ODJWE.js";export{a as sample};
@@ -1,13 +1,12 @@
1
1
  import { IsStringLiteral, IsNumericLiteral } from 'type-fest';
2
- import { I as If } from './if-D4QIikQ1.cjs';
3
2
 
4
- type StringToPath<S> = If<IsStringLiteral<S>, StringToPathImpl<S>, Array<string | number>>;
3
+ type StringToPath<S> = IsStringLiteral<S> extends true ? StringToPathImpl<S> : Array<string | number>;
5
4
  type StringToPathImpl<S> = S extends `${infer Head}['${infer Quoted}']${infer Tail}` ? [...StringToPath<Head>, Quoted, ...StringToPath<Tail>] : S extends `${infer Head}["${infer DoubleQuoted}"]${infer Tail}` ? [...StringToPath<Head>, DoubleQuoted, ...StringToPath<Tail>] : S extends `${infer Head}[${infer Unquoted}]${infer Tail}` ? [
6
5
  ...StringToPath<Head>,
7
6
  ...StringToPath<Unquoted>,
8
7
  ...StringToPath<Tail>
9
8
  ] : S extends `${infer Head}.${infer Tail}` ? [...StringToPath<Head>, ...StringToPath<Tail>] : '' extends S ? [] : S extends `${infer N extends number}` ? [
10
- If<IsNumericLiteral<N>, N, S>
9
+ IsNumericLiteral<N> extends true ? N : S
11
10
  ] : [S];
12
11
  /**
13
12
  * A utility to allow JSONPath-like strings to be used in other utilities which
@@ -1,13 +1,12 @@
1
1
  import { IsStringLiteral, IsNumericLiteral } from 'type-fest';
2
- import { I as If } from './if-D4QIikQ1.js';
3
2
 
4
- type StringToPath<S> = If<IsStringLiteral<S>, StringToPathImpl<S>, Array<string | number>>;
3
+ type StringToPath<S> = IsStringLiteral<S> extends true ? StringToPathImpl<S> : Array<string | number>;
5
4
  type StringToPathImpl<S> = S extends `${infer Head}['${infer Quoted}']${infer Tail}` ? [...StringToPath<Head>, Quoted, ...StringToPath<Tail>] : S extends `${infer Head}["${infer DoubleQuoted}"]${infer Tail}` ? [...StringToPath<Head>, DoubleQuoted, ...StringToPath<Tail>] : S extends `${infer Head}[${infer Unquoted}]${infer Tail}` ? [
6
5
  ...StringToPath<Head>,
7
6
  ...StringToPath<Unquoted>,
8
7
  ...StringToPath<Tail>
9
8
  ] : S extends `${infer Head}.${infer Tail}` ? [...StringToPath<Head>, ...StringToPath<Tail>] : '' extends S ? [] : S extends `${infer N extends number}` ? [
10
- If<IsNumericLiteral<N>, N, S>
9
+ IsNumericLiteral<N> extends true ? N : S
11
10
  ] : [S];
12
11
  /**
13
12
  * A utility to allow JSONPath-like strings to be used in other utilities which
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vinicunca/perkakas",
3
3
  "type": "module",
4
- "version": "1.7.0",
4
+ "version": "1.7.1",
5
5
  "description": "Utility for JavaScript and Typescript.",
6
6
  "author": "praburangki<https://github.com/praburangki>",
7
7
  "license": "MIT",
@@ -40,15 +40,15 @@
40
40
  "type-fest": "^4.41.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/node": "^22.16.5",
44
- "@vinicunca/eslint-config": "^3.18.0",
43
+ "@types/node": "^22.17.0",
44
+ "@vinicunca/eslint-config": "^3.20.0",
45
45
  "@vitest/coverage-v8": "^3.2.4",
46
- "bumpp": "^10.2.0",
47
- "eslint": "^9.31.0",
46
+ "bumpp": "^10.2.2",
47
+ "eslint": "^9.32.0",
48
48
  "prettier": "^3.6.2",
49
49
  "taze": "^19.1.0",
50
50
  "tsup": "^8.5.0",
51
- "typescript": "^5.8.3",
51
+ "typescript": "^5.9.2",
52
52
  "vitest": "^3.2.4"
53
53
  },
54
54
  "scripts": {
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkXR72I63Wcjs = require('./chunk-XR72I63W.cjs');function m(...e){return _chunkXR72I63Wcjs.a.call(void 0, o,e)}function o(e,r){if(r<=0)return[];if(r>=e.length)return[...e];let i=Math.min(r,e.length-r),t=new Set;for(;t.size<i;){let n=Math.floor(Math.random()*e.length);t.add(n)}return r===i?[...t].sort((n,a)=>n-a).map(n=>e[n]):e.filter((n,a)=>!t.has(a))}exports.a = m;
@@ -1 +0,0 @@
1
- import{a as n}from"./chunk-J6WPJH72.js";function p(...e){return n(t,e)}function t(e,o){return e[o]}export{p as a,t as b};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkXR72I63Wcjs = require('./chunk-XR72I63W.cjs');function p(...e){return _chunkXR72I63Wcjs.a.call(void 0, t,e)}function t(e,o){return e[o]}exports.a = p; exports.b = t;
@@ -1 +0,0 @@
1
- import{a as l}from"./chunk-J6WPJH72.js";function m(...e){return l(o,e)}function o(e,r){if(r<=0)return[];if(r>=e.length)return[...e];let i=Math.min(r,e.length-r),t=new Set;for(;t.size<i;){let n=Math.floor(Math.random()*e.length);t.add(n)}return r===i?[...t].sort((n,a)=>n-a).map(n=>e[n]):e.filter((n,a)=>!t.has(a))}export{m as a};
@@ -1,5 +0,0 @@
1
- import { IsNever } from 'type-fest';
2
-
3
- type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
4
-
5
- export type { If as I };
@@ -1,5 +0,0 @@
1
- import { IsNever } from 'type-fest';
2
-
3
- type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
4
-
5
- export type { If as I };
File without changes
File without changes