@augment-vir/core 31.71.1 → 31.71.3
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Digit } from '../number/digit.js';
|
|
1
2
|
/**
|
|
2
3
|
* Creates a tuple with length of `OriginalTuple` with values of `NewValueType`.
|
|
3
4
|
*
|
|
@@ -49,14 +50,31 @@ export type RemoveFirstTupleEntry<T extends any[]> = T extends [
|
|
|
49
50
|
any?,
|
|
50
51
|
...infer Tail
|
|
51
52
|
] ? Tail : any[];
|
|
53
|
+
/**
|
|
54
|
+
* Detects whether `Length` is a safe size to materialize as a tuple at the type level. Only matches
|
|
55
|
+
* non-negative integer literals 0–99, whose stringification is exactly one or two ASCII digits.
|
|
56
|
+
* Anything else — sizes ≥ 100, negatives, non-integers, scientific notation, or a non-literal
|
|
57
|
+
* `number` — fails to match, because `_TupleOf` either exceeds TS's recursion limit or never
|
|
58
|
+
* terminates for those inputs.
|
|
59
|
+
*
|
|
60
|
+
* @category Array
|
|
61
|
+
* @category Package : @augment-vir/common
|
|
62
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
63
|
+
*/
|
|
64
|
+
export type IsTupleSizeSafe<Length extends number> = `${Length}` extends `${Digit}` | `${Digit}${Digit}` ? true : false;
|
|
52
65
|
/**
|
|
53
66
|
* A tuple with entries of type `Element` and length of `Length`.
|
|
54
67
|
*
|
|
68
|
+
* Only literal `Length` values from 0 to 99 produce a precise tuple; anything else (≥ 100,
|
|
69
|
+
* negatives, non-integers, scientific notation, or a non-literal `number`) falls back to
|
|
70
|
+
* `Element[]`, because the recursive helper either exceeds TS's recursion limit or never terminates
|
|
71
|
+
* for those inputs.
|
|
72
|
+
*
|
|
55
73
|
* @category Array
|
|
56
74
|
* @category Package : @augment-vir/common
|
|
57
75
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
58
76
|
*/
|
|
59
|
-
export type Tuple<Element, Length extends number> = Length extends Length ?
|
|
77
|
+
export type Tuple<Element, Length extends number> = Length extends Length ? IsTupleSizeSafe<Length> extends true ? _TupleOf<Element, Length, []> : Element[] : never;
|
|
60
78
|
type _TupleOf<ArrayElementGeneric, LengthGeneric extends number, FullArrayGeneric extends unknown[]> = FullArrayGeneric['length'] extends LengthGeneric ? FullArrayGeneric : _TupleOf<ArrayElementGeneric, LengthGeneric, [
|
|
61
79
|
ArrayElementGeneric,
|
|
62
80
|
...FullArrayGeneric
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A union of all single digits in base 10.
|
|
3
|
+
*
|
|
4
|
+
* @category Number
|
|
5
|
+
* @category Package : @augment-vir/common
|
|
6
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
7
|
+
*/
|
|
8
|
+
export type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type ArrayElement } from '../array/array.js';
|
|
2
1
|
import { type CompleteRequire } from './required-keys.js';
|
|
3
2
|
/**
|
|
4
3
|
* Gets the value types of an object with all parts of that object required.
|
|
@@ -11,11 +10,13 @@ export type CompleteValues<T> = CompleteRequire<T>[keyof T];
|
|
|
11
10
|
/**
|
|
12
11
|
* Gets the value types of an object.
|
|
13
12
|
*
|
|
13
|
+
* Do NOT use this on arrays, it will return incorrect values. Instead, use `ArrayElement`.
|
|
14
|
+
*
|
|
14
15
|
* @category Object
|
|
15
16
|
* @category Package : @augment-vir/common
|
|
16
17
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
17
18
|
*/
|
|
18
|
-
export type Values<T> = T
|
|
19
|
+
export type Values<T> = T[keyof T];
|
|
19
20
|
/**
|
|
20
21
|
* Gets the value within an object when all its keys are required.
|
|
21
22
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './augments/http/http-status.js';
|
|
|
13
13
|
export * from './augments/json/json-compatible.js';
|
|
14
14
|
export * from './augments/min-max.js';
|
|
15
15
|
export * from './augments/narrow-type.js';
|
|
16
|
+
export * from './augments/number/digit.js';
|
|
16
17
|
export * from './augments/object/generic-object-type.js';
|
|
17
18
|
export * from './augments/object/object-keys.js';
|
|
18
19
|
export * from './augments/object/object-sort.js';
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from './augments/http/http-status.js';
|
|
|
13
13
|
export * from './augments/json/json-compatible.js';
|
|
14
14
|
export * from './augments/min-max.js';
|
|
15
15
|
export * from './augments/narrow-type.js';
|
|
16
|
+
export * from './augments/number/digit.js';
|
|
16
17
|
export * from './augments/object/generic-object-type.js';
|
|
17
18
|
export * from './augments/object/object-keys.js';
|
|
18
19
|
export * from './augments/object/object-sort.js';
|