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AAC,CAAC,WAAW","file":"index.js","sourcesContent":["import { Transform } from 'stream'\n\n/**\n * Create a Transform stream which will maintain a buffer with data received from a Readable stream and write data when the buffer can be matched against the regex. It will push the whole match object (or objects when the g flag is used) returned by `/regex/.exec(buffer)`.\n * @param {RegExp} regex Regular expression to execute\n */\nexport default function createRegexTransformStream(regex) {\n let buffer = ''\n\n const ts = new Transform({\n transform(chunk, encoding, next) {\n let lastMatch\n let match\n buffer += chunk.toString()\n\n // thx stream-snitch\n // https://github.com/dmotz/stream-snitch/blob/master/index.js#L52\n // eslint-disable-next-line no-cond-assign\n while (match = regex.exec(buffer)) {\n ts.push(match)\n lastMatch = match\n if (!regex.global) break\n }\n if (lastMatch) {\n buffer = buffer.slice(lastMatch.index + lastMatch[0].length)\n }\n next()\n },\n objectMode: true,\n })\n\n return ts\n}\n\n\nexport {\n makeMarkers,\n makeCutRule,\n makePasteRule,\n} from './lib/markers'\n\nexport { default as Replaceable } from './Replaceable'\n\n/* documentary types/rules.xml */\n/**\n * @typedef {(match: string, ...params: string[]) => string} Replacer\n *\n * @typedef {(match: string, ...params: string[]) => Promise.<string>} AsyncReplacer\n *\n * @typedef {Object} Rule A replacement rule.\n * @prop {RegExp} re A Regular expression to match against.\n * @prop {string|Replacer|AsyncReplacer} replacement A replacement string, or a replacement string function.\n */\n"]}
\No newline at end of file