type-fest
Advanced tools
Comparing version 3.5.1 to 3.5.2
{ | ||
"name": "type-fest", | ||
"version": "3.5.1", | ||
"version": "3.5.2", | ||
"description": "A collection of essential TypeScript types", | ||
@@ -5,0 +5,0 @@ "license": "(MIT OR CC0-1.0)", |
import type {Primitive} from './primitive'; | ||
import type {Simplify} from './simplify'; | ||
import type {Trim} from './trim'; | ||
@@ -46,6 +47,34 @@ /** | ||
export type WordSeparators = '-' | '_' | ' '; | ||
export type StringDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'; | ||
export type Whitespace = | ||
| '\u{9}' // '\t' | ||
| '\u{A}' // '\n' | ||
| '\u{B}' // '\v' | ||
| '\u{C}' // '\f' | ||
| '\u{D}' // '\r' | ||
| '\u{20}' // ' ' | ||
| '\u{85}' | ||
| '\u{A0}' | ||
| '\u{1680}' | ||
| '\u{2000}' | ||
| '\u{2001}' | ||
| '\u{2002}' | ||
| '\u{2003}' | ||
| '\u{2004}' | ||
| '\u{2005}' | ||
| '\u{2006}' | ||
| '\u{2007}' | ||
| '\u{2008}' | ||
| '\u{2009}' | ||
| '\u{200A}' | ||
| '\u{2028}' | ||
| '\u{2029}' | ||
| '\u{202F}' | ||
| '\u{205F}' | ||
| '\u{3000}' | ||
| '\u{FEFF}'; | ||
export type WordSeparators = '-' | '_' | Whitespace; | ||
/** | ||
@@ -114,5 +143,20 @@ Matches any unknown record. | ||
/** | ||
Returns a boolean for whether a string is whitespace. | ||
*/ | ||
export type IsWhitespace<T extends string> = T extends Whitespace | ||
? true | ||
: T extends `${Whitespace}${infer Rest}` | ||
? IsWhitespace<Rest> | ||
: false; | ||
/** | ||
Returns a boolean for whether the string is numeric. | ||
This type is a workaround for [Microsoft/TypeScript#46109](https://github.com/microsoft/TypeScript/issues/46109#issuecomment-930307987). | ||
*/ | ||
export type IsNumeric<T extends string> = T extends `${number}` ? true : false; | ||
export type IsNumeric<T extends string> = T extends `${number}` | ||
? Trim<T> extends T | ||
? true | ||
: false | ||
: false; | ||
@@ -119,0 +163,0 @@ /** |
@@ -36,3 +36,3 @@ import type {IsLowerCase, IsNumeric, IsUpperCase, WordSeparators} from './internal'; | ||
// Skip word separator | ||
? [...SkipEmptyWord<CurrentWord>, ...SplitWords<RemainingCharacters, LastCharacter>] | ||
? [...SkipEmptyWord<CurrentWord>, ...SplitWords<RemainingCharacters>] | ||
: LastCharacter extends '' | ||
@@ -39,0 +39,0 @@ // Fist char of word |
@@ -0,5 +1,7 @@ | ||
import type {Whitespace} from './internal'; | ||
/** | ||
Remove spaces from the left side. | ||
*/ | ||
type TrimLeft<V extends string> = V extends ` ${infer R}` ? TrimLeft<R> : V; | ||
type TrimLeft<V extends string> = V extends `${Whitespace}${infer R}` ? TrimLeft<R> : V; | ||
@@ -9,3 +11,3 @@ /** | ||
*/ | ||
type TrimRight<V extends string> = V extends `${infer R} ` ? TrimRight<R> : V; | ||
type TrimRight<V extends string> = V extends `${infer R}${Whitespace}` ? TrimRight<R> : V; | ||
@@ -12,0 +14,0 @@ /** |
240105
5600