@vinicunca/perkakas 1.0.0 → 1.0.2

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 (189) hide show
  1. package/dist/add-prop.d.cts +5 -9
  2. package/dist/add-prop.d.ts +5 -9
  3. package/dist/chunk-2T576V7A.js +1 -0
  4. package/dist/chunk-5NG5PDAH.js +1 -0
  5. package/dist/{chunk-4PHYW76J.cjs → chunk-64KL2FA2.cjs} +1 -1
  6. package/dist/chunk-6TRXWRYJ.cjs +1 -0
  7. package/dist/chunk-CIZWCFSY.cjs +1 -0
  8. package/dist/chunk-E6JSDI5S.cjs +1 -0
  9. package/dist/chunk-EBS4GCKX.js +1 -0
  10. package/dist/{chunk-WN5RHRS6.cjs → chunk-GUZPDGVH.cjs} +1 -1
  11. package/dist/chunk-GXVKH5OX.cjs +1 -0
  12. package/dist/chunk-H2E5GCCP.js +1 -0
  13. package/dist/chunk-KG2TAX4E.js +1 -0
  14. package/dist/chunk-LWPEZ7RI.js +1 -0
  15. package/dist/chunk-MKM3UJUV.js +1 -0
  16. package/dist/chunk-R3TYGYBQ.cjs +1 -0
  17. package/dist/chunk-RBODUO3Q.js +1 -0
  18. package/dist/chunk-T2LJNGWI.js +1 -0
  19. package/dist/chunk-TFN3JWPS.cjs +1 -0
  20. package/dist/chunk-TKJ7YEHS.cjs +1 -0
  21. package/dist/chunk-TT2VLICK.js +1 -0
  22. package/dist/chunk-UHUFGDIS.cjs +1 -0
  23. package/dist/chunk-VEG55EJ6.cjs +1 -0
  24. package/dist/chunk-XXU2FTTA.cjs +1 -0
  25. package/dist/chunk-ZIF7K2PC.js +1 -0
  26. package/dist/chunk-ZSI3ZTMX.js +1 -0
  27. package/dist/chunk.d.cts +1 -1
  28. package/dist/chunk.d.ts +1 -1
  29. package/dist/concat.d.cts +1 -1
  30. package/dist/concat.d.ts +1 -1
  31. package/dist/conditional.cjs +1 -1
  32. package/dist/conditional.d.cts +6 -6
  33. package/dist/conditional.d.ts +6 -6
  34. package/dist/conditional.js +1 -1
  35. package/dist/drop-first-by.d.cts +1 -1
  36. package/dist/drop-first-by.d.ts +1 -1
  37. package/dist/evolve.d.cts +1 -1
  38. package/dist/evolve.d.ts +1 -1
  39. package/dist/first-by.d.cts +1 -1
  40. package/dist/first-by.d.ts +1 -1
  41. package/dist/first.d.cts +1 -1
  42. package/dist/first.d.ts +1 -1
  43. package/dist/flat.d.cts +1 -1
  44. package/dist/flat.d.ts +1 -1
  45. package/dist/for-each-obj.d.cts +1 -1
  46. package/dist/for-each-obj.d.ts +1 -1
  47. package/dist/for-each.cjs +1 -1
  48. package/dist/for-each.d.cts +5 -2
  49. package/dist/for-each.d.ts +5 -2
  50. package/dist/for-each.js +1 -1
  51. package/dist/from-entries.d.cts +5 -5
  52. package/dist/from-entries.d.ts +5 -5
  53. package/dist/from-keys.cjs +1 -1
  54. package/dist/from-keys.d.cts +2 -2
  55. package/dist/from-keys.d.ts +2 -2
  56. package/dist/from-keys.js +1 -1
  57. package/dist/group-by.d.cts +1 -1
  58. package/dist/group-by.d.ts +1 -1
  59. package/dist/has-at-least.d.cts +1 -1
  60. package/dist/has-at-least.d.ts +1 -1
  61. package/dist/has-sub-object.cjs +1 -1
  62. package/dist/has-sub-object.d.cts +18 -3
  63. package/dist/has-sub-object.d.ts +18 -3
  64. package/dist/has-sub-object.js +1 -1
  65. package/dist/human-readable-file-size.d.cts +3 -5
  66. package/dist/human-readable-file-size.d.ts +3 -5
  67. package/dist/index-by.d.cts +1 -1
  68. package/dist/index-by.d.ts +1 -1
  69. package/dist/index.cjs +1 -1
  70. package/dist/index.d.cts +2 -1
  71. package/dist/index.d.ts +2 -1
  72. package/dist/index.js +1 -1
  73. package/dist/is-array.d.cts +1 -1
  74. package/dist/is-array.d.ts +1 -1
  75. package/dist/is-big-int.d.cts +1 -1
  76. package/dist/is-big-int.d.ts +1 -1
  77. package/dist/is-boolean.d.cts +1 -1
  78. package/dist/is-boolean.d.ts +1 -1
  79. package/dist/is-empty.d.cts +1 -1
  80. package/dist/is-empty.d.ts +1 -1
  81. package/dist/is-included-in.d.cts +1 -1
  82. package/dist/is-included-in.d.ts +1 -1
  83. package/dist/is-nullish.d.cts +1 -1
  84. package/dist/is-nullish.d.ts +1 -1
  85. package/dist/is-number.d.cts +1 -1
  86. package/dist/is-number.d.ts +1 -1
  87. package/dist/is-object-type.cjs +1 -1
  88. package/dist/is-object-type.d.cts +6 -4
  89. package/dist/is-object-type.d.ts +6 -4
  90. package/dist/is-object-type.js +1 -1
  91. package/dist/is-plain-object.d.cts +1 -1
  92. package/dist/is-plain-object.d.ts +1 -1
  93. package/dist/is-string.d.cts +1 -1
  94. package/dist/is-string.d.ts +1 -1
  95. package/dist/is-symbol.d.cts +1 -1
  96. package/dist/is-symbol.d.ts +1 -1
  97. package/dist/keys.d.cts +1 -1
  98. package/dist/keys.d.ts +1 -1
  99. package/dist/last.d.cts +1 -1
  100. package/dist/last.d.ts +1 -1
  101. package/dist/map-keys.cjs +1 -1
  102. package/dist/map-keys.d.cts +3 -3
  103. package/dist/map-keys.d.ts +3 -3
  104. package/dist/map-keys.js +1 -1
  105. package/dist/map-values.d.cts +1 -1
  106. package/dist/map-values.d.ts +1 -1
  107. package/dist/map-with-feedback.d.cts +1 -1
  108. package/dist/map-with-feedback.d.ts +1 -1
  109. package/dist/map.d.cts +1 -1
  110. package/dist/map.d.ts +1 -1
  111. package/dist/nth-by.d.cts +1 -1
  112. package/dist/nth-by.d.ts +1 -1
  113. package/dist/omit-by.cjs +1 -1
  114. package/dist/omit-by.d.cts +3 -3
  115. package/dist/omit-by.d.ts +3 -3
  116. package/dist/omit-by.js +1 -1
  117. package/dist/only.d.cts +1 -1
  118. package/dist/only.d.ts +1 -1
  119. package/dist/pick-by.cjs +1 -1
  120. package/dist/pick-by.d.cts +3 -3
  121. package/dist/pick-by.d.ts +3 -3
  122. package/dist/pick-by.js +1 -1
  123. package/dist/product.cjs +1 -1
  124. package/dist/product.d.cts +22 -5
  125. package/dist/product.d.ts +22 -5
  126. package/dist/product.js +1 -1
  127. package/dist/pull-object.cjs +1 -1
  128. package/dist/pull-object.d.cts +3 -3
  129. package/dist/pull-object.d.ts +3 -3
  130. package/dist/pull-object.js +1 -1
  131. package/dist/rank-by.d.cts +1 -1
  132. package/dist/rank-by.d.ts +1 -1
  133. package/dist/sample.d.cts +1 -1
  134. package/dist/sample.d.ts +1 -1
  135. package/dist/set.d.cts +1 -1
  136. package/dist/set.d.ts +1 -1
  137. package/dist/sleep.d.cts +3 -4
  138. package/dist/sleep.d.ts +3 -4
  139. package/dist/slugify.d.cts +3 -5
  140. package/dist/slugify.d.ts +3 -5
  141. package/dist/sort-by.d.cts +1 -1
  142. package/dist/sort-by.d.ts +1 -1
  143. package/dist/sort.d.cts +1 -1
  144. package/dist/sort.d.ts +1 -1
  145. package/dist/split.cjs +1 -0
  146. package/dist/split.d.cts +60 -0
  147. package/dist/split.d.ts +60 -0
  148. package/dist/split.js +1 -0
  149. package/dist/string-to-path.d.cts +5 -2
  150. package/dist/string-to-path.d.ts +5 -2
  151. package/dist/sum.cjs +1 -1
  152. package/dist/sum.d.cts +22 -5
  153. package/dist/sum.d.ts +22 -5
  154. package/dist/sum.js +1 -1
  155. package/dist/swap-indices.d.cts +1 -1
  156. package/dist/swap-indices.d.ts +1 -1
  157. package/dist/take-first-by.d.cts +1 -1
  158. package/dist/take-first-by.d.ts +1 -1
  159. package/dist/times.d.cts +13 -4
  160. package/dist/times.d.ts +13 -4
  161. package/dist/{types-DCY4LHuA.d.cts → types-BMu1PIvo.d.cts} +41 -28
  162. package/dist/{types-DCY4LHuA.d.ts → types-BMu1PIvo.d.ts} +41 -28
  163. package/dist/values.d.cts +1 -1
  164. package/dist/values.d.ts +1 -1
  165. package/dist/zip-with.d.cts +1 -1
  166. package/dist/zip-with.d.ts +1 -1
  167. package/dist/zip.d.cts +1 -1
  168. package/dist/zip.d.ts +1 -1
  169. package/package.json +1 -1
  170. package/dist/chunk-2G3P6PPR.js +0 -1
  171. package/dist/chunk-2SALTIYD.js +0 -1
  172. package/dist/chunk-5OVP2TQW.js +0 -1
  173. package/dist/chunk-67PSL457.cjs +0 -1
  174. package/dist/chunk-6LV46ASN.cjs +0 -1
  175. package/dist/chunk-6SQ2YEMB.js +0 -1
  176. package/dist/chunk-775ZQ6M4.js +0 -1
  177. package/dist/chunk-BH4FVL5M.js +0 -1
  178. package/dist/chunk-DQPVQH4H.cjs +0 -1
  179. package/dist/chunk-EIHJRQSP.js +0 -1
  180. package/dist/chunk-I237OF5R.cjs +0 -1
  181. package/dist/chunk-IF5LD7K5.js +0 -1
  182. package/dist/chunk-LNPZR2QM.cjs +0 -1
  183. package/dist/chunk-S2HXZ3NZ.cjs +0 -1
  184. package/dist/chunk-T43Q6JL2.js +0 -1
  185. package/dist/chunk-TUUS6PD5.cjs +0 -1
  186. package/dist/chunk-U5RGUZNM.js +0 -1
  187. package/dist/chunk-VD6VNORF.cjs +0 -1
  188. package/dist/chunk-YZNFAANS.cjs +0 -1
  189. package/dist/chunk-Z6SSEPER.js +0 -1
