engines/rails_erb.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encode = void 0;
const convertMatchToSpaces = (match) => " ".repeat(match.length);
/**
 * Encode erb string, leave only javascript code, replace other erb code with whitespace.
 * @param str {string} html string
 * @returns {string} encoded string
 */
function encode(str) {
    return str
        .replace(/(<\/script>|<%.*?end.*?>).*?(<script.*?>|<%=.*?javascript_tag.*?%>)/gis, convertMatchToSpaces)
        .replace(/^.*?(<script.*?>|<%=.*?javascript_tag.*?%>)/is, convertMatchToSpaces)
        .replace(/(<\/script>|<%.*?end.*?>).*?$/is, convertMatchToSpaces);
}
exports.encode = encode;