-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
51 lines (41 loc) · 1.49 KB
/
utils.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
function _is(input: string, func: (input: string) => boolean): boolean {
if (input.length === 0) return true;
if (input.length === 1) return func(input);
return input.split("").every(func);
}
export function isLowerAlpha(input: string) {
return _is(input, (input) => {
const charCode = input.charCodeAt(0);
const aCharCode = "a".charCodeAt(0);
const zCharCode = "z".charCodeAt(0);
return aCharCode <= charCode && charCode <= zCharCode;
});
}
export function isUpperAlpha(input: string) {
return _is(input, (input) => {
const charCode = input.charCodeAt(0);
const ACharCode = "A".charCodeAt(0);
const ZCharCode = "Z".charCodeAt(0);
return ACharCode <= charCode && charCode <= ZCharCode;
});
}
export function isAlpha(input: string): boolean {
return _is(input, (input) => isUpperAlpha(input) || isLowerAlpha(input));
}
export function isNum(input: string): boolean {
return _is(input, (input: string) => {
const charCode = input.charAt(0);
const _0charCode = "0".charAt(0);
const _9charCode = "9".charAt(0);
return _0charCode <= charCode && charCode <= _9charCode;
});
}
export function isAlphaNum(input: string): boolean {
return _is(input, (input) => isAlpha(input) || isNum(input));
}
export function isLowerAlphaNum(input: string): boolean {
return _is(input, (input) => isLowerAlpha(input) || isNum(input));
}
export function isUpperAlphaNum(input: string): boolean {
return _is(input, (input) => isUpperAlpha(input) || isNum(input));
}