type-fest 3.5.1 → 3.5.2
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 +1 -1
- package/source/internal.d.ts +47 -3
- package/source/split-words.d.ts +1 -1
- package/source/trim.d.ts +4 -2
package/package.json
CHANGED
package/source/internal.d.ts
CHANGED
|
@@ -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}`
|
|
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`.
|
package/source/split-words.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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}
|
|
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.
|