MCPcopy
hub / github.com/TiddlyWiki/TiddlyDesktop / stringify

Function stringify

source/js/utils/saving.js:97–113  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

95// Turns a string into a legal JavaScript string
96// Copied from peg.js, thanks to David Majda
97function stringify(s) {
98 /*
99 * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a string
100 * literal except for the closing quote character, backslash, carriage return,
101 * line separator, paragraph separator, and line feed. Any character may
102 * appear in the form of an escape sequence.
103 *
104 * For portability, we also escape all non-ASCII characters.
105 */
106 return (s || "")
107 .replace(/\\/g, '\\\\') // backslash
108 .replace(/"/g, '\\"') // double quote character
109 .replace(/'/g, "\\'") // single quote character
110 .replace(/\r/g, '\\r') // carriage return
111 .replace(/\n/g, '\\n') // line feed
112 .replace(/[\x00-\x1f\x80-\uFFFF]/g, escape); // non-ASCII characters
113};
114
115// Helper function to save a file
116function saveFile(filepath,content) {

Callers 1

injectClassicOverridesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected