type-fest 5.4.4 → 5.6.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/index.d.ts +10 -0
- package/package.json +6 -4
- package/readme.md +83 -58
- package/source/absolute.d.ts +52 -0
- package/source/all-extend.d.ts +5 -6
- package/source/all-union-fields.d.ts +18 -18
- package/source/and-all.d.ts +76 -0
- package/source/and.d.ts +4 -3
- package/source/array-length.d.ts +36 -0
- package/source/array-splice.d.ts +26 -26
- package/source/camel-case.d.ts +38 -5
- package/source/camel-cased-properties-deep.d.ts +11 -4
- package/source/camel-cased-properties.d.ts +5 -1
- package/source/conditional-pick-deep.d.ts +5 -3
- package/source/conditional-pick.d.ts +6 -4
- package/source/delimiter-case.d.ts +1 -0
- package/source/delimiter-cased-properties-deep.d.ts +8 -1
- package/source/delimiter-cased-properties.d.ts +5 -1
- package/source/empty-object.d.ts +1 -1
- package/source/entries.d.ts +1 -1
- package/source/entry.d.ts +1 -1
- package/source/exclude-exactly.d.ts +57 -0
- package/source/get.d.ts +1 -1
- package/source/greater-than-or-equal.d.ts +34 -1
- package/source/greater-than.d.ts +37 -3
- package/source/has-optional-keys.d.ts +1 -1
- package/source/has-readonly-keys.d.ts +1 -1
- package/source/has-required-keys.d.ts +1 -1
- package/source/has-writable-keys.d.ts +1 -1
- package/source/int-closed-range.d.ts +1 -3
- package/source/int-range.d.ts +3 -5
- package/source/internal/array.d.ts +7 -14
- package/source/internal/keys.d.ts +9 -9
- package/source/internal/numeric.d.ts +13 -23
- package/source/internal/tuple.d.ts +3 -3
- package/source/internal/type.d.ts +1 -0
- package/source/is-equal.d.ts +0 -1
- package/source/is-integer.d.ts +8 -8
- package/source/is-literal.d.ts +5 -5
- package/source/is-union.d.ts +12 -12
- package/source/iterable-element.d.ts +5 -5
- package/source/jsonify.d.ts +4 -4
- package/source/kebab-case.d.ts +1 -0
- package/source/kebab-cased-properties-deep.d.ts +7 -0
- package/source/kebab-cased-properties.d.ts +5 -1
- package/source/keys-of-union.d.ts +2 -2
- package/source/less-than-or-equal.d.ts +40 -4
- package/source/less-than.d.ts +35 -3
- package/source/literal-to-primitive.d.ts +1 -1
- package/source/literal-union.d.ts +1 -1
- package/source/merge-exclusive.d.ts +3 -3
- package/source/merge.d.ts +25 -0
- package/source/multidimensional-array.d.ts +1 -1
- package/source/multidimensional-readonly-array.d.ts +1 -1
- package/source/non-nullable-deep.d.ts +102 -0
- package/source/numeric.d.ts +3 -3
- package/source/omit-deep.d.ts +22 -23
- package/source/optional.d.ts +31 -0
- package/source/or-all.d.ts +73 -0
- package/source/or.d.ts +4 -11
- package/source/package-json.d.ts +7 -7
- package/source/partial-deep.d.ts +3 -1
- package/source/pascal-case.d.ts +1 -0
- package/source/pascal-cased-properties-deep.d.ts +7 -0
- package/source/pascal-cased-properties.d.ts +5 -1
- package/source/pick-deep.d.ts +8 -21
- package/source/readonly-deep.d.ts +5 -3
- package/source/remove-prefix.d.ts +15 -15
- package/source/replace.d.ts +2 -2
- package/source/require-all-or-none.d.ts +1 -1
- package/source/require-at-least-one.d.ts +5 -7
- package/source/require-exactly-one.d.ts +3 -3
- package/source/require-one-or-none.d.ts +1 -1
- package/source/required-deep.d.ts +3 -1
- package/source/screaming-snake-case.d.ts +1 -0
- package/source/set-non-nullable-deep.d.ts +6 -3
- package/source/set-non-nullable.d.ts +4 -11
- package/source/set-optional.d.ts +6 -10
- package/source/set-parameter-type.d.ts +2 -2
- package/source/set-readonly.d.ts +4 -8
- package/source/set-required-deep.d.ts +1 -1
- package/source/set-required.d.ts +4 -8
- package/source/shared-union-fields-deep.d.ts +1 -1
- package/source/shared-union-fields.d.ts +9 -9
- package/source/snake-case.d.ts +1 -0
- package/source/snake-cased-properties-deep.d.ts +7 -0
- package/source/snake-cased-properties.d.ts +5 -1
- package/source/some-extend.d.ts +113 -0
- package/source/spread.d.ts +1 -5
- package/source/subtract.d.ts +4 -3
- package/source/sum.d.ts +5 -4
- package/source/tagged.d.ts +5 -7
- package/source/tsconfig-json.d.ts +39 -7
- package/source/union-length.d.ts +27 -0
- package/source/union-member.d.ts +65 -0
- package/source/union-to-intersection.d.ts +1 -1
- package/source/union-to-tuple.d.ts +10 -19
- package/source/words.d.ts +30 -4
- package/source/writable.d.ts +15 -19
- package/source/xor.d.ts +1 -1
|
@@ -1,19 +1,7 @@
|
|
|
1
|
+
import type {ExcludeExactly} from './exclude-exactly.d.ts';
|
|
1
2
|
import type {IsNever} from './is-never.d.ts';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
Returns the last element of a union type.
|
|
6
|
-
|
|
7
|
-
@example
|
|
8
|
-
```
|
|
9
|
-
type Last = LastOfUnion<1 | 2 | 3>;
|
|
10
|
-
//=> 3
|
|
11
|
-
```
|
|
12
|
-
*/
|
|
13
|
-
type LastOfUnion<T> =
|
|
14
|
-
UnionToIntersection<T extends any ? () => T : never> extends () => (infer R)
|
|
15
|
-
? R
|
|
16
|
-
: never;
|
|
3
|
+
import type {UnionMember} from './union-member.d.ts';
|
|
4
|
+
import type {UnknownArray} from './unknown-array.d.ts';
|
|
17
5
|
|
|
18
6
|
/**
|
|
19
7
|
Convert a union type into an unordered tuple type of its elements.
|
|
@@ -50,9 +38,12 @@ const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
|
50
38
|
|
|
51
39
|
@category Array
|
|
52
40
|
*/
|
|
53
|
-
export type UnionToTuple<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
export type UnionToTuple<Union> =
|
|
42
|
+
_UnionToTuple<Union> extends infer Result extends UnknownArray ? Result : never; // Nudges the compiler that `UnionToTuple` always yields an array.
|
|
43
|
+
|
|
44
|
+
type _UnionToTuple<Union, Accumulator extends UnknownArray = [], Member = UnionMember<Union>> =
|
|
45
|
+
IsNever<Union> extends true
|
|
46
|
+
? Accumulator
|
|
47
|
+
: _UnionToTuple<ExcludeExactly<Union, Member>, [Member, ...Accumulator]>;
|
|
57
48
|
|
|
58
49
|
export {};
|
package/source/words.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ApplyDefaultOptions,
|
|
3
|
+
AsciiPunctuation,
|
|
3
4
|
IsNumeric,
|
|
4
5
|
WordSeparators,
|
|
5
6
|
} from './internal/index.d.ts';
|
|
@@ -38,17 +39,34 @@ export type WordsOptions = {
|
|
|
38
39
|
```
|
|
39
40
|
*/
|
|
40
41
|
splitOnNumbers?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
Split on {@link AsciiPunctuation | punctuation characters} (e.g., `#`, `&`, `*`, `:`, `?`, `@`, `~`).
|
|
44
|
+
|
|
45
|
+
@example
|
|
46
|
+
```
|
|
47
|
+
import type {Words} from 'type-fest';
|
|
48
|
+
|
|
49
|
+
type Example1 = Words<'hello:world', {splitOnPunctuation: true}>;
|
|
50
|
+
//=> ['hello', 'world']
|
|
51
|
+
|
|
52
|
+
type Example2 = Words<'hello:world', {splitOnPunctuation: false}>;
|
|
53
|
+
//=> ['hello', ':world']
|
|
54
|
+
```
|
|
55
|
+
*/
|
|
56
|
+
splitOnPunctuation?: boolean;
|
|
41
57
|
};
|
|
42
58
|
|
|
43
59
|
export type _DefaultWordsOptions = {
|
|
44
60
|
splitOnNumbers: true;
|
|
61
|
+
splitOnPunctuation: false;
|
|
45
62
|
};
|
|
46
63
|
|
|
47
64
|
/**
|
|
48
|
-
Split a string
|
|
65
|
+
Split a string similar to Lodash's `_.words()` function.
|
|
49
66
|
|
|
50
67
|
- Split on each word that begins with a capital letter.
|
|
51
68
|
- Split on each {@link WordSeparators}.
|
|
69
|
+
- Split on each {@link AsciiPunctuation} (if {@link WordsOptions.splitOnPunctuation} is enabled).
|
|
52
70
|
- Split on numeric sequence.
|
|
53
71
|
|
|
54
72
|
@example
|
|
@@ -72,13 +90,21 @@ type Words4 = Words<'lifeIs42'>;
|
|
|
72
90
|
|
|
73
91
|
type Words5 = Words<'p2pNetwork', {splitOnNumbers: false}>;
|
|
74
92
|
//=> ['p2p', 'Network']
|
|
93
|
+
|
|
94
|
+
type Words6 = Words<'hello:world', {splitOnPunctuation: true}>;
|
|
95
|
+
//=> ['hello', 'world']
|
|
96
|
+
|
|
97
|
+
type Words7 = Words<'hello:world', {splitOnPunctuation: false}>;
|
|
98
|
+
//=> ['hello', ':world']
|
|
99
|
+
|
|
100
|
+
type Words8 = Words<'hello::world', {splitOnPunctuation: true}>;
|
|
101
|
+
//=> ['hello', 'world']
|
|
75
102
|
```
|
|
76
103
|
|
|
77
104
|
@category Change case
|
|
78
105
|
@category Template literal
|
|
79
106
|
*/
|
|
80
|
-
export type Words<Sentence extends string, Options extends WordsOptions = {}> =
|
|
81
|
-
WordsImplementation<Sentence, ApplyDefaultOptions<WordsOptions, _DefaultWordsOptions, Options>>;
|
|
107
|
+
export type Words<Sentence extends string, Options extends WordsOptions = {}> = WordsImplementation<Sentence, ApplyDefaultOptions<WordsOptions, _DefaultWordsOptions, Options>>;
|
|
82
108
|
|
|
83
109
|
type WordsImplementation<
|
|
84
110
|
Sentence extends string,
|
|
@@ -86,7 +112,7 @@ type WordsImplementation<
|
|
|
86
112
|
LastCharacter extends string = '',
|
|
87
113
|
CurrentWord extends string = '',
|
|
88
114
|
> = Sentence extends `${infer FirstCharacter}${infer RemainingCharacters}`
|
|
89
|
-
? FirstCharacter extends WordSeparators
|
|
115
|
+
? FirstCharacter extends WordSeparators | (Options['splitOnPunctuation'] extends true ? AsciiPunctuation : never)
|
|
90
116
|
// Skip word separator
|
|
91
117
|
? [...SkipEmptyWord<CurrentWord>, ...WordsImplementation<RemainingCharacters, Options>]
|
|
92
118
|
: LastCharacter extends ''
|
package/source/writable.d.ts
CHANGED
|
@@ -37,11 +37,7 @@ writableFoo.b[0] = 'new value'; // Will still fail as the value of property "b"
|
|
|
37
37
|
writableFoo.b = ['something']; // Will work as the "b" property itself is no longer readonly.
|
|
38
38
|
|
|
39
39
|
type SomeWritable = Writable<Foo, 'b' | 'c'>;
|
|
40
|
-
|
|
41
|
-
// readonly a: number;
|
|
42
|
-
// b: readonly string[]; // It's now writable. The type of the property remains unaffected.
|
|
43
|
-
// c: boolean; // It's now writable.
|
|
44
|
-
// }
|
|
40
|
+
//=> {readonly a: number; b: readonly string[]; c: boolean}
|
|
45
41
|
|
|
46
42
|
// Also supports array
|
|
47
43
|
const readonlyArray: readonly number[] = [1, 2, 3];
|
|
@@ -54,19 +50,19 @@ writableArray.push(4); // Will work as the array itself is now writable.
|
|
|
54
50
|
@category Object
|
|
55
51
|
*/
|
|
56
52
|
export type Writable<BaseType, Keys extends keyof BaseType = keyof BaseType> =
|
|
57
|
-
BaseType extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
BaseType extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
54
|
+
? Map<KeyType, ValueType>
|
|
55
|
+
: BaseType extends ReadonlySet<infer ItemType>
|
|
56
|
+
? Set<ItemType>
|
|
57
|
+
: BaseType extends readonly unknown[]
|
|
58
|
+
// Handle array
|
|
59
|
+
? WritableArray<BaseType>
|
|
60
|
+
// Handle object
|
|
61
|
+
: Simplify<
|
|
62
|
+
// Pick just the keys that are not writable from the base type.
|
|
63
|
+
Except<BaseType, Keys>
|
|
64
|
+
// Pick the keys that should be writable from the base type and make them writable by removing the `readonly` modifier from the key.
|
|
65
|
+
& {-readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType]}
|
|
66
|
+
>;
|
|
71
67
|
|
|
72
68
|
export {};
|
package/source/xor.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type {And} from './and.d.ts';
|
|
|
3
3
|
import type {Or} from './or.d.ts';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
Returns a boolean for whether only one of two given types is true
|
|
6
|
+
Returns a boolean for whether only one of two given types is `true`.
|
|
7
7
|
|
|
8
8
|
Use-case: Constructing complex conditional types where one single condition must be satisfied.
|
|
9
9
|
|