package/dist/sum.d.cts CHANGED
@@ -1,32 +1,49 @@
1
- import { N as NonEmptyArray } from './types-DCY4LHuA.cjs';
1
+ import { I as IterableContainer } from './types-BMu1PIvo.cjs';
2
2
  import 'type-fest';
3
3
 
4
+ type Sum<T extends IterableContainer<bigint> | IterableContainer<number>> = T extends readonly [] ? 0 : T extends readonly [bigint, ...ReadonlyArray<unknown>] ? bigint : T[number] extends bigint ? 0 | bigint : number;
4
5
  /**
5
6
  * Sums the numbers in the array, or return 0 for an empty array.
6
7
  *
8
+ * Works for both `number` and `bigint` arrays, but not arrays that contain both
9
+ * types.
10
+ *
11
+ * IMPORTANT: The result for empty arrays would be 0 (`number`) regardless of
12
+ * the type of the array; to avoid adding this to the return type for cases
13
+ * where the array is known to be non-empty you can use `hasAtLeast` or
14
+ * `isEmpty` to guard against this case.
15
+ *
7
16
  * @param data - The array of numbers.
8
17
  * @signature
9
18
  * P.sum(data);
10
19
  * @example
11
20
  * P.sum([1, 2, 3]); // => 6
21
+ * P.sum([1n, 2n, 3n]); // => 6n
12
22
  * P.sum([]); // => 0
13
23
  * @dataFirst
14
24
  * @category Number
15
25
  */
