diff options
author | Yuchen Pei <hi@ypei.me> | 2022-04-29 17:05:16 +1000 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-04-29 17:05:16 +1000 |
commit | e86693c682d15a29efd936c2b185e121a0c9ffda (patch) | |
tree | 6ad9272cb9fbdf38c5600ac6177da59ef9883963 /pattern_utils.js | |
parent | 3dafc83753fbabc8d80540e05cf1e374ae73f4fa (diff) |
Stripping comments when checking between @license and @license-end
example (say it's an external script):
/* my awesome script */
/* @license magnet ... */
....
// @license-end
Diffstat (limited to 'pattern_utils.js')
-rw-r--r-- | pattern_utils.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/pattern_utils.js b/pattern_utils.js index ef1e304..7ab143b 100644 --- a/pattern_utils.js +++ b/pattern_utils.js @@ -31,10 +31,18 @@ exports.patternUtils = { removeNonalpha: function(str) { return str.replace(/[^a-z0-9<>@]+/gi, ''); }, + removeWhitespace: function(str) { return str.replace(/\/\//gmi, '').replace(/\*/gmi, '').replace(/\s+/gmi, ''); }, + replaceTokens: function(str) { return str.replace(/<.*?>/gi, '.*?'); + }, + + removeJsComments: function(str) { + const ml_comments = /\/\*.*?(\*\/)/g; + const il_comments = /\/\/.*/gm; + return str.replace(ml_comments, '').replace(il_comments, ''); } }; |