type-fest 3.5.1 → 3.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "3.5.1",
3
+ "version": "3.5.3",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
package/source/exact.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type {KeysOfUnion, ArrayElement, ObjectValue} from './internal';
2
2
  import type {Opaque} from './opaque';
3
+ import type {IsEqual} from './is-equal';
3
4
 
4
5
  /**
5
6
  Create a type from `ParameterType` and `InputType` and change keys exclusive to `InputType` to `never`.
@@ -50,11 +51,12 @@ onlyAcceptNameImproved(invalidInput); // Compilation error
50
51
  @category Utilities
51
52
  */
52
53
  export type Exact<ParameterType, InputType> =
53
- // Convert union of array to array of union: A[] & B[] => (A & B)[]
54
- ParameterType extends unknown[] ? Array<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>>
55
- // In TypeScript, Array is a subtype of ReadonlyArray, so always test Array before ReadonlyArray.
56
- : ParameterType extends readonly unknown[] ? ReadonlyArray<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>>
57
- // For Opaque types, internal details are hidden from public, so let's leave it as is.
58
- : ParameterType extends Opaque<infer OpaqueType, infer OpaqueToken> ? ParameterType
59
- : ParameterType extends object ? ExactObject<ParameterType, InputType>
60
- : ParameterType;
54
+ IsEqual<ParameterType, InputType> extends true ? ParameterType
55
+ // Convert union of array to array of union: A[] & B[] => (A & B)[]
56
+ : ParameterType extends unknown[] ? Array<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>>
57
+ // In TypeScript, Array is a subtype of ReadonlyArray, so always test Array before ReadonlyArray.
58
+ : ParameterType extends readonly unknown[] ? ReadonlyArray<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>>
59
+ // For Opaque types, internal details are hidden from public, so let's leave it as is.
60
+ : ParameterType extends Opaque<infer OpaqueType, infer OpaqueToken> ? ParameterType
61
+ : ParameterType extends object ? ExactObject<ParameterType, InputType>
62
+ : ParameterType;
@@ -1,5 +1,6 @@
1
1
  import type {Primitive} from './primitive';
2
2
  import type {Simplify} from './simplify';
3
+ import type {Trim} from './trim';
3
4
 
4
5
  /**
5
6
  Infer the length of the given array `<T>`.
@@ -43,10 +44,38 @@ export type KeysOfUnion<T> = T extends T ? keyof T : never;
43
44
 
44
45
  export type UpperCaseCharacters = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
45
46
 
46
- export type WordSeparators = '-' | '_' | ' ';
47
-
48
47
  export type StringDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
49
48
 
49
+ export type Whitespace =
50
+ | '\u{9}' // '\t'
51
+ | '\u{A}' // '\n'
52
+ | '\u{B}' // '\v'
53
+ | '\u{C}' // '\f'
54
+ | '\u{D}' // '\r'
55
+ | '\u{20}' // ' '
56
+ | '\u{85}'
57
+ | '\u{A0}'
58
+ | '\u{1680}'
59
+ | '\u{2000}'
60
+ | '\u{2001}'
61
+ | '\u{2002}'
62
+ | '\u{2003}'
63
+ | '\u{2004}'
64
+ | '\u{2005}'
65
+ | '\u{2006}'
66
+ | '\u{2007}'
67
+ | '\u{2008}'
68
+ | '\u{2009}'
69
+ | '\u{200A}'
70
+ | '\u{2028}'
71
+ | '\u{2029}'
72
+ | '\u{202F}'
73
+ | '\u{205F}'
74
+ | '\u{3000}'
75
+ | '\u{FEFF}';
76
+
77
+ export type WordSeparators = '-' | '_' | Whitespace;
78
+
50
79
  /**
51
80
  Matches any unknown record.
52
81
  */
@@ -109,10 +138,25 @@ Returns a boolean for whether the string is uppercased.
109
138
  */
110
139
  export type IsUpperCase<T extends string> = T extends Uppercase<T> ? true : false;
111
140
 
141
+ /**
142
+ Returns a boolean for whether a string is whitespace.
143
+ */
144
+ export type IsWhitespace<T extends string> = T extends Whitespace
145
+ ? true
146
+ : T extends `${Whitespace}${infer Rest}`
147
+ ? IsWhitespace<Rest>
148
+ : false;
149
+
112
150
  /**
113
151
  Returns a boolean for whether the string is numeric.
152
+
153
+ This type is a workaround for [Microsoft/TypeScript#46109](https://github.com/microsoft/TypeScript/issues/46109#issuecomment-930307987).
114
154
  */
115
- export type IsNumeric<T extends string> = T extends `${number}` ? true : false;
155
+ export type IsNumeric<T extends string> = T extends `${number}`
156
+ ? Trim<T> extends T
157
+ ? true
158
+ : false
159
+ : false;
116
160
 
117
161
  /**
118
162
  Returns a boolean for whether the the type is `any`.
@@ -33,7 +33,7 @@ export type SplitWords<
33
33
  > = Sentence extends `${infer FirstCharacter}${infer RemainingCharacters}`
34
34
  ? FirstCharacter extends WordSeparators
35
35
  // Skip word separator
36
- ? [...SkipEmptyWord<CurrentWord>, ...SplitWords<RemainingCharacters, LastCharacter>]
36
+ ? [...SkipEmptyWord<CurrentWord>, ...SplitWords<RemainingCharacters>]
37
37
  : LastCharacter extends ''
38
38
  // Fist char of word
39
39
  ? SplitWords<RemainingCharacters, FirstCharacter, FirstCharacter>
package/source/trim.d.ts CHANGED
@@ -1,12 +1,14 @@
1
+ import type {Whitespace} from './internal';
2
+
1
3
  /**
2
4
  Remove spaces from the left side.
3
5
  */
4
- type TrimLeft<V extends string> = V extends ` ${infer R}` ? TrimLeft<R> : V;
6
+ type TrimLeft<V extends string> = V extends `${Whitespace}${infer R}` ? TrimLeft<R> : V;
5
7
 
6
8
  /**
7
9
  Remove spaces from the right side.
8
10
  */
9
- type TrimRight<V extends string> = V extends `${infer R} ` ? TrimRight<R> : V;
11
+ type TrimRight<V extends string> = V extends `${infer R}${Whitespace}` ? TrimRight<R> : V;
10
12
 
11
13
  /**
12
14
  Remove leading and trailing spaces from a string.