@builder.io/mitosis
Version:
Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io
27 lines (26 loc) • 849 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.stripNewlinesInStrings = void 0;
function stripNewlinesInStrings(string) {
let inString = null;
return string
.split('')
.map((char, index) => {
if (inString) {
if (char === '\n') {
return ' ';
}
}
// Prior char is escape char and the char before that is not escaping it
const isEscaped = string[index - 1] === '\\' && string[index - 2] !== '\\';
if (!inString && (char === '"' || char === "'") && !isEscaped) {
inString = char;
}
else if (inString && char === inString && !isEscaped) {
inString = null;
}
return char;
})
.join('');
}
exports.stripNewlinesInStrings = stripNewlinesInStrings;
;