-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (26 loc) · 1021 Bytes
/
index.js
File metadata and controls
29 lines (26 loc) · 1021 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
const through2 = require('through2');
module.exports = function (file, opts) {
// set default obj if undefined
opts = opts || {}
let code = '';
const startTag = opts.startTag || 'start-strip-code'
const endTag = opts.endTag || 'end-strip-code'
const startComment = '\\/\\* '
const endComment = ' \\*\\/'
const startBlock = startComment + startTag + endComment
const endBlock = startComment + endTag + endComment
const codeBetweenTags = '((?:.|)*)'
const stripCodeExpression = new RegExp(startBlock + codeBetweenTags + endBlock, 'gms')
return through2.obj(function stripCodeThrough(/**Buffer*/buf, enc, next) {
/* accumulate the code chunks */
code += buf.toString('utf8')
next()
}, function stripCodeThroughNext(next) {
if (!Array.isArray(opts.whitelist) || opts.whitelist.findIndex(item => (file.indexOf(item) !== -1)) !== -1) {
/* transform the code */
code = code.replace(stripCodeExpression, '')
}
this.push(Buffer.from(code))
next()
})
}