-
Notifications
You must be signed in to change notification settings - Fork 0
/
char.ts
65 lines (56 loc) · 2.26 KB
/
char.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
export {
char,
charset,
}
import type { _ } from "../util.js"
import type { any } from "../any/exports.js"
import type { nonempty } from "../nonempty/nonempty.js"
import type { boolean } from "../boolean/exports.js"
import type { string } from "./string.js"
declare namespace char {
export const Lowers: [
"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",
]
export const Uppers: [
"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",
]
export const Digits
: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
}
declare namespace Internal {
type splitOnChar<acc extends any.array<string>, intermediate extends string, text extends string, splitOn extends any.showable>
= text extends nonempty.string<infer head, infer tail>
? head extends splitOn
? splitOnChar<intermediate extends "" ? acc : [...acc, intermediate], "", tail, splitOn>
: splitOnChar<acc, `${intermediate}${head}`, tail, splitOn>
: intermediate extends "" ? acc : [...acc, intermediate]
;
}
declare namespace char {
type Lower = charset.Lowers[number]
type Upper = charset.Uppers[number]
type Digit = charset.Digits[number]
type is<type> = [type] extends [`${string}${infer tail}`] ? string.is.empty<tail> : false
namespace is {
type alpha<type extends string> = boolean.all<[char.is<type>, string.is.alpha<type>]>
type digit<type> = boolean.all<[char.is<type>, [type] extends [char.Digit] ? true : false]>
type lowercase<type extends string> = boolean.all<[char.is<type>, string.is.lowercase<type>]>
type uppercase<type extends string> = boolean.all<[char.is<type>, string.is.uppercase<type>]>
type uppercaseAlpha<type extends string> = boolean.all<[char.is.alpha<`${type}`>, char.is.uppercase<`${type}`>]>
}
type splitOnChar<text extends string, splitter extends any.showable> = Internal.splitOnChar<[], "", text, splitter>
}
declare namespace charset {
type Lowers = typeof char.Lowers
type Uppers = typeof char.Uppers
type Digits = typeof char.Digits
type is<chars>
= chars extends nonempty.string<string, infer tail>
? string.is.nonempty<tail>
: false
;
}