-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
38 lines (31 loc) · 955 Bytes
/
utils.js
File metadata and controls
38 lines (31 loc) · 955 Bytes
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
const ALPHA_REGEX = /[a-z]/i;
const ALPHA_NUM_REGEX = /[a-z0-9]/i;
const WHITESPACE_REGEX = /\s+/i;
export function is_digit(ch) {
const code = ch.charCodeAt(0);
return code > 47 && code < 58;
}
export function is_alpha(ch) {
// return ch.charCodeAt(0) > 64 && ch.charCodeAt() < 123;
return ch.match(ALPHA_REGEX);
}
export function is_alphanum(ch) {
return ALPHA_NUM_REGEX.test(ch);
}
export function is_whitespace(ch) {
return WHITESPACE_REGEX.test(ch);
}
export function panic(message) {
console.error(message);
exit_rand();
}
export function pretty_error(row, column, error_line, error_message) {
console.error(`\x1b[31mError at line: ${row + 1} column: ${column + 1}`);
console.error(`\n\x1b[33m ${error_line}`);
console.error(` \x1b[0m^^^${error_message}`);
exit_rand();
}
export function exit_rand() {
const rand_code = Math.round(42 + Math.random() * 28);
process.exit(rand_code);
}