@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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Primitive } from '../type/primitive-type.js';
|
|
2
|
+
import { type Jsonify } from './jsonify.js';
|
|
2
3
|
/**
|
|
3
4
|
* These are similar in purpose, name, and structure to type-fest's JsonValue types but these are
|
|
4
5
|
* more permissive. The goal here is to allow any types that do not get serialized into just empty
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches a JSON object.
|
|
3
|
+
*
|
|
4
|
+
* Copied from the `JsonObject` type in the `type-fest` package so that this package's public types
|
|
5
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
6
|
+
*
|
|
7
|
+
* @category JSON
|
|
8
|
+
* @category Package : @augment-vir/common
|
|
9
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
|
+
*/
|
|
11
|
+
export type JsonObject = {
|
|
12
|
+
[Key in string]: JsonValue;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Matches a JSON array.
|
|
16
|
+
*
|
|
17
|
+
* Copied from the `JsonArray` type in the `type-fest` package so that this package's public types
|
|
18
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
19
|
+
*
|
|
20
|
+
* @category JSON
|
|
21
|
+
* @category Package : @augment-vir/common
|
|
22
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
23
|
+
*/
|
|
24
|
+
export type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
25
|
+
/**
|
|
26
|
+
* Matches any valid JSON primitive value.
|
|
27
|
+
*
|
|
28
|
+
* Copied from the `JsonPrimitive` type in the `type-fest` package so that this package's public
|
|
29
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
30
|
+
*
|
|
31
|
+
* @category JSON
|
|
32
|
+
* @category Package : @augment-vir/common
|
|
33
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
34
|
+
*/
|
|
35
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
36
|
+
/**
|
|
37
|
+
* Matches any valid JSON value.
|
|
38
|
+
*
|
|
39
|
+
* Copied from the `JsonValue` 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 JSON
|
|
43
|
+
* @category Package : @augment-vir/common
|
|
44
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
45
|
+
*/
|
|
46
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type NegativeInfinity, type PositiveInfinity } from '../number/infinity.js';
|
|
2
|
+
import { type EmptyObject } from '../type/empty-object.js';
|
|
3
|
+
import { type IsUnknown } from '../type/is-unknown.js';
|
|
4
|
+
import { type IsAny, type IsNever } from '../type/type-checks.js';
|
|
5
|
+
import { type TypedArray } from '../type/typed-array.js';
|
|
6
|
+
import { type UndefinedToOptional } from '../type/undefined-to-optional.js';
|
|
7
|
+
import { type UnknownArray } from '../type/unknown-array.js';
|
|
8
|
+
import { type JsonPrimitive, type JsonValue } from './json-value.js';
|
|
9
|
+
type NotJsonable = ((...arguments_: any[]) => any) | undefined | symbol;
|
|
10
|
+
type NeverToNull<T> = IsNever<T> extends true ? null : T;
|
|
11
|
+
type UndefinedToNull<T> = T extends undefined ? null : T;
|
|
12
|
+
type JsonifyList<T extends UnknownArray> = T extends readonly [] ? [] : T extends readonly [
|
|
13
|
+
infer F,
|
|
14
|
+
...infer R
|
|
15
|
+
] ? [
|
|
16
|
+
F,
|
|
17
|
+
...R
|
|
18
|
+
] extends T ? [
|
|
19
|
+
NeverToNull<Jsonify<F>>,
|
|
20
|
+
...JsonifyList<R>
|
|
21
|
+
] : [NeverToNull<Jsonify<F>>] : IsUnknown<T[number]> extends true ? JsonValue[] : Array<T[number] extends NotJsonable ? null : Jsonify<UndefinedToNull<T[number]>>>;
|
|
22
|
+
type FilterJsonableKeys<T extends object> = {
|
|
23
|
+
[Key in keyof T]: T[Key] extends NotJsonable ? never : Key;
|
|
24
|
+
}[keyof T];
|
|
25
|
+
type JsonifyObject<T extends object> = {
|
|
26
|
+
[Key in keyof Pick<T, FilterJsonableKeys<T>>]: Jsonify<T[Key]>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Transform a type to one that is assignable to the `JsonValue` type.
|
|
30
|
+
*
|
|
31
|
+
* Copied from the `Jsonify` type in the `type-fest` package so that this package's public types do
|
|
32
|
+
* not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
33
|
+
*
|
|
34
|
+
* @category JSON
|
|
35
|
+
* @category Package : @augment-vir/common
|
|
36
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
37
|
+
*/
|
|
38
|
+
export type Jsonify<T> = IsAny<T> extends true ? any : T extends PositiveInfinity | NegativeInfinity ? null : T extends JsonPrimitive ? T : T extends {
|
|
39
|
+
toJSON(): infer J;
|
|
40
|
+
} ? (() => J) extends () => JsonValue ? J : Jsonify<J> : T extends Number ? number : T extends String ? string : T extends Boolean ? boolean : T extends Map<any, any> | Set<any> ? EmptyObject : T extends TypedArray ? Record<string, number> : T extends NotJsonable ? never : T extends UnknownArray ? JsonifyList<T> : T extends object ? JsonifyObject<UndefinedToOptional<T>> : IsUnknown<T> extends true ? JsonValue : never;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches the hidden `Infinity` type.
|
|
3
|
+
*
|
|
4
|
+
* Copied from the `PositiveInfinity` 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 Number
|
|
8
|
+
* @category Package : @augment-vir/common
|
|
9
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
|
+
*/
|
|
11
|
+
export type PositiveInfinity = 1e999;
|
|
12
|
+
/**
|
|
13
|
+
* Matches the hidden `-Infinity` type.
|
|
14
|
+
*
|
|
15
|
+
* Copied from the `NegativeInfinity` type in the `type-fest` package so that this package's public
|
|
16
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
17
|
+
*
|
|
18
|
+
* @category Number
|
|
19
|
+
* @category Package : @augment-vir/common
|
|
20
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
21
|
+
*/
|
|
22
|
+
export type NegativeInfinity = -1e999;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Except
|
|
2
|
-
|
|
1
|
+
import { type Except } from '../type/except.js';
|
|
2
|
+
import { type Simplify } from '../type/simplify.js';
|
|
3
3
|
/**
|
|
4
4
|
* Same as the Required<> built-in type helper but this requires that each property be present and
|
|
5
5
|
* be not null.
|
|
@@ -50,9 +50,9 @@ export type SetOptionalWithUndefined<OriginalObjectGeneric, OptionalKeysGeneric
|
|
|
50
50
|
* @category Package : @augment-vir/common
|
|
51
51
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
52
52
|
*/
|
|
53
|
-
export type RequiredKeysOf<BaseType> =
|
|
54
|
-
[Key in keyof BaseType
|
|
55
|
-
}
|
|
53
|
+
export type RequiredKeysOf<BaseType> = keyof {
|
|
54
|
+
[Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? Key : never]: never;
|
|
55
|
+
} & keyof BaseType;
|
|
56
56
|
/**
|
|
57
57
|
* Requires every part of an object, even the indexed keys. This is needed because
|
|
58
58
|
* `Required<Partial<T>>` doesn't fully remove `| undefined` from indexed keys when the
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Primitive } from './primitive-type.js';
|
|
2
|
+
/**
|
|
3
|
+
* Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
4
|
+
*
|
|
5
|
+
* Copied from the internal `BuiltIns` 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 BuiltIns = Primitive | void | Date | RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* Tests if the given function has multiple call signatures. Needed to handle the case of a single
|
|
15
|
+
* call signature with properties, as multiple call signatures cannot currently be supported due to
|
|
16
|
+
* a TypeScript limitation.
|
|
17
|
+
*
|
|
18
|
+
* Copied from the internal `HasMultipleCallSignatures` type in the `type-fest` package so that this
|
|
19
|
+
* package's public types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
20
|
+
*
|
|
21
|
+
* @category Type
|
|
22
|
+
* @category Package : @augment-vir/common
|
|
23
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
24
|
+
*/
|
|
25
|
+
export type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
|
|
26
|
+
(...arguments_: infer A): unknown;
|
|
27
|
+
(...arguments_: infer B): unknown;
|
|
28
|
+
} ? B extends A ? A extends B ? false : true : true : false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type IsNever } from './type-checks.js';
|
|
2
|
+
/**
|
|
3
|
+
* An if-else-like type that resolves depending on whether the given `boolean` type is `true` or
|
|
4
|
+
* `false`. Returns the else branch when the given type is `never`.
|
|
5
|
+
*
|
|
6
|
+
* Copied from the `If` type in the `type-fest` package so that this package's public types do not
|
|
7
|
+
* depend on `type-fest` (see the note in `type-checks.ts`).
|
|
8
|
+
*
|
|
9
|
+
* @category Type
|
|
10
|
+
* @category Package : @augment-vir/common
|
|
11
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
12
|
+
*/
|
|
13
|
+
export type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches a class constructor.
|
|
3
|
+
*
|
|
4
|
+
* Copied from the `Constructor` type in the `type-fest` package so that this package's public types
|
|
5
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
6
|
+
*
|
|
7
|
+
* @category Function
|
|
8
|
+
* @category Package : @augment-vir/common
|
|
9
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
|
+
*/
|
|
11
|
+
export type Constructor<T, Arguments extends unknown[] = any[]> = new (...constructorArguments: Arguments) => T;
|
|
12
|
+
/**
|
|
13
|
+
* Matches a class constructor with an abstract signature.
|
|
14
|
+
*
|
|
15
|
+
* Copied from the `AbstractConstructor` type in the `type-fest` package so that this package's
|
|
16
|
+
* public types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
17
|
+
*
|
|
18
|
+
* @category Function
|
|
19
|
+
* @category Package : @augment-vir/common
|
|
20
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
21
|
+
*/
|
|
22
|
+
export type AbstractConstructor<T, Arguments extends unknown[] = any[]> = abstract new (...constructorArguments: Arguments) => T;
|
|
23
|
+
/**
|
|
24
|
+
* Matches a
|
|
25
|
+
* [`class`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/class).
|
|
26
|
+
*
|
|
27
|
+
* Copied from the `Class` type in the `type-fest` package so that this package's public types do
|
|
28
|
+
* not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
29
|
+
*
|
|
30
|
+
* @category Function
|
|
31
|
+
* @category Package : @augment-vir/common
|
|
32
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
33
|
+
*/
|
|
34
|
+
export type Class<T, Arguments extends unknown[] = any[]> = {
|
|
35
|
+
prototype: Pick<T, keyof T>;
|
|
36
|
+
new (...constructorArguments: Arguments): T;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Matches an [`abstract
|
|
40
|
+
* class`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Classes#abstract_classes).
|
|
41
|
+
*
|
|
42
|
+
* Copied from the `AbstractClass` type in the `type-fest` package so that this package's public
|
|
43
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
44
|
+
*
|
|
45
|
+
* @category Function
|
|
46
|
+
* @category Package : @augment-vir/common
|
|
47
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
48
|
+
*/
|
|
49
|
+
export type AbstractClass<T, Arguments extends unknown[] = any[]> = AbstractConstructor<T, Arguments> & {
|
|
50
|
+
prototype: Pick<T, keyof T>;
|
|
51
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type KeysOfUnion } from './keys-of-union.js';
|
|
2
|
+
/**
|
|
3
|
+
* Omits keys from a type, distributing the operation over a union. Unlike the built-in `Omit`, this
|
|
4
|
+
* retains member-specific properties of each union member.
|
|
5
|
+
*
|
|
6
|
+
* Copied from the `DistributedOmit` type in the `type-fest` package so that this package's public
|
|
7
|
+
* types do not depend on `type-fest` (see the 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 DistributedOmit<ObjectType, KeyType extends KeysOfUnion<ObjectType>> = ObjectType extends unknown ? Omit<ObjectType, KeyType> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const emptyObjectSymbol: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* Represents a strictly empty plain object, the `{}` value.
|
|
4
|
+
*
|
|
5
|
+
* Copied from the `EmptyObject` type in the `type-fest` package so that this package's public types
|
|
6
|
+
* 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 EmptyObject = {
|
|
13
|
+
[emptyObjectSymbol]?: never;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Returns a boolean for whether the type is strictly equal to an empty plain object, the `{}`
|
|
17
|
+
* value.
|
|
18
|
+
*
|
|
19
|
+
* Copied from the `IsEmptyObject` type in the `type-fest` package so that this package's public
|
|
20
|
+
* types do 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 IsEmptyObject<T> = T extends EmptyObject ? true : false;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type IsUnknown } from './is-unknown.js';
|
|
2
|
+
import { type KeysOfUnion } from './keys-of-union.js';
|
|
3
|
+
import { type Primitive } from './primitive-type.js';
|
|
4
|
+
import { type IsEqual } from './type-checks.js';
|
|
5
|
+
type ToString<T> = T extends string | number ? `${T}` : never;
|
|
6
|
+
type ArrayElementOf<T> = T extends readonly (infer ElementType)[] ? ElementType : never;
|
|
7
|
+
type ObjectValue<T, K> = K extends keyof T ? T[K] : ToString<K> extends keyof T ? T[ToString<K>] : K extends `${infer NumberK extends number}` ? NumberK extends keyof T ? T[NumberK] : never : never;
|
|
8
|
+
type ExactObject<ParameterType, InputType> = {
|
|
9
|
+
[Key in keyof ParameterType]: Exact<ParameterType[Key], ObjectValue<InputType, Key>>;
|
|
10
|
+
} & Record<Exclude<keyof InputType, KeysOfUnion<ParameterType>>, never>;
|
|
11
|
+
/**
|
|
12
|
+
* Create a type that does not allow extra properties, meaning it only allows properties that are
|
|
13
|
+
* explicitly declared.
|
|
14
|
+
*
|
|
15
|
+
* Copied from the `Exact` type in the `type-fest` package so that this package's public types do
|
|
16
|
+
* 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 Exact<ParameterType, InputType> = IsEqual<ParameterType, InputType> extends true ? ParameterType : ParameterType extends Primitive ? ParameterType : IsUnknown<ParameterType> extends true ? unknown : ParameterType extends Function ? ParameterType : ParameterType extends unknown[] ? Array<Exact<ArrayElementOf<ParameterType>, ArrayElementOf<InputType>>> : ParameterType extends readonly unknown[] ? ReadonlyArray<Exact<ArrayElementOf<ParameterType>, ArrayElementOf<InputType>>> : ExactObject<ParameterType, InputType>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type IsEqual } from './type-checks.js';
|
|
2
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : KeyType extends ExcludeType ? never : KeyType;
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link Except}.
|
|
5
|
+
*
|
|
6
|
+
* Copied from the `ExceptOptions` type in the `type-fest` package so that this package's public
|
|
7
|
+
* types do not depend on `type-fest` (see the 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 ExceptOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* Disallow assigning non-specified properties.
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
requireExactProps?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Create a type from an object type without certain keys. This is a stricter version of the
|
|
23
|
+
* built-in `Omit` type: it restricts the omitted keys to keys present on the given type.
|
|
24
|
+
*
|
|
25
|
+
* Copied from the `Except` type in the `type-fest` package so that this package's public types do
|
|
26
|
+
* not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
27
|
+
*
|
|
28
|
+
* @category Object
|
|
29
|
+
* @category Package : @augment-vir/common
|
|
30
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
31
|
+
*/
|
|
32
|
+
export type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = {
|
|
33
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
34
|
+
} & (Options extends {
|
|
35
|
+
requireExactProps: true;
|
|
36
|
+
} ? Partial<Record<KeysType, never>> : {});
|
|
37
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a boolean for whether the given type is `null`.
|
|
3
|
+
*
|
|
4
|
+
* Copied from the `IsNull` type in the `type-fest` package so that this package's public types do
|
|
5
|
+
* 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 IsNull<T> = [T] extends [null] ? true : false;
|
|
12
|
+
/**
|
|
13
|
+
* Returns a boolean for whether the given type is `unknown`.
|
|
14
|
+
*
|
|
15
|
+
* Copied from the `IsUnknown` type in the `type-fest` package so that this package's public types
|
|
16
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
17
|
+
*
|
|
18
|
+
* @category Type
|
|
19
|
+
* @category Package : @augment-vir/common
|
|
20
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
21
|
+
*/
|
|
22
|
+
export type IsUnknown<T> = unknown extends T ? (IsNull<T> extends false ? true : false) : false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type UnionToIntersection } from './union-to-intersection.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
4
|
+
* Unlike the native `keyof` keyword, which returns keys present in _all_ union members, this type
|
|
5
|
+
* returns keys from _any_ member.
|
|
6
|
+
*
|
|
7
|
+
* Copied from the `KeysOfUnion` type in the `type-fest` package so that this package's public types
|
|
8
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
9
|
+
*
|
|
10
|
+
* @category Object
|
|
11
|
+
* @category Package : @augment-vir/common
|
|
12
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
13
|
+
*/
|
|
14
|
+
export type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Primitive } from './primitive-type.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a union type by combining primitive types and literal types without sacrificing
|
|
4
|
+
* auto-completion in IDEs for the literal type part of the union.
|
|
5
|
+
*
|
|
6
|
+
* Copied from the `LiteralUnion` type in the `type-fest` package so that this package's public
|
|
7
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
8
|
+
*
|
|
9
|
+
* @category Type
|
|
10
|
+
* @category Package : @augment-vir/common
|
|
11
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
12
|
+
*/
|
|
13
|
+
export type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blocks empty string literal types. Use this to constrain a string type parameter so that the
|
|
3
|
+
* empty string is rejected.
|
|
4
|
+
*
|
|
5
|
+
* @category Type
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
8
|
+
*/
|
|
9
|
+
export type NonEmptyString<T> = T extends '' ? never : T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|