16
- declare function sum(data: ReadonlyArray<number>): number;
17
- declare function sum(data: Readonly<NonEmptyArray<bigint>>): bigint;
26
+ declare function sum<T extends IterableContainer<bigint> | IterableContainer<number>>(data: T): Sum<T>;
18
27
  /**
19
28
  * Sums the numbers in the array, or return 0 for an empty array.
20
29
  *
30
+ * Works for both `number` and `bigint` arrays, but not arrays that contain both
31
+ * types.
32
+ *
33
+ * IMPORTANT: The result for empty arrays would be 0 (`number`) regardless of
34
+ * the type of the array; to avoid adding this to the return type for cases
35
+ * where the array is known to be non-empty you can use `hasAtLeast` or
36
+ * `isEmpty`to guard against this case.
37
+ *
21
38
  * @signature
22
39
  * P.sum()(data);
23
40
  * @example
24
41
  * P.pipe([1, 2, 3], P.sum()); // => 6
42
+ * P.pipe([1n, 2n, 3n], R.sum()); // => 6n
25
43
  * P.pipe([], P.sum()); // => 0
26
44
  * @dataLast
27
45
  * @category Number
28
46
  */
29
- declare function sum(): (data: ReadonlyArray<number>) => number;
30
- declare function sum(): (data: Readonly<NonEmptyArray<bigint>>) => bigint;
47
+ declare function sum(): <T extends IterableContainer<bigint> | IterableContainer<number>>(data: T) => Sum<T>;
31
48
 
32
49
  export { sum };
package/dist/sum.d.ts CHANGED
@@ -1,32 +1,49 @@
1
- import { N as NonEmptyArray } from './types-DCY4LHuA.js';
1
+ import { I as IterableContainer } from './types-BMu1PIvo.js';
2
2
  import 'type-fest';
3
3
 
4
+ type Sum<T extends IterableContainer<bigint> | IterableContainer<number>> = T extends readonly [] ? 0 : T extends readonly [bigint, ...ReadonlyArray<unknown>] ? bigint : T[number] extends bigint ? 0 | bigint : number;
4
5
  /**
5
6
  * Sums the numbers in the array, or return 0 for an empty array.
6
7
  *
8
+ * Works for both `number` and `bigint` arrays, but not arrays that contain both
9
+ * types.
10
+ *
11
+ * IMPORTANT: The result for empty arrays would be 0 (`number`) regardless of
12
+ * the type of the array; to avoid adding this to the return type for cases
13
+ * where the array is known to be non-empty you can use `hasAtLeast` or
14
+ * `isEmpty` to guard against this case.
15
+ *
7
16
  * @param data - The array of numbers.
8
17
  * @signature
9
18
  * P.sum(data);
10
19
  * @example
11
20
  * P.sum([1, 2, 3]); // => 6
21
+ * P.sum([1n, 2n, 3n]); // => 6n
12
22
  * P.sum([]); // => 0
13
23
  * @dataFirst
14
24
  * @category Number
15
25
  */
16
- declare function sum(data: ReadonlyArray<number>): number;
17
- declare function sum(data: Readonly<NonEmptyArray<bigint>>): bigint;
26
+ declare function sum<T extends IterableContainer<bigint> | IterableContainer<number>>(data: T): Sum<T>;
18
27
  /**
19
28
  * Sums the numbers in the array, or return 0 for an empty array.
20
29
  *
30
+ * Works for both `number` and `bigint` arrays, but not arrays that contain both
31
+ * types.
32
+ *
33
+ * IMPORTANT: The result for empty arrays would be 0 (`number`) regardless of
34
+ * the type of the array; to avoid adding this to the return type for cases
35
+ * where the array is known to be non-empty you can use `hasAtLeast` or
36
+ * `isEmpty`to guard against this case.
37
+ *
21
38
  * @signature
22
39
  * P.sum()(data);
23
40
  * @example
24
41
  * P.pipe([1, 2, 3], P.sum()); // => 6
42
+ * P.pipe([1n, 2n, 3n], R.sum()); // => 6n
25
43
  * P.pipe([], P.sum()); // => 0
26
44
  * @dataLast
27
45
  * @category Number
28
46
  */
29
- declare function sum(): (data: ReadonlyArray<number>) => number;
30
- declare function sum(): (data: Readonly<NonEmptyArray<bigint>>) => bigint;
47
+ declare function sum(): <T extends IterableContainer<bigint> | IterableContainer<number>>(data: T) => Sum<T>;
31
48
 
32
49
  export { sum };
