1 | const { Transform } = require('stream');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | function createRegexTransformStream(regex) {
|
8 | let buffer = ''
|
9 |
|
10 | const ts = new Transform({
|
11 | transform(chunk, encoding, next) {
|
12 | let lastMatch
|
13 | let match
|
14 | buffer += chunk.toString()
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | while (match = regex.exec(buffer)) {
|
20 | ts.push(match)
|
21 | lastMatch = match
|
22 | if (!regex.global) break
|
23 | }
|
24 | if (lastMatch) {
|
25 | buffer = buffer.slice(lastMatch.index + lastMatch[0].length)
|
26 | }
|
27 | next()
|
28 | },
|
29 | objectMode: true,
|
30 | })
|
31 |
|
32 | return ts
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | const $_lib_markers = require('./lib/markers');
|
40 |
|
41 | const $_Replaceable = require('./Replaceable');
|
42 | const $_SyncReplaceable = require('./SyncReplaceable');
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | module.exports = createRegexTransformStream
|
57 | module.exports.makeMarkers = $_lib_markers.makeMarkers
|
58 | module.exports.makeCutRule = $_lib_markers.makeCutRule
|
59 | module.exports.makePasteRule = $_lib_markers.makePasteRule
|
60 | module.exports.Replaceable = $_Replaceable
|
61 | module.exports.SerialAsyncReplaceable = $_Replaceable.SerialAsyncReplaceable
|
62 | module.exports.SyncReplaceable = $_SyncReplaceable |
\ | No newline at end of file |