-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathis-lowercase.d.ts
More file actions
38 lines (30 loc) · 1 KB
/
is-lowercase.d.ts
File metadata and controls
38 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type {AllExtend} from './all-extend.d.ts';
/**
Returns a boolean for whether the given string literal is lowercase.
@example
```
import type {IsLowercase} from 'type-fest';
type A = IsLowercase<'abc'>;
//=> true
type B = IsLowercase<'Abc'>;
//=> false
type C = IsLowercase<string>;
//=> boolean
```
*/
export type IsLowercase<S extends string> = AllExtend<_IsLowercase<S>, true>;
/**
Loops through each part in the string and returns a boolean array indicating whether each part is lowercase.
*/
type _IsLowercase<S extends string, Accumulator extends boolean[] = []> = S extends `${infer First}${infer Rest}`
? _IsLowercase<Rest, [...Accumulator, IsLowercaseHelper<First>]>
: [...Accumulator, IsLowercaseHelper<S>];
/**
Returns a boolean for whether an individual part of the string is lowercase.
*/
type IsLowercaseHelper<S extends string> = S extends Lowercase<string>
? true
: S extends Uppercase<string> | Capitalize<string> | `${string}${Uppercase<string>}${string}`
? false
: boolean;
export {};