-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (23 loc) · 784 Bytes
/
Copy pathindex.js
File metadata and controls
29 lines (23 loc) · 784 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
class Reggie {
constructor() {
this.defaultFlag = 'gm';
}
setFlag(flag) {
this.defaultFlag = flag;
}
stripComments(templateLiteral) {
let string = (typeof templateLiteral === 'string') ? templateLiteral : templateLiteral.raw[0];
return string
.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm, '');
}
create(templateLiteral) {
let string = (typeof templateLiteral === 'string') ? templateLiteral : templateLiteral.raw[0];
return this.stripComments(string)
.replace(/(\r\n|r\|\n|\s)/gm, '');
}
generate(templateLiteral, flags = this.defaultFlag) {
let string = (typeof templateLiteral === 'string') ? templateLiteral : templateLiteral.raw[0];
return new RegExp(this.create(string), flags);
}
}
module.exports = Reggie;