package/dist/sum.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-U5RGUZNM.js";import"./chunk-JFXZ246Y.js";import"./chunk-KQGY2DBY.js";export{a as sum};
1
+ import{a}from"./chunk-2T576V7A.js";import"./chunk-JFXZ246Y.js";import"./chunk-KQGY2DBY.js";export{a as sum};
@@ -1,5 +1,5 @@
1
1
  import { Join } from 'type-fest';
2
- import { I as IterableContainer } from './types-DCY4LHuA.cjs';
2
+ import { I as IterableContainer } from './types-BMu1PIvo.cjs';
3
3
 
4
4
  /**
5
5
  * @see https://github.com/sindresorhus/type-fest/blob/main/source/is-equal.d.ts
@@ -1,5 +1,5 @@
1
1
  import { Join } from 'type-fest';
2
- import { I as IterableContainer } from './types-DCY4LHuA.js';
2
+ import { I as IterableContainer } from './types-BMu1PIvo.js';
3
3
 
4
4
  /**
5
5
  * @see https://github.com/sindresorhus/type-fest/blob/main/source/is-equal.d.ts
@@ -1,4 +1,4 @@
1
- import { N as NonEmptyArray } from './types-DCY4LHuA.cjs';
1
+ import { N as NonEmptyArray } from './types-BMu1PIvo.cjs';
2
2
  import { O as OrderRule } from './curry-order-rules-BOMf1JS7.cjs';
3
3
  import 'type-fest';
4
4
 
@@ -1,4 +1,4 @@
1
- import { N as NonEmptyArray } from './types-DCY4LHuA.js';
1
+ import { N as NonEmptyArray } from './types-BMu1PIvo.js';
2
2
  import { O as OrderRule } from './curry-order-rules-BOMf1JS7.js';
3
3
  import 'type-fest';
4
4
 
package/dist/times.d.cts CHANGED
@@ -7,9 +7,13 @@
7
7
  *
8
8
  * @param count - A value between `0` and `n - 1`. Increments after each function call.
9
9
  * @param fn - The function to invoke. Passed one argument, the current value of `n`.
10
- * @returns An array containing the return values of all calls to `fn`.
11
- * @example times(5, identity()); //=> [0, 1, 2, 3, 4]
10
+ * @signature
11
+ * P.times(count, fn)
12
+ * @example
13
+ * P.times(5, identity()); //=> [0, 1, 2, 3, 4]
14
+ *
12
15
  * @dataFirst
16
+ * @category Array
13
17
  */
14
18
  declare function times<T>(count: number, fn: (n: number) => T): Array<T>;
15
19
  /**
@@ -20,9 +24,14 @@ declare function times<T>(count: number, fn: (n: number) => T): Array<T>;
20
24
  * and is gradually incremented to `n - 1`.
21
25
  *
22
26
  * @param fn - The function to invoke. Passed one argument, the current value of `n`.
23
- * @returns An array containing the return values of all calls to `fn`.
24
- * @example times(identity())(5); //=> [0, 1, 2, 3, 4]
27
+ *
28
+ * @signature
29
+ * P.times(count, fn)
30
+ * @example
31
+ * P.times(identity())(5); //=> [0, 1, 2, 3, 4]
32
+ *
25
33
  * @dataLast
34
+ * @category Array
26
35
  */
27
36
  declare function times<T>(fn: (n: number) => T): (count: number) => Array<T>;
28
37
 
package/dist/times.d.ts CHANGED
@@ -7,9 +7,13 @@
7
7
  *
8
8
  * @param count - A value between `0` and `n - 1`. Increments after each function call.
9
9
  * @param fn - The function to invoke. Passed one argument, the current value of `n`.
10
- * @returns An array containing the return values of all calls to `fn`.
11
- * @example times(5, identity()); //=> [0, 1, 2, 3, 4]
10
+ * @signature
11
+ * P.times(count, fn)
12
+ * @example
13
+ * P.times(5, identity()); //=> [0, 1, 2, 3, 4]
14
+ *
12
15
  * @dataFirst
16
+ * @category Array
13
17
  */
14
18
  declare function times<T>(count: number, fn: (n: number) => T): Array<T>;
15
19
  /**
@@ -20,9 +24,14 @@ declare function times<T>(count: number, fn: (n: number) => T): Array<T>;
20
24
  * and is gradually incremented to `n - 1`.
21
25
  *
22
26
  * @param fn - The function to invoke. Passed one argument, the current value of `n`.
23
- * @returns An array containing the return values of all calls to `fn`.
24
- * @example times(identity())(5); //=> [0, 1, 2, 3, 4]
27
+ *
28
+ * @signature
29
+ * P.times(count, fn)
30
+ * @example
31
+ * P.times(identity())(5); //=> [0, 1, 2, 3, 4]
32
+ *
25
33
  * @dataLast
34
+ * @category Array
26
35
  */
27
36
  declare function times<T>(fn: (n: number) => T): (count: number) => Array<T>;
28
37
 
@@ -1,4 +1,4 @@
1
- import { IsAny, Simplify, IsLiteral, IsNever } from 'type-fest';
1
+ import { EmptyObject, IsAny, Simplify, IsLiteral, IsNever, KeysOfUnion, IsStringLiteral, IsNumericLiteral, IsSymbolLiteral, Split } from 'type-fest';
2
2
 
3
3
  declare const __brand: unique symbol;
4
4
  type Branded<T, Brand extends symbol> = T & {
@@ -21,12 +21,30 @@ type Mapped<T extends IterableContainer, K> = {
21
21
  */
22
22
  type IterableContainer<T = unknown> = ReadonlyArray<T> | readonly [];
23
23
  /**
24
- * Define a Simple record as one that doesn't define it's properties beyond
25
- * their general type. This is the case for string and number keys (and their
26
- * combination). Another way of thinking about simple records is that the number
27
- * of properties are unbound (they can be empty, or they can have 1000 props).
24
+ * Check if a type is guaranteed to be a bounded record: a record with a finite
25
+ * set of keys.
26
+ *
27
+ * @example
28
+ * IfBoundedRecord<{ a: 1, 1: "a" }>; //=> true
29
+ * IfBoundedRecord<Record<string | number, unknown>>; //=> false
30
+ * IfBoundedRecord<Record<`prefix_${number}`, unknown>>; //=> false
31
+ */
32
+ type IfBoundedRecord<T, TypeIfBoundedRecord = true, TypeIfUnboundedRecord = false> = IsBoundedKey<KeysOfUnion<T>> extends true ? TypeIfBoundedRecord : TypeIfUnboundedRecord;
33
+ /**
34
+ * Checks if a type is a bounded key: a union of bounded strings, numeric
35
+ * literals, or symbol literals.
36
+ */
37
+ type IsBoundedKey<T> = T extends unknown ? IsStringLiteral<T> extends true ? IsBoundedString<T> : IsNumericLiteral<T> extends true ? true : IsSymbolLiteral<T> : never;
38
+ /**
39
+ * Checks if a type is a bounded string: a type that only has a finite
40
+ * number of strings that are that type.
41
+ *
42
+ * Most relevant for template literals: IsBoundedString<`${1 | 2}_${3 | 4}`> is
43
+ * true, and IsBoundedString<`${1 | 2}_${number}`> is false.
28
44
  */
29
- type IfSimpleRecord<T, TypeIfSimpleRecord = true, TypeIfNotSimpleRecord = false> = string extends keyof T ? TypeIfSimpleRecord : number extends keyof T ? TypeIfSimpleRecord : number | string extends keyof T ? TypeIfSimpleRecord : TypeIfNotSimpleRecord;
45
+ type IsBoundedString<T> = T extends string ? Split<T, ''>[number] extends infer U ? [
46
+ `${number}`
47
+ ] extends [U] ? false : [string] extends [U] ? false : true : false : false;
30
48
  /**
31
49
  * A union of all keys of T which are not symbols, and where number keys are
32
50
  * converted to strings, following the definition of `Object.keys` and
@@ -36,14 +54,18 @@ type IfSimpleRecord<T, TypeIfSimpleRecord = true, TypeIfNotSimpleRecord = false>
36
54
  *
37
55
  * @see EnumerableStringKeyedValueOf
38
56
  */
39
- type EnumerableStringKeyOf<T> = `${Exclude<keyof T, symbol>}`;
57
+ type EnumerableStringKeyOf<T> = Required<T> extends Record<infer K, unknown> ? `${Exclude<K, symbol>}` : never;
40
58
  /**
41
59
  * A union of all values of properties in T which are not keyed by a symbol,
42
60
  * following the definition of `Object.values` and `Object.entries`.
43
61
  */
44
- type EnumerableStringKeyedValueOf<T> = {
62
+ type EnumerableStringKeyedValueOf<T> = ValuesOf<{
45
63
  [K in keyof T]-?: K extends symbol ? never : T[K];
46
- }[keyof T];
64
+ }>;
65
+ /**
66
+ * Extracts the value type from an object type T.
67
+ */
68
+ type ValuesOf<T> = T extends EmptyObject ? T[keyof T] : T extends Record<PropertyKey, infer V> ? V : never;
47
69
  /**
48
70
  * This is the type you'd get from doing:
49
71
  * `Object.fromEntries(Object.entries(x))`.
@@ -57,24 +79,7 @@ type ReconstructedRecord<T> = Record<EnumerableStringKeyOf<T>, EnumerableStringK
57
79
  * function isMyType<T>(data: T | MyType): data is NarrowedTo<T, MyType> { ... }
58
80
  */
59
81
  type NarrowedTo<T, Base> = Extract<T, Base> extends never ? Base : IsAny<T> extends true ? Base : Extract<T, Base>;
60
- /**
61
- * Records keyed with generic `string` and `number`
62
- * have different semantics to those with a a union of literal values
63
- * (e.g. 'cat' | 'dog') when using 'noUncheckedIndexedAccess',
64
- * the former being implicitly `Partial` whereas the latter are implicitly `Required`.
65
- */
66
- type ExactRecord<Key extends PropertyKey, Value> = IfSimpleRecord<Record<Key, Value>,
67
- /**
68
- * If either string or number extend Key it means that Key is at least as wide as them,
69
- * so we don't need to wrap the returned record with Partial.
70
- */
71
- Record<Key, Value>,
72
- /**
73
- * If the key is specific, e.g. 'cat' | 'dog', the result is partial
74
- * because we can't statically know what values the mapper would return on
75
- * a specific input.
76
- */
77
- Partial<Record<Key, Value>>>;
82
+ type ExactRecord<Key extends PropertyKey, Value> = IfBoundedRecord<Record<Key, Value>, Partial<Record<Key, Value>>, Record<Key, Value>>;
78
83
  type ReorderedArray<T extends IterableContainer> = {
79
84
  -readonly [P in keyof T]: T[number];
80
85
  };
@@ -98,5 +103,13 @@ type IsSingleLiteral<K> = IsLiteral<K> extends true ? (IsUnion<K> extends true ?
98
103
  */
99
104
  type IsUnion<T> = InternalIsUnion<T>;
100
105
  type InternalIsUnion<T, U = T> = (IsNever<T> extends true ? false : T extends any ? [U] extends [T] ? false : true : never) extends infer Result ? boolean extends Result ? true : Result : never;
106
+ /**
107
+ * Extracts a type predicate from a type guard function for the first argument.
108
+ *
109
+ * @example
110
+ * type TypeGuardFn = (x: unknown) => x is string;
111
+ * type Result = GuardType<TypeGuardFn>; // `string`
112
+ */
113
+ type GuardType<T, Fallback = never> = T extends (x: any, ...rest: any) => x is infer U ? U : Fallback;
101
114
 
102
- export type { Branded as B, EnumerableStringKeyedValueOf as E, IterableContainer as I, Mapped as M, NonEmptyArray as N, ReconstructedRecord as R, UpsertProp as U, EnumerableStringKeyOf as a, ExactRecord as b, NarrowedTo as c, IsUnion as d, IfSimpleRecord as e, ReorderedArray as f };
115
+ export type { Branded as B, EnumerableStringKeyedValueOf as E, GuardType as G, IterableContainer as I, Mapped as M, NonEmptyArray as N, ReconstructedRecord as R, UpsertProp as U, EnumerableStringKeyOf as a, ExactRecord as b, NarrowedTo as c, IsUnion as d, IfBoundedRecord as e, ReorderedArray as f };
@@ -1,4 +1,4 @@
1
- import { IsAny, Simplify, IsLiteral, IsNever } from 'type-fest';
1
+ import { EmptyObject, IsAny, Simplify, IsLiteral, IsNever, KeysOfUnion, IsStringLiteral, IsNumericLiteral, IsSymbolLiteral, Split } from 'type-fest';
2
2
 
3
3
  declare const __brand: unique symbol;
4
4
  type Branded<T, Brand extends symbol> = T & {
@@ -21,12 +21,30 @@ type Mapped<T extends IterableContainer, K> = {
21
21
  */
22
22
  type IterableContainer<T = unknown> = ReadonlyArray<T> | readonly [];
23
23
  /**
24
- * Define a Simple record as one that doesn't define it's properties beyond
25
- * their general type. This is the case for string and number keys (and their
26
- * combination). Another way of thinking about simple records is that the number
27
- * of properties are unbound (they can be empty, or they can have 1000 props).
24
+ * Check if a type is guaranteed to be a bounded record: a record with a finite
25
+ * set of keys.
26
+ *
27
+ * @example
28
+ * IfBoundedRecord<{ a: 1, 1: "a" }>; //=> true
29
+ * IfBoundedRecord<Record<string | number, unknown>>; //=> false
30
+ * IfBoundedRecord<Record<`prefix_${number}`, unknown>>; //=> false
31
+ */
32
+ type IfBoundedRecord<T, TypeIfBoundedRecord = true, TypeIfUnboundedRecord = false> = IsBoundedKey<KeysOfUnion<T>> extends true ? TypeIfBoundedRecord : TypeIfUnboundedRecord;
33
+ /**
34
+ * Checks if a type is a bounded key: a union of bounded strings, numeric
35
+ * literals, or symbol literals.
36
+ */
37
+ type IsBoundedKey<T> = T extends unknown ? IsStringLiteral<T> extends true ? IsBoundedString<T> : IsNumericLiteral<T> extends true ? true : IsSymbolLiteral<T> : never;
38
+ /**
39
+ * Checks if a type is a bounded string: a type that only has a finite
40
+ * number of strings that are that type.
41
+ *
42
+ * Most relevant for template literals: IsBoundedString<`${1 | 2}_${3 | 4}`> is
43
+ * true, and IsBoundedString<`${1 | 2}_${number}`> is false.
28
44
  */
29
- type IfSimpleRecord<T, TypeIfSimpleRecord = true, TypeIfNotSimpleRecord = false> = string extends keyof T ? TypeIfSimpleRecord : number extends keyof T ? TypeIfSimpleRecord : number | string extends keyof T ? TypeIfSimpleRecord : TypeIfNotSimpleRecord;
45
+ type IsBoundedString<T> = T extends string ? Split<T, ''>[number] extends infer U ? [
46
+ `${number}`
47
+ ] extends [U] ? false : [string] extends [U] ? false : true : false : false;
30
48
  /**
31
49
  * A union of all keys of T which are not symbols, and where number keys are
32
50
  * converted to strings, following the definition of `Object.keys` and
@@ -36,14 +54,18 @@ type IfSimpleRecord<T, TypeIfSimpleRecord = true, TypeIfNotSimpleRecord = false>
36
54
  *
37
55
  * @see EnumerableStringKeyedValueOf
38
56
  */
39
- type EnumerableStringKeyOf<T> = `${Exclude<keyof T, symbol>}`;
57
+ type EnumerableStringKeyOf<T> = Required<T> extends Record<infer K, unknown> ? `${Exclude<K, symbol>}` : never;
40
58
  /**
41
59
  * A union of all values of properties in T which are not keyed by a symbol,
42
60
  * following the definition of `Object.values` and `Object.entries`.
43
61
  */
44
- type EnumerableStringKeyedValueOf<T> = {
62
+ type EnumerableStringKeyedValueOf<T> = ValuesOf<{
45
63
  [K in keyof T]-?: K extends symbol ? never : T[K];
46
- }[keyof T];
64
+ }>;
65
+ /**
66
+ * Extracts the value type from an object type T.
67
+ */
68
+ type ValuesOf<T> = T extends EmptyObject ? T[keyof T] : T extends Record<PropertyKey, infer V> ? V : never;
47
69
  /**
48
70
  * This is the type you'd get from doing:
49
71
  * `Object.fromEntries(Object.entries(x))`.
@@ -57,24 +79,7 @@ type ReconstructedRecord<T> = Record<EnumerableStringKeyOf<T>, EnumerableStringK
57
79
  * function isMyType<T>(data: T | MyType): data is NarrowedTo<T, MyType> { ... }
58
80
  */
59
81
  type NarrowedTo<T, Base> = Extract<T, Base> extends never ? Base : IsAny<T> extends true ? Base : Extract<T, Base>;
60
- /**
61
- * Records keyed with generic `string` and `number`
62
- * have different semantics to those with a a union of literal values
63
- * (e.g. 'cat' | 'dog') when using 'noUncheckedIndexedAccess',
64
- * the former being implicitly `Partial` whereas the latter are implicitly `Required`.
65
- */
66
- type ExactRecord<Key extends PropertyKey, Value> = IfSimpleRecord<Record<Key, Value>,
67
- /**
68
- * If either string or number extend Key it means that Key is at least as wide as them,
69
- * so we don't need to wrap the returned record with Partial.
70
- */
71
- Record<Key, Value>,
72
- /**
73
- * If the key is specific, e.g. 'cat' | 'dog', the result is partial
74
- * because we can't statically know what values the mapper would return on
75
- * a specific input.
76
- */
77
- Partial<Record<Key, Value>>>;
82
+ type ExactRecord<Key extends PropertyKey, Value> = IfBoundedRecord<Record<Key, Value>, Partial<Record<Key, Value>>, Record<Key, Value>>;
78
83
  type ReorderedArray<T extends IterableContainer> = {
79
84
  -readonly [P in keyof T]: T[number];
80
85
  };
@@ -98,5 +103,13 @@ type IsSingleLiteral<K> = IsLiteral<K> extends true ? (IsUnion<K> extends true ?
98
103
  */
99
104
  type IsUnion<T> = InternalIsUnion<T>;
100
105
  type InternalIsUnion<T, U = T> = (IsNever<T> extends true ? false : T extends any ? [U] extends [T] ? false : true : never) extends infer Result ? boolean extends Result ? true : Result : never;
106
+ /**
107
+ * Extracts a type predicate from a type guard function for the first argument.
108
+ *
109
+ * @example
110
+ * type TypeGuardFn = (x: unknown) => x is string;
111
+ * type Result = GuardType<TypeGuardFn>; // `string`
112
+ */
113
+ type GuardType<T, Fallback = never> = T extends (x: any, ...rest: any) => x is infer U ? U : Fallback;
101
114
 
102
- export type { Branded as B, EnumerableStringKeyedValueOf as E, IterableContainer as I, Mapped as M, NonEmptyArray as N, ReconstructedRecord as R, UpsertProp as U, EnumerableStringKeyOf as a, ExactRecord as b, NarrowedTo as c, IsUnion as d, IfSimpleRecord as e, ReorderedArray as f };
115
+ export type { Branded as B, EnumerableStringKeyedValueOf as E, GuardType as G, IterableContainer as I, Mapped as M, NonEmptyArray as N, ReconstructedRecord as R, UpsertProp as U, EnumerableStringKeyOf as a, ExactRecord as b, NarrowedTo as c, IsUnion as d, IfBoundedRecord as e, ReorderedArray as f };
package/dist/values.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { I as IterableContainer, E as EnumerableStringKeyedValueOf } from './types-DCY4LHuA.cjs';
1
+ import { I as IterableContainer, E as EnumerableStringKeyedValueOf } from './types-BMu1PIvo.cjs';
2
2
  import 'type-fest';
3
3
 
4
4
  type Values<T extends object> = T extends IterableContainer ? Array<T[number]> : Array<EnumerableStringKeyedValueOf<T>>;
package/dist/values.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { I as IterableContainer, E as EnumerableStringKeyedValueOf } from './types-DCY4LHuA.js';
1
+ import { I as IterableContainer, E as EnumerableStringKeyedValueOf } from './types-BMu1PIvo.js';
2
2
  import 'type-fest';
3
3
 
4
4
  type Values<T extends object> = T extends IterableContainer ? Array<T[number]> : Array<EnumerableStringKeyedValueOf<T>>;
@@ -1,4 +1,4 @@
1
- import { I as IterableContainer } from './types-DCY4LHuA.cjs';
1
+ import { I as IterableContainer } from './types-BMu1PIvo.cjs';
2
2
  import 'type-fest';
3
3
 
4
4
  type ZippingFunction<T1 extends IterableContainer = IterableContainer, T2 extends IterableContainer = IterableContainer, Value = unknown> = (first: T1[number], second: T2[number], index: number, data: readonly [first: T1, second: T2]) => Value;
@@ -1,4 +1,4 @@
1
- import { I as IterableContainer } from './types-DCY4LHuA.js';
1
+ import { I as IterableContainer } from './types-BMu1PIvo.js';
2
2
  import 'type-fest';
3
3
 
4
4
  type ZippingFunction<T1 extends IterableContainer = IterableContainer, T2 extends IterableContainer = IterableContainer, Value = unknown> = (first: T1[number], second: T2[number], index: number, data: readonly [first: T1, second: T2]) => Value;
package/dist/zip.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { I as IterableContainer } from './types-DCY4LHuA.cjs';
1
+ import { I as IterableContainer } from './types-BMu1PIvo.cjs';
2
2
  import 'type-fest';
3
3
 
4
4
  type Zipped<Left extends IterableContainer, Right extends IterableContainer> = Left extends readonly [] ? [] : Right extends readonly [] ? [] : Left extends readonly [infer LeftHead, ...infer LeftRest] ? Right extends readonly [infer RightHead, ...infer RightRest] ? [
package/dist/zip.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { I as IterableContainer } from './types-DCY4LHuA.js';
1
+ import { I as IterableContainer } from './types-BMu1PIvo.js';
2
2
  import 'type-fest';
3
3
 
4
4
  type Zipped<Left extends IterableContainer, Right extends IterableContainer> = Left extends readonly [] ? [] : Right extends readonly [] ? [] : Left extends readonly [infer LeftHead, ...infer LeftRest] ? Right extends readonly [infer RightHead, ...infer RightRest] ? [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vinicunca/perkakas",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
5
  "description": "Utility for JavaScript and Typescript.",
6
6
  "author": "praburangki<https://github.com/praburangki>",
7
7
  "license": "MIT",
@@ -1 +0,0 @@
1
- function t(n,r,e){return n(e[0])?u=>r(u,...e):r(...e)}var i=Object.assign(T,{defaultCase:o});function T(...n){return t(s,a,n)}function a(n,...r){for(let[e,u]of r)if(e(n))return u(n);throw new Error("conditional: data failed for all cases")}function s(n){if(!Array.isArray(n))return!1;let[r,e,...u]=n;return typeof r=="function"&&r.length<=1&&typeof e=="function"&&e.length<=1&&u.length===0}function o(n=h){return[R,n]}function R(){return!0}function h(){}export{i as a};
@@ -1 +0,0 @@
1
- import{a as n}from"./chunk-JFXZ246Y.js";function u(...a){return n(t,a,d)}function t(a,r){return a.forEach(r),a}function d(a){return(r,e,o)=>(a(r,e,o),{done:!1,hasNext:!0,next:r})}export{u as a};
@@ -1 +0,0 @@
1
- import{a as n}from"./chunk-JFXZ246Y.js";function y(...e){return n(l,e)}function l(e,a){let t={...e};for(let[r,o]of Object.entries(t))a(o,r,e)&&delete t[r];return t}export{y as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkY74ER22Ocjs = require('./chunk-Y74ER22O.cjs');function u(...a){return _chunkY74ER22Ocjs.a.call(void 0, t,a,d)}function t(a,r){return a.forEach(r),a}function d(a){return(r,e,o)=>(a(r,e,o),{done:!1,hasNext:!0,next:r})}exports.a = u;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkY74ER22Ocjs = require('./chunk-Y74ER22O.cjs');function y(...e){return _chunkY74ER22Ocjs.a.call(void 0, l,e)}function l(e,a){let t={...e};for(let[r,o]of Object.entries(t))a(o,r,e)&&delete t[r];return t}exports.a = y;
@@ -1 +0,0 @@
1
- var o=e=>typeof e=="object"&&e!==null;export{o as a};
@@ -1 +0,0 @@
1
- import{a}from"./chunk-JFXZ246Y.js";function c(...e){return a(d,e)}function d(e,o,i){let t={};for(let[r,n]of e.entries()){let u=o(n,r,e),m=i(n,r,e);t[u]=m}return t}export{c as a};
@@ -1 +0,0 @@
1
- import{a as t}from"./chunk-JFXZ246Y.js";function a(...n){return t(e,n)}function e(n){let r=typeof n[0]=="bigint"?1n:1;for(let o of n)r*=o;return r}export{a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});function t(n,r,e){return n(e[0])?u=>r(u,...e):r(...e)}var i=Object.assign(T,{defaultCase:o});function T(...n){return t(s,a,n)}function a(n,...r){for(let[e,u]of r)if(e(n))return u(n);throw new Error("conditional: data failed for all cases")}function s(n){if(!Array.isArray(n))return!1;let[r,e,...u]=n;return typeof r=="function"&&r.length<=1&&typeof e=="function"&&e.length<=1&&u.length===0}function o(n=h){return[R,n]}function R(){return!0}function h(){}exports.a = i;
@@ -1 +0,0 @@
1
- import{a as n}from"./chunk-JFXZ246Y.js";function l(...e){return n(i,e)}function i(e,o){let t={};for(let[r,a]of Object.entries(e))o(a,r,e)&&(t[r]=a);return t}export{l as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkY74ER22Ocjs = require('./chunk-Y74ER22O.cjs');function a(...n){return _chunkY74ER22Ocjs.a.call(void 0, e,n)}function e(n){let r=typeof n[0]=="bigint"?0n:0;for(let o of n)r+=o;return r}exports.a = a;
@@ -1 +0,0 @@
1
- import{a as r}from"./chunk-YTNT635N.js";import{a}from"./chunk-JFXZ246Y.js";function b(...e){return a(s,e)}function s(e,n){for(let[t,u]of Object.entries(n))if(!Object.hasOwn(e,t)||!r(u,e[t]))return!1;return!0}export{b as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkY74ER22Ocjs = require('./chunk-Y74ER22O.cjs');function c(...e){return _chunkY74ER22Ocjs.a.call(void 0, d,e)}function d(e,o,i){let t={};for(let[r,n]of e.entries()){let u=o(n,r,e),m=i(n,r,e);t[u]=m}return t}exports.a = c;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkY74ER22Ocjs = require('./chunk-Y74ER22O.cjs');function a(...n){return _chunkY74ER22Ocjs.a.call(void 0, e,n)}function e(n){let r=typeof n[0]=="bigint"?1n:1;for(let o of n)r*=o;return r}exports.a = a;
@@ -1 +0,0 @@
1
- import{a as t}from"./chunk-JFXZ246Y.js";function i(...e){return t(m,e)}function m(e,o){let r={};for(let[y,n]of e.entries())r[n]=o(n,y,e);return r}export{i as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkY74ER22Ocjs = require('./chunk-Y74ER22O.cjs');function d(...e){return _chunkY74ER22Ocjs.a.call(void 0, u,e)}function u(e,a){let n={};for(let[o,r]of Object.entries(e)){let y=a(o,r,e);n[y]=r}return n}exports.a = d;
@@ -1 +0,0 @@
1
- import{a as t}from"./chunk-JFXZ246Y.js";function a(...n){return t(e,n)}function e(n){let r=typeof n[0]=="bigint"?0n:0;for(let o of n)r+=o;return r}export{a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var o=e=>typeof e=="object"&&e!==null;exports.a = o;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkY74ER22Ocjs = require('./chunk-Y74ER22O.cjs');function l(...e){return _chunkY74ER22Ocjs.a.call(void 0, i,e)}function i(e,o){let t={};for(let[r,a]of Object.entries(e))o(a,r,e)&&(t[r]=a);return t}exports.a = l;
@@ -1 +0,0 @@
1
- import{a as t}from"./chunk-JFXZ246Y.js";function d(...e){return t(u,e)}function u(e,a){let n={};for(let[o,r]of Object.entries(e)){let y=a(o,r,e);n[y]=r}return n}export{d as a};