Slide 8
Slide 8 text
function quoteString(string, ctx) {
const quote = ArrayPrototypeFind(
ctx.quotes,
(c) => !StringPrototypeIncludes(string, c),
) ?? ctx.quotes[0];
const escapePattern = new SafeRegExp(`(?=[${quote}\\\\])`, "g");
string = StringPrototypeReplace(string, escapePattern, "\\");
if (ctx.escapeSequences) {
string = replaceEscapeSequences(string);
}
return `${quote}${string}${quote}`;
}
8
deno/ext/console/01_console.js