-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
48 lines (44 loc) · 1006 Bytes
/
mod.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
import { getTokens } from './src/lexer.ts';
import * as color from './src/colorizer.ts';
interface CODE_COLORS_PARAMS {
BLACK: number[];
RED: number[];
GREEN: number[];
YELLOW: number[];
BLUE: number[];
MAGENTA: number[];
CYAN: number[];
WHITE: number[];
NONE: number[];
GRAY: number[];
}
interface generalOptions {
print?: boolean;
pretty?: boolean;
colors?: Record<string, number[]>;
}
export function colorize(json: string, opts: generalOptions = {}) {
if (opts.print == undefined || opts.print == true) {
console.log(
color.colorize(getTokens(json, { pretty: opts.pretty }), {
colors: opts.colors,
}),
);
return '';
}
return color.colorize(getTokens(json, { pretty: opts.pretty }), {
colors: opts.colors,
});
}
export const CODE_COLORS = {
BLACK: [30, 39],
RED: [31, 39],
GREEN: [32, 39],
YELLOW: [33, 39],
BLUE: [34, 39],
MAGENTA: [35, 39],
CYAN: [36, 39],
WHITE: [37, 39],
NONE: [0, 0],
GRAY: [90, 39],
};