vike
Version:
The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.
9 lines (8 loc) • 400 B
JavaScript
export { applyRegExpWithMagicString };
function applyRegExpWithMagicString(magicString, regExp, replacement) {
const envStatementRegEx = typeof regExp === 'string' ? new RegExp(regExp, 'g') : regExp;
let match;
while ((match = envStatementRegEx.exec(magicString.original))) {
magicString.overwrite(match.index, match.index + match[0].length, JSON.stringify(replacement));
}
}