@augment-vir/core 32.1.0 → 32.2.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/augments/error/ensure-error.d.ts +1 -1
- package/dist/augments/json/json-compatible.d.ts +2 -1
- package/dist/augments/json/json-value.d.ts +46 -0
- package/dist/augments/json/json-value.js +1 -0
- package/dist/augments/json/jsonify.d.ts +41 -0
- package/dist/augments/json/jsonify.js +1 -0
- package/dist/augments/number/infinity.d.ts +22 -0
- package/dist/augments/number/infinity.js +1 -0
- package/dist/augments/object/object-keys.d.ts +1 -1
- package/dist/augments/object/required-keys.d.ts +5 -5
- package/dist/augments/type/built-in-type.d.ts +28 -0
- package/dist/augments/type/built-in-type.js +1 -0
- package/dist/augments/type/conditional-type.d.ts +13 -0
- package/dist/augments/type/conditional-type.js +1 -0
- package/dist/augments/type/constructor-type.d.ts +51 -0
- package/dist/augments/type/constructor-type.js +1 -0
- package/dist/augments/type/distributed-omit.d.ts +13 -0
- package/dist/augments/type/distributed-omit.js +1 -0
- package/dist/augments/type/empty-object.d.ts +27 -0
- package/dist/augments/type/empty-object.js +1 -0
- package/dist/augments/type/exact.d.ts +23 -0
- package/dist/augments/type/exact.js +1 -0
- package/dist/augments/type/except.d.ts +37 -0
- package/dist/augments/type/except.js +1 -0
- package/dist/augments/type/is-unknown.d.ts +22 -0
- package/dist/augments/type/is-unknown.js +1 -0
- package/dist/augments/type/keys-of-union.d.ts +14 -0
- package/dist/augments/type/keys-of-union.js +1 -0
- package/dist/augments/type/literal-union.d.ts +13 -0
- package/dist/augments/type/literal-union.js +1 -0
- package/dist/augments/type/non-empty-string.d.ts +9 -0
- package/dist/augments/type/non-empty-string.js +1 -0
- package/dist/augments/type/omit-deep.d.ts +290 -0
- package/dist/augments/type/omit-deep.js +1 -0
- package/dist/augments/type/omit-index-signature.d.ts +14 -0
- package/dist/augments/type/omit-index-signature.js +2 -0
- package/dist/augments/type/optional-keys-of.d.ts +25 -0
- package/dist/augments/type/optional-keys-of.js +1 -0
- package/dist/augments/type/package-json.d.ts +176 -0
- package/dist/augments/type/package-json.js +1 -0
- package/dist/augments/type/partial-deep.d.ts +52 -0
- package/dist/augments/type/partial-deep.js +1 -0
- package/dist/augments/type/primitive-type.d.ts +11 -0
- package/dist/augments/type/primitive-type.js +1 -0
- package/dist/augments/type/promisable.d.ts +11 -0
- package/dist/augments/type/promisable.js +1 -0
- package/dist/augments/type/readonly-deep.d.ts +30 -0
- package/dist/augments/type/readonly-deep.js +1 -0
- package/dist/augments/type/readonly-keys-of.d.ts +20 -0
- package/dist/augments/type/readonly-keys-of.js +1 -0
- package/dist/augments/type/require-keys.d.ts +43 -0
- package/dist/augments/type/require-keys.js +1 -0
- package/dist/augments/type/require-one-or-none.d.ts +16 -0
- package/dist/augments/type/require-one-or-none.js +1 -0
- package/dist/augments/type/set-optional.d.ts +19 -0
- package/dist/augments/type/set-optional.js +1 -0
- package/dist/augments/type/set-required.d.ts +47 -0
- package/dist/augments/type/set-required.js +1 -0
- package/dist/augments/type/simplify.d.ts +14 -0
- package/dist/augments/type/simplify.js +1 -0
- package/dist/augments/type/subtract.d.ts +177 -0
- package/dist/augments/type/subtract.js +1 -0
- package/dist/augments/type/tagged.d.ts +30 -0
- package/dist/augments/type/tagged.js +1 -0
- package/dist/augments/type/type-checks.d.ts +32 -0
- package/dist/augments/type/type-checks.js +9 -0
- package/dist/augments/type/typed-array.d.ts +13 -0
- package/dist/augments/type/typed-array.js +1 -0
- package/dist/augments/type/undefined-to-optional.d.ts +27 -0
- package/dist/augments/type/undefined-to-optional.js +1 -0
- package/dist/augments/type/union-to-intersection.d.ts +11 -0
- package/dist/augments/type/union-to-intersection.js +1 -0
- package/dist/augments/type/union-to-tuple.d.ts +18 -0
- package/dist/augments/type/union-to-tuple.js +1 -0
- package/dist/augments/type/unknown-array.d.ts +11 -0
- package/dist/augments/type/unknown-array.js +1 -0
- package/dist/augments/type/writable-deep.d.ts +32 -0
- package/dist/augments/type/writable-deep.js +1 -0
- package/dist/augments/type/writable-keys-of.d.ts +12 -0
- package/dist/augments/type/writable-keys-of.js +1 -0
- package/dist/augments/type/writable.d.ts +29 -0
- package/dist/augments/type/writable.js +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +39 -0
- package/package.json +2 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type RequiredKeysOf } from '../object/required-keys.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `true` if the given object type has at least one required key, otherwise `false`.
|
|
4
|
+
*
|
|
5
|
+
* Copied from the `HasRequiredKeys` type in the `type-fest` package (built on
|
|
6
|
+
* {@link RequiredKeysOf}) so that this package's public types do not depend on `type-fest` (see the
|
|
7
|
+
* note in `type-checks.ts`).
|
|
8
|
+
*
|
|
9
|
+
* @category Object
|
|
10
|
+
* @category Package : @augment-vir/common
|
|
11
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
12
|
+
*/
|
|
13
|
+
export type HasRequiredKeys<BaseType> = [RequiredKeysOf<BaseType>] extends [never] ? false : true;
|
|
14
|
+
/**
|
|
15
|
+
* Create a type that requires exactly one of the given keys and disallows the rest, while keeping
|
|
16
|
+
* the remaining (non-listed) keys as is.
|
|
17
|
+
*
|
|
18
|
+
* Copied from the classic `RequireExactlyOne` implementation in the `type-fest` package (before
|
|
19
|
+
* `type-fest` v5 wrapped it in an `IfNotAnyOrNever` conditional that breaks structural
|
|
20
|
+
* assignability). See the note in `type-checks.ts`.
|
|
21
|
+
*
|
|
22
|
+
* @category Object
|
|
23
|
+
* @category Package : @augment-vir/common
|
|
24
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
25
|
+
*/
|
|
26
|
+
export type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = {
|
|
27
|
+
[Key in KeysType]: Required<Pick<ObjectType, Key>> & Partial<Record<Exclude<KeysType, Key>, never>>;
|
|
28
|
+
}[KeysType] & Omit<ObjectType, KeysType>;
|
|
29
|
+
/**
|
|
30
|
+
* Create a type that requires at least one of the given keys, while keeping the remaining
|
|
31
|
+
* (non-listed) keys as is.
|
|
32
|
+
*
|
|
33
|
+
* Copied from the classic `RequireAtLeastOne` implementation in the `type-fest` package (before
|
|
34
|
+
* `type-fest` v5 wrapped it in an `IfNotAnyOrNever` conditional). See the note in
|
|
35
|
+
* `type-checks.ts`.
|
|
36
|
+
*
|
|
37
|
+
* @category Object
|
|
38
|
+
* @category Package : @augment-vir/common
|
|
39
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
40
|
+
*/
|
|
41
|
+
export type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = {
|
|
42
|
+
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> & Partial<Pick<ObjectType, Exclude<KeysType, Key>>>;
|
|
43
|
+
}[KeysType] & Omit<ObjectType, KeysType>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type RequireExactlyOne } from './require-keys.js';
|
|
2
|
+
type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
|
|
3
|
+
/**
|
|
4
|
+
* Create a type that requires exactly one of the given keys or none of the given keys, while
|
|
5
|
+
* keeping the remaining keys as is.
|
|
6
|
+
*
|
|
7
|
+
* Copied from the classic `RequireOneOrNone` implementation in the `type-fest` package (before
|
|
8
|
+
* `type-fest` v5 wrapped it in an `IfNotAnyOrNever` conditional). See the note in
|
|
9
|
+
* `type-checks.ts`.
|
|
10
|
+
*
|
|
11
|
+
* @category Object
|
|
12
|
+
* @category Package : @augment-vir/common
|
|
13
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
14
|
+
*/
|
|
15
|
+
export type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = (RequireExactlyOne<ObjectType, KeysType> | RequireNone<KeysType>) & Omit<ObjectType, KeysType>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Except } from './except.js';
|
|
2
|
+
import { type KeysOfUnion } from './keys-of-union.js';
|
|
3
|
+
import { type Simplify } from './simplify.js';
|
|
4
|
+
type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = {
|
|
5
|
+
[P in keyof T as Extract<P, Keys>]: T[P];
|
|
6
|
+
};
|
|
7
|
+
type _SetOptional<BaseType, Keys extends keyof BaseType> = BaseType extends unknown ? Simplify<Except<BaseType, Keys> & Partial<HomomorphicPick<BaseType, Keys>>> : never;
|
|
8
|
+
/**
|
|
9
|
+
* Create a type that makes the given keys optional, while keeping the remaining keys as is.
|
|
10
|
+
*
|
|
11
|
+
* Copied from the `SetOptional` type in the `type-fest` package so that this package's public types
|
|
12
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
13
|
+
*
|
|
14
|
+
* @category Object
|
|
15
|
+
* @category Package : @augment-vir/common
|
|
16
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
17
|
+
*/
|
|
18
|
+
export type SetOptional<BaseType, Keys extends keyof BaseType> = (BaseType extends (...arguments_: never) => any ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType> : unknown) & _SetOptional<BaseType, Keys>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type If } from './conditional-type.js';
|
|
2
|
+
import { type Except } from './except.js';
|
|
3
|
+
import { type KeysOfUnion } from './keys-of-union.js';
|
|
4
|
+
import { type OptionalKeysOf } from './optional-keys-of.js';
|
|
5
|
+
import { type Simplify } from './simplify.js';
|
|
6
|
+
import { type IsNever } from './type-checks.js';
|
|
7
|
+
import { type UnknownArray } from './unknown-array.js';
|
|
8
|
+
type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = {
|
|
9
|
+
[P in keyof T as Extract<P, Keys>]: T[P];
|
|
10
|
+
};
|
|
11
|
+
type IsArrayReadonly<T extends UnknownArray> = If<IsNever<T>, false, T extends unknown[] ? false : true>;
|
|
12
|
+
/** Remove the optional modifier from the specified keys in an array. */
|
|
13
|
+
type SetArrayRequired<TArray extends UnknownArray, Keys, Counter extends any[] = [], Accumulator extends UnknownArray = []> = TArray extends unknown ? keyof TArray & `${number}` extends never ? [
|
|
14
|
+
...Accumulator,
|
|
15
|
+
...TArray
|
|
16
|
+
] : TArray extends readonly [
|
|
17
|
+
(infer First)?,
|
|
18
|
+
...infer Rest
|
|
19
|
+
] ? '0' extends OptionalKeysOf<TArray> ? `${Counter['length']}` extends `${Keys & (string | number)}` ? SetArrayRequired<Rest, Keys, [
|
|
20
|
+
...Counter,
|
|
21
|
+
any
|
|
22
|
+
], [
|
|
23
|
+
...Accumulator,
|
|
24
|
+
First
|
|
25
|
+
]> : [
|
|
26
|
+
...Accumulator,
|
|
27
|
+
...TArray
|
|
28
|
+
] : SetArrayRequired<Rest, Keys, [
|
|
29
|
+
...Counter,
|
|
30
|
+
any
|
|
31
|
+
], [
|
|
32
|
+
...Accumulator,
|
|
33
|
+
TArray[0]
|
|
34
|
+
]> : never : never;
|
|
35
|
+
type _SetRequired<BaseType, Keys extends keyof BaseType> = BaseType extends UnknownArray ? SetArrayRequired<BaseType, Keys> extends infer ResultantArray ? If<IsArrayReadonly<BaseType>, Readonly<ResultantArray>, ResultantArray> : never : Simplify<Except<BaseType, Keys> & Required<HomomorphicPick<BaseType, Keys>>>;
|
|
36
|
+
/**
|
|
37
|
+
* Create a type that makes the given keys required, while keeping the remaining keys as is.
|
|
38
|
+
*
|
|
39
|
+
* Copied from the `SetRequired` type in the `type-fest` package so that this package's public types
|
|
40
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
41
|
+
*
|
|
42
|
+
* @category Object
|
|
43
|
+
* @category Package : @augment-vir/common
|
|
44
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
45
|
+
*/
|
|
46
|
+
export type SetRequired<BaseType, Keys extends keyof BaseType> = (BaseType extends (...arguments_: never) => any ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType> : unknown) & _SetRequired<BaseType, Keys>;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flattens the type output to improve type hints shown in editors. Also transforms an interface
|
|
3
|
+
* into a type to aid with assignability.
|
|
4
|
+
*
|
|
5
|
+
* Copied from the `Simplify` type in the `type-fest` package so that this package's public types do
|
|
6
|
+
* not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
7
|
+
*
|
|
8
|
+
* @category Object
|
|
9
|
+
* @category Package : @augment-vir/common
|
|
10
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
11
|
+
*/
|
|
12
|
+
export type Simplify<T> = {
|
|
13
|
+
[KeyType in keyof T]: T[KeyType];
|
|
14
|
+
} & {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { type NegativeInfinity, type PositiveInfinity } from '../number/infinity.js';
|
|
2
|
+
import { type If } from './conditional-type.js';
|
|
3
|
+
import { type IsAny, type IsEqual, type IsNever } from './type-checks.js';
|
|
4
|
+
import { type UnknownArray } from './unknown-array.js';
|
|
5
|
+
type Numeric = number | bigint;
|
|
6
|
+
type Zero = 0 | 0n;
|
|
7
|
+
type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
|
|
8
|
+
type IsNegative<T extends Numeric> = T extends Negative<T> ? true : false;
|
|
9
|
+
type ReverseSign<N extends number> = N extends 0 ? 0 : N extends PositiveInfinity ? NegativeInfinity : N extends NegativeInfinity ? PositiveInfinity : `${N}` extends `-${infer P extends number}` ? P : `-${N}` extends `${infer R extends number}` ? R : never;
|
|
10
|
+
type StringToNumber<S extends string> = S extends `${infer N extends number}` ? N : S extends 'Infinity' ? PositiveInfinity : S extends '-Infinity' ? NegativeInfinity : never;
|
|
11
|
+
type Absolute<N extends number | bigint> = N extends bigint ? `${N}` extends `-${infer Magnitude extends bigint}` ? Magnitude : N : `${N}` extends `-${infer Magnitude}` ? StringToNumber<Magnitude> : N;
|
|
12
|
+
type IfNotAnyOrNever<T, IfNotAny, IfAny = any, IfNever = never> = If<IsAny<T>, IfAny, If<IsNever<T>, IfNever, IfNotAny>>;
|
|
13
|
+
type DigitCharacter = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
14
|
+
type DigitTupleOf<Digit extends DigitCharacter, Fill> = [
|
|
15
|
+
[
|
|
16
|
+
],
|
|
17
|
+
[
|
|
18
|
+
Fill
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
Fill,
|
|
22
|
+
Fill
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
Fill,
|
|
26
|
+
Fill,
|
|
27
|
+
Fill
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
Fill,
|
|
31
|
+
Fill,
|
|
32
|
+
Fill,
|
|
33
|
+
Fill
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
Fill,
|
|
37
|
+
Fill,
|
|
38
|
+
Fill,
|
|
39
|
+
Fill,
|
|
40
|
+
Fill
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
Fill,
|
|
44
|
+
Fill,
|
|
45
|
+
Fill,
|
|
46
|
+
Fill,
|
|
47
|
+
Fill,
|
|
48
|
+
Fill
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
Fill,
|
|
52
|
+
Fill,
|
|
53
|
+
Fill,
|
|
54
|
+
Fill,
|
|
55
|
+
Fill,
|
|
56
|
+
Fill,
|
|
57
|
+
Fill
|
|
58
|
+
],
|
|
59
|
+
[
|
|
60
|
+
Fill,
|
|
61
|
+
Fill,
|
|
62
|
+
Fill,
|
|
63
|
+
Fill,
|
|
64
|
+
Fill,
|
|
65
|
+
Fill,
|
|
66
|
+
Fill,
|
|
67
|
+
Fill
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
Fill,
|
|
71
|
+
Fill,
|
|
72
|
+
Fill,
|
|
73
|
+
Fill,
|
|
74
|
+
Fill,
|
|
75
|
+
Fill,
|
|
76
|
+
Fill,
|
|
77
|
+
Fill,
|
|
78
|
+
Fill
|
|
79
|
+
]
|
|
80
|
+
][Digit];
|
|
81
|
+
type RepeatTupleTenTimes<Tuple extends UnknownArray> = [
|
|
82
|
+
...Tuple,
|
|
83
|
+
...Tuple,
|
|
84
|
+
...Tuple,
|
|
85
|
+
...Tuple,
|
|
86
|
+
...Tuple,
|
|
87
|
+
...Tuple,
|
|
88
|
+
...Tuple,
|
|
89
|
+
...Tuple,
|
|
90
|
+
...Tuple,
|
|
91
|
+
...Tuple
|
|
92
|
+
];
|
|
93
|
+
type BuildTupleDigitByDigit<Length extends string, Fill, Accumulator extends UnknownArray = []> = Length extends `${infer First extends DigitCharacter}${infer Rest}` ? BuildTupleDigitByDigit<Rest, Fill, [
|
|
94
|
+
...RepeatTupleTenTimes<Accumulator>,
|
|
95
|
+
...DigitTupleOf<First, Fill>
|
|
96
|
+
]> : Accumulator;
|
|
97
|
+
type BuildTuple<Length extends number, Fill> = number extends Length ? Fill[] : BuildTupleDigitByDigit<`${Length}`, Fill>;
|
|
98
|
+
type TupleOf<Length extends number, Fill = unknown> = IfNotAnyOrNever<Length, BuildTuple<If<IsNegative<Length>, 0, Length>, Fill>, Fill[], [
|
|
99
|
+
]>;
|
|
100
|
+
type And<A extends boolean, B extends boolean> = A extends true ? B extends true ? true : false : false;
|
|
101
|
+
type Or<A extends boolean, B extends boolean> = A extends true ? true : B extends true ? true : false;
|
|
102
|
+
type StringToArray<S extends string, Result extends string[] = []> = string extends S ? never : S extends `${infer F}${infer R}` ? StringToArray<R, [
|
|
103
|
+
...Result,
|
|
104
|
+
F
|
|
105
|
+
]> : Result;
|
|
106
|
+
type StringLength<S extends string> = string extends S ? never : StringToArray<S>['length'];
|
|
107
|
+
type NumericString = '0123456789';
|
|
108
|
+
type PositiveNumericCharacterGt<A extends string, B extends string> = NumericString extends `${infer HeadA}${A}${infer TailA}` ? NumericString extends `${infer HeadB}${B}${infer TailB}` ? HeadA extends `${HeadB}${infer _}${infer __}` ? true : false : never : never;
|
|
109
|
+
type SameLengthPositiveNumericStringGt<A extends string, B extends string> = A extends `${infer FirstA}${infer RestA}` ? B extends `${infer FirstB}${infer RestB}` ? FirstA extends FirstB ? SameLengthPositiveNumericStringGt<RestA, RestB> : PositiveNumericCharacterGt<FirstA, FirstB> : never : false;
|
|
110
|
+
type PositiveNumericStringGt<A extends string, B extends string> = A extends B ? false : [
|
|
111
|
+
TupleOf<StringLength<A>, 0>,
|
|
112
|
+
TupleOf<StringLength<B>, 0>
|
|
113
|
+
] extends infer R extends [
|
|
114
|
+
readonly unknown[],
|
|
115
|
+
readonly unknown[]
|
|
116
|
+
] ? R[0] extends [
|
|
117
|
+
...R[1],
|
|
118
|
+
...infer Remain extends readonly unknown[]
|
|
119
|
+
] ? 0 extends Remain['length'] ? SameLengthPositiveNumericStringGt<A, B> : true : false : never;
|
|
120
|
+
type GreaterThan<A extends number, B extends number> = A extends number ? B extends number ? number extends A | B ? boolean : [
|
|
121
|
+
IsEqual<A, PositiveInfinity>,
|
|
122
|
+
IsEqual<A, NegativeInfinity>,
|
|
123
|
+
IsEqual<B, PositiveInfinity>,
|
|
124
|
+
IsEqual<B, NegativeInfinity>
|
|
125
|
+
] extends infer R extends [
|
|
126
|
+
boolean,
|
|
127
|
+
boolean,
|
|
128
|
+
boolean,
|
|
129
|
+
boolean
|
|
130
|
+
] ? Or<And<IsEqual<R[0], true>, IsEqual<R[2], false>>, And<IsEqual<R[3], true>, IsEqual<R[1], false>>> extends true ? true : Or<And<IsEqual<R[1], true>, IsEqual<R[3], false>>, And<IsEqual<R[2], true>, IsEqual<R[0], false>>> extends true ? false : true extends R[number] ? false : [
|
|
131
|
+
IsNegative<A>,
|
|
132
|
+
IsNegative<B>
|
|
133
|
+
] extends infer R extends [
|
|
134
|
+
boolean,
|
|
135
|
+
boolean
|
|
136
|
+
] ? [
|
|
137
|
+
true,
|
|
138
|
+
false
|
|
139
|
+
] extends R ? false : [
|
|
140
|
+
false,
|
|
141
|
+
true
|
|
142
|
+
] extends R ? true : [
|
|
143
|
+
false,
|
|
144
|
+
false
|
|
145
|
+
] extends R ? PositiveNumericStringGt<`${A}`, `${B}`> : PositiveNumericStringGt<`${Absolute<B>}`, `${Absolute<A>}`> : never : never : never : never;
|
|
146
|
+
type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B ? boolean : A extends number ? B extends number ? A extends B ? true : GreaterThan<A, B> : never : never;
|
|
147
|
+
type LessThan<A extends number, B extends number> = GreaterThanOrEqual<A, B> extends infer Result ? (Result extends true ? false : true) : never;
|
|
148
|
+
type SubtractIfAGreaterThanB<A extends number, B extends number> = TupleOf<A> extends [
|
|
149
|
+
...TupleOf<B>,
|
|
150
|
+
...infer R
|
|
151
|
+
] ? R['length'] : never;
|
|
152
|
+
type SubtractPositives<A extends number, B extends number> = LessThan<A, B> extends true ? ReverseSign<SubtractIfAGreaterThanB<B, A>> : SubtractIfAGreaterThanB<A, B>;
|
|
153
|
+
type SubtractPostChecks<A extends number, B extends number, AreNegative = [
|
|
154
|
+
IsNegative<A>,
|
|
155
|
+
IsNegative<B>
|
|
156
|
+
]> = AreNegative extends [
|
|
157
|
+
false,
|
|
158
|
+
false
|
|
159
|
+
] ? SubtractPositives<A, B> : AreNegative extends [
|
|
160
|
+
true,
|
|
161
|
+
true
|
|
162
|
+
] ? ReverseSign<SubtractPositives<Absolute<A>, Absolute<B>>> : [
|
|
163
|
+
...TupleOf<Absolute<A>>,
|
|
164
|
+
...TupleOf<Absolute<B>>
|
|
165
|
+
] extends infer R extends unknown[] ? LessThan<A, B> extends true ? ReverseSign<R['length']> : R['length'] : never;
|
|
166
|
+
/**
|
|
167
|
+
* Returns the difference between two numbers. `A` or `B` can only support `-999` ~ `999`.
|
|
168
|
+
*
|
|
169
|
+
* Copied from the `Subtract` type in the `type-fest` package so that this package's public types do
|
|
170
|
+
* not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
171
|
+
*
|
|
172
|
+
* @category Number
|
|
173
|
+
* @category Package : @augment-vir/common
|
|
174
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
175
|
+
*/
|
|
176
|
+
export type Subtract<A extends number, B extends number> = number extends A | B ? number : A extends B & (PositiveInfinity | NegativeInfinity) ? number : A extends NegativeInfinity ? NegativeInfinity : B extends PositiveInfinity ? NegativeInfinity : A extends PositiveInfinity ? PositiveInfinity : B extends NegativeInfinity ? PositiveInfinity : A extends B ? 0 : A extends 0 ? ReverseSign<B> : B extends 0 ? A : SubtractPostChecks<A, B>;
|
|
177
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare const tag: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* The container object that holds a {@link Tagged} type's tags.
|
|
4
|
+
*
|
|
5
|
+
* Copied from the `TagContainer` type in the `type-fest` package so that this package's public
|
|
6
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
7
|
+
*
|
|
8
|
+
* @category Type
|
|
9
|
+
* @category Package : @augment-vir/common
|
|
10
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
11
|
+
*/
|
|
12
|
+
export type TagContainer<Token> = {
|
|
13
|
+
readonly [tag]: Token;
|
|
14
|
+
};
|
|
15
|
+
type Tag<Token extends PropertyKey, TagMetadata> = TagContainer<{
|
|
16
|
+
[K in Token]: TagMetadata;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a tagged type that can support multiple tags and per-tag metadata. Useful for creating
|
|
20
|
+
* distinct types that are not assignable to one another even though they share an underlying type.
|
|
21
|
+
*
|
|
22
|
+
* Copied from the `Tagged` type in the `type-fest` package so that this package's public types do
|
|
23
|
+
* not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
24
|
+
*
|
|
25
|
+
* @category Type
|
|
26
|
+
* @category Package : @augment-vir/common
|
|
27
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
28
|
+
*/
|
|
29
|
+
export type Tagged<Type, TagName extends PropertyKey, TagMetadata = never> = Type & Tag<TagName, TagMetadata>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These type predicates are copied from the `type-fest` package rather than imported from it.
|
|
3
|
+
* Owning them here keeps `@augment-vir` (and its consumers) decoupled from `type-fest`'s evolving
|
|
4
|
+
* internals: `type-fest` v5 started wrapping several of its utility types in an `IfNotAnyOrNever`
|
|
5
|
+
* conditional that breaks structural assignability and narrowing, and because those utilities leak
|
|
6
|
+
* through the public `.d.ts` of downstream packages, a `type-fest` upgrade could silently break
|
|
7
|
+
* consumers. These local copies use only built-in types so they never reference `type-fest`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Returns `true` if the two given types are exactly equal, otherwise `false`.
|
|
11
|
+
*
|
|
12
|
+
* @category Type
|
|
13
|
+
* @category Package : @augment-vir/common
|
|
14
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
15
|
+
*/
|
|
16
|
+
export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B ? 1 : 2 ? true : false;
|
|
17
|
+
/**
|
|
18
|
+
* Returns `true` if the given type is `never`, otherwise `false`.
|
|
19
|
+
*
|
|
20
|
+
* @category Type
|
|
21
|
+
* @category Package : @augment-vir/common
|
|
22
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
23
|
+
*/
|
|
24
|
+
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
25
|
+
/**
|
|
26
|
+
* Returns `true` if the given type is `any`, otherwise `false`.
|
|
27
|
+
*
|
|
28
|
+
* @category Type
|
|
29
|
+
* @category Package : @augment-vir/common
|
|
30
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
31
|
+
*/
|
|
32
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These type predicates are copied from the `type-fest` package rather than imported from it.
|
|
3
|
+
* Owning them here keeps `@augment-vir` (and its consumers) decoupled from `type-fest`'s evolving
|
|
4
|
+
* internals: `type-fest` v5 started wrapping several of its utility types in an `IfNotAnyOrNever`
|
|
5
|
+
* conditional that breaks structural assignability and narrowing, and because those utilities leak
|
|
6
|
+
* through the public `.d.ts` of downstream packages, a `type-fest` upgrade could silently break
|
|
7
|
+
* consumers. These local copies use only built-in types so they never reference `type-fest`.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches any [typed
|
|
3
|
+
* array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray),
|
|
4
|
+
* like `Uint8Array` or `Float64Array`.
|
|
5
|
+
*
|
|
6
|
+
* Copied from the `TypedArray` type in the `type-fest` package so that this package's public types
|
|
7
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
8
|
+
*
|
|
9
|
+
* @category Array
|
|
10
|
+
* @category Package : @augment-vir/common
|
|
11
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
12
|
+
*/
|
|
13
|
+
export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type IsUnknown } from './is-unknown.js';
|
|
2
|
+
import { type Simplify } from './simplify.js';
|
|
3
|
+
import { type IsAny } from './type-checks.js';
|
|
4
|
+
type BaseKeyFilter<Type, Key extends keyof Type> = Key extends symbol ? never : Type[Key] extends symbol ? never : Type[Key] extends Record<string, unknown> ? Key : [(...arguments_: any[]) => any] extends [Type[Key]] ? never : Key;
|
|
5
|
+
type FilterDefinedKeys<T extends object> = Exclude<{
|
|
6
|
+
[Key in keyof T]: IsAny<T[Key]> extends true ? Key : IsUnknown<T[Key]> extends true ? Key : undefined extends T[Key] ? never : T[Key] extends undefined ? never : BaseKeyFilter<T, Key>;
|
|
7
|
+
}[keyof T], undefined>;
|
|
8
|
+
type FilterOptionalKeys<T extends object> = Exclude<{
|
|
9
|
+
[Key in keyof T]: IsAny<T[Key]> extends true ? never : undefined extends T[Key] ? T[Key] extends undefined ? never : BaseKeyFilter<T, Key> : never;
|
|
10
|
+
}[keyof T], undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* For an object `T`, if it has any properties that are a union with `undefined`, make those into
|
|
13
|
+
* optional properties instead.
|
|
14
|
+
*
|
|
15
|
+
* Copied from the internal `UndefinedToOptional` type in the `type-fest` package so that this
|
|
16
|
+
* package's public types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
17
|
+
*
|
|
18
|
+
* @category Object
|
|
19
|
+
* @category Package : @augment-vir/common
|
|
20
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
21
|
+
*/
|
|
22
|
+
export type UndefinedToOptional<T extends object> = Simplify<{
|
|
23
|
+
[Key in keyof Pick<T, FilterDefinedKeys<T>>]: T[Key];
|
|
24
|
+
} & {
|
|
25
|
+
[Key in keyof Pick<T, FilterOptionalKeys<T>>]?: Exclude<T[Key], undefined>;
|
|
26
|
+
}>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a union type to an intersection type.
|
|
3
|
+
*
|
|
4
|
+
* Copied from the `UnionToIntersection` type in the `type-fest` package so that this package's
|
|
5
|
+
* public types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
6
|
+
*
|
|
7
|
+
* @category Type
|
|
8
|
+
* @category Package : @augment-vir/common
|
|
9
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
|
+
*/
|
|
11
|
+
export type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection & Union : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type UnionToIntersection } from './union-to-intersection.js';
|
|
2
|
+
type LastOfUnion<Union> = UnionToIntersection<Union extends unknown ? () => Union : never> extends () => infer Last ? Last : never;
|
|
3
|
+
/**
|
|
4
|
+
* Convert a union type into an unordered tuple type of its elements. The order of the resulting
|
|
5
|
+
* tuple is not guaranteed.
|
|
6
|
+
*
|
|
7
|
+
* Copied from the `UnionToTuple` type in the `type-fest` package so that this package's public
|
|
8
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
9
|
+
*
|
|
10
|
+
* @category Array
|
|
11
|
+
* @category Package : @augment-vir/common
|
|
12
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
13
|
+
*/
|
|
14
|
+
export type UnionToTuple<Union, Accumulator extends unknown[] = []> = [Union] extends [never] ? Accumulator : UnionToTuple<Exclude<Union, LastOfUnion<Union>>, [
|
|
15
|
+
LastOfUnion<Union>,
|
|
16
|
+
...Accumulator
|
|
17
|
+
]>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an array with `unknown` values. Any array can be assigned to this type.
|
|
3
|
+
*
|
|
4
|
+
* Copied from the `UnknownArray` type in the `type-fest` package so that this package's public
|
|
5
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
6
|
+
*
|
|
7
|
+
* @category Array
|
|
8
|
+
* @category Package : @augment-vir/common
|
|
9
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
|
+
*/
|
|
11
|
+
export type UnknownArray = readonly unknown[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type BuiltIns, type HasMultipleCallSignatures } from './built-in-type.js';
|
|
2
|
+
type WritableMapDeep<MapType extends ReadonlyMap<unknown, unknown>> = MapType extends ReadonlyMap<infer KeyType, infer ValueType> ? Map<WritableDeep<KeyType>, WritableDeep<ValueType>> : MapType;
|
|
3
|
+
type WritableSetDeep<SetType extends ReadonlySet<unknown>> = SetType extends ReadonlySet<infer ItemType> ? Set<WritableDeep<ItemType>> : SetType;
|
|
4
|
+
type WritableObjectDeep<ObjectType extends object> = {
|
|
5
|
+
-readonly [KeyType in keyof ObjectType]: WritableDeep<ObjectType[KeyType]>;
|
|
6
|
+
};
|
|
7
|
+
type WritableArrayDeep<ArrayType extends readonly unknown[]> = ArrayType extends readonly [] ? [] : ArrayType extends readonly [
|
|
8
|
+
...infer U,
|
|
9
|
+
infer V
|
|
10
|
+
] ? [
|
|
11
|
+
...WritableArrayDeep<U>,
|
|
12
|
+
WritableDeep<V>
|
|
13
|
+
] : ArrayType extends readonly [
|
|
14
|
+
infer U,
|
|
15
|
+
...infer V
|
|
16
|
+
] ? [
|
|
17
|
+
WritableDeep<U>,
|
|
18
|
+
...WritableArrayDeep<V>
|
|
19
|
+
] : ArrayType extends ReadonlyArray<infer U> ? Array<WritableDeep<U>> : ArrayType extends Array<infer U> ? Array<WritableDeep<U>> : ArrayType;
|
|
20
|
+
/**
|
|
21
|
+
* Create a deeply mutable version of an `object`/`ReadonlyMap`/`ReadonlySet`/`ReadonlyArray` type.
|
|
22
|
+
* The inverse of `ReadonlyDeep<T>`.
|
|
23
|
+
*
|
|
24
|
+
* Copied from the `WritableDeep` type in the `type-fest` package so that this package's public
|
|
25
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
26
|
+
*
|
|
27
|
+
* @category Object
|
|
28
|
+
* @category Package : @augment-vir/common
|
|
29
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
30
|
+
*/
|
|
31
|
+
export type WritableDeep<T> = T extends BuiltIns ? T : T extends (...arguments_: any[]) => unknown ? {} extends WritableObjectDeep<T> ? T : HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & WritableObjectDeep<T> : T extends ReadonlyMap<unknown, unknown> ? WritableMapDeep<T> : T extends ReadonlySet<unknown> ? WritableSetDeep<T> : T extends readonly unknown[] ? WritableArrayDeep<T> : T extends object ? WritableObjectDeep<T> : unknown;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ReadonlyKeysOf } from './readonly-keys-of.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extract all writable keys from the given type.
|
|
4
|
+
*
|
|
5
|
+
* Copied from the `WritableKeysOf` type in the `type-fest` package so that this package's public
|
|
6
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
7
|
+
*
|
|
8
|
+
* @category Object
|
|
9
|
+
* @category Package : @augment-vir/common
|
|
10
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
11
|
+
*/
|
|
12
|
+
export type WritableKeysOf<Type extends object> = Type extends unknown ? Exclude<keyof Type, ReadonlyKeysOf<Type>> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Except } from './except.js';
|
|
2
|
+
import { type Simplify } from './simplify.js';
|
|
3
|
+
type WritableArray<ArrayType extends readonly unknown[]> = ArrayType extends readonly [] ? [] : ArrayType extends readonly [
|
|
4
|
+
...infer U,
|
|
5
|
+
infer V
|
|
6
|
+
] ? [
|
|
7
|
+
...U,
|
|
8
|
+
V
|
|
9
|
+
] : ArrayType extends readonly [
|
|
10
|
+
infer U,
|
|
11
|
+
...infer V
|
|
12
|
+
] ? [
|
|
13
|
+
U,
|
|
14
|
+
...V
|
|
15
|
+
] : ArrayType extends ReadonlyArray<infer U> ? U[] : ArrayType;
|
|
16
|
+
/**
|
|
17
|
+
* Create a type that strips `readonly` from the given type. Inverse of `Readonly<T>`.
|
|
18
|
+
*
|
|
19
|
+
* Copied from the `Writable` type in the `type-fest` package so that this package's public types do
|
|
20
|
+
* not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
21
|
+
*
|
|
22
|
+
* @category Object
|
|
23
|
+
* @category Package : @augment-vir/common
|
|
24
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
25
|
+
*/
|
|
26
|
+
export type Writable<BaseType, Keys extends keyof BaseType = keyof BaseType> = BaseType extends ReadonlyMap<infer KeyType, infer ValueType> ? Map<KeyType, ValueType> : BaseType extends ReadonlySet<infer ItemType> ? Set<ItemType> : BaseType extends readonly unknown[] ? WritableArray<BaseType> : Simplify<Except<BaseType, Keys> & {
|
|
27
|
+
-readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType];
|
|
28
|
+
}>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|