MCPcopy Create free account
hub / github.com/denoland/std / unescape

Function unescape

internal/diff_str.ts:24–36  ·  view source on GitHub ↗
(string: string)

Source from the content-addressed store, hash-verified

22 * ```
23 */
24export function unescape(string: string): string {
25 return string
26 .replaceAll("\\", "\\\\")
27 .replaceAll("\b", "\\b")
28 .replaceAll("\f", "\\f")
29 .replaceAll("\t", "\\t")
30 .replaceAll("\v", "\\v")
31 // This does not remove line breaks
32 .replaceAll(
33 /\r\n|\r|\n/g,
34 (str) => str === "\r" ? "\\r" : str === "\n" ? "\\n\n" : "\\r\\n\r\n",
35 );
36}
37
38const WHITESPACE_SYMBOLS_REGEXP =
39 /((?:\\[bftv]|[^\S\r\n])+|\\[rn\\]|[()[\]{}'"\r\n]|\b)/;

Callers 2

fnFunction · 0.90
diffStrFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected