-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser-chalk.ts
88 lines (77 loc) · 1.65 KB
/
browser-chalk.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
80
81
82
83
84
85
86
87
88
// Without this typescript won't require tslib
export {};
/*
This is can be used to make html-differ work in the browser using the NormalModuleReplacementPlugin
webpack plugin:
new NormalModuleReplacementPlugin(
/chalk/,
(resource: any): void => {
info('Replace chalk with browser-chalk for browser compatibility');
resource.request = '@tepez/jasmine-misc-matchers/dist/browser-chalk.js';
}
)
It makes all the functions of chalk return the same string, i.e. do thing
Based on the API of https://github.com/chalk/chalk/blob/v4.1.0/readme.md
*/
const identity: any = function (str: any): any {
return str;
}
const colorFn: any = function (str: any): any {
return str;
}
const modifiers = [
'reset',
'bold',
'dim',
'italic',
'underline',
'inverse',
'hidden',
'strikethrough',
'visible',
];
for (const modifier of modifiers) {
colorFn[modifier] = identity;
}
const colors = [
'black',
'red',
'green',
'yellow',
'blue',
'magenta',
'cyan',
'white',
'blackBright',
'gray',
'grey',
'redBright',
'greenBright',
'yellowBright',
'blueBright',
'magentaBright',
'cyanBright',
'whiteBright',
'bgBlack',
'bgRed',
'bgGreen',
'bgYellow',
'bgBlue',
'bgMagenta',
'bgCyan',
'bgWhite',
'bgBlackBright',
'bgGray',
'bgGrey',
'bgRedBright',
'bgGreenBright',
'bgYellowBright',
'bgBlueBright',
'bgMagentaBright',
'bgCyanBright',
'bgWhiteBright',
]
module.exports = {};
for (const color of colors) {
module.exports[color] = colorFn;
}