forked from lukaswagner/uebungsrahmen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cleanupPatterns.js
34 lines (30 loc) · 757 Bytes
/
cleanupPatterns.js
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
'use strict';
const defaultPatterns = [
// js, glsl, etc comments
{
start: /\/\/ ?REMOVE BEGIN/,
end: /\/\/ ?REMOVE END/
},
// markdown comments
{
start: /# ?REMOVE BEGIN/,
end: /# ?REMOVE END/
}
];
const optionalLineStart = /(?:^\s*)?/;
/**
*
* @param {[{start: RegExp, end: RegExp}]} customPatterns
* @param {boolean} includeDefault
* @returns
*/
function cleanupPatterns(customPatterns = [], includeDefault = true) {
return [
...(includeDefault ? defaultPatterns : []),
...(customPatterns ?? [])
]
.map((p) => new RegExp(
optionalLineStart.source + p.start.source + '.*?' + p.end.source,
'gms'));
}
module.exports = cleanupPatterns;