-
-
Notifications
You must be signed in to change notification settings - Fork 151
/
groups.ts
79 lines (70 loc) · 1.77 KB
/
groups.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import type { IObjectOf } from "@thi.ng/api";
import { charRange } from "./range.js";
/** @internal */
const __defGroup = (...ranges: Iterable<string>[]) => {
const acc: IObjectOf<boolean> = {};
for (let range of ranges) {
for (let c of range) {
acc[c] = true;
}
}
return Object.freeze(acc);
};
/**
* Object with whitespace characters as keys and their values set to
* true. All others undefined.
*/
export const WS: IObjectOf<boolean> = Object.freeze({
"\t": true,
"\n": true,
"\v": true,
"\f": true,
"\r": true,
" ": true,
});
/**
* Object with 0-9 characters as keys and their values set to true. All
* others undefined.
*/
export const DIGITS = __defGroup(charRange("0", "9"));
/**
* Object with hex digit characters (upper & lower case versions) as
* keys and their values set to true. All others undefined.
*/
export const HEX = __defGroup(
charRange("0", "9"),
charRange("A", "F"),
charRange("a", "f")
);
/**
* Object with ASCII lowercase characters as keys and their values set
* to true. All others undefined.
*/
export const LOWER = __defGroup(charRange("a", "z"));
/**
* Object with ASCII uppercase characters as keys and their values set
* to true. All others undefined.
*/
export const UPPER = __defGroup(charRange("A", "Z"));
/**
* Combination of {@link UPPER} and {@link LOWER}.
*/
export const ALPHA = Object.freeze({ ...UPPER, ...LOWER });
/**
* Combination of {@link ALPHA} and {@link DIGITS} and '_'.
*/
export const ALPHA_NUM: IObjectOf<boolean> = Object.freeze({
...ALPHA,
...DIGITS,
_: true,
});
/**
* Object with ASCII punctuation characters as keys and their values set
* to true. All others undefined.
*/
export const PUNCTUATION = __defGroup(
charRange("!", "/"),
charRange(":", "@"),
charRange("[", "`"),
charRange("{", "~")
);