MCPcopy
hub / github.com/livebud/bud / jsesc2

Function jsesc2

framework/view/ssr/svelte.js:97–279  ·  view source on GitHub ↗
(argument, options)

Source from the content-addressed store, hash-verified

95 var escapeEverythingRegex = /([\uD800-\uDBFF][\uDC00-\uDFFF])|([\uD800-\uDFFF])|(['"`])|[^]/g;
96 var escapeNonAsciiRegex = /([\uD800-\uDBFF][\uDC00-\uDFFF])|([\uD800-\uDFFF])|(['"`])|[^ !#-&\(-\[\]-_a-~]/g;
97 var jsesc2 = (argument, options) => {
98 const increaseIndentation = () => {
99 oldIndent = indent;
100 ++options.indentLevel;
101 indent = options.indent.repeat(options.indentLevel);
102 };
103 const defaults = {
104 "escapeEverything": false,
105 "minimal": false,
106 "isScriptContext": false,
107 "quotes": "single",
108 "wrap": false,
109 "es6": false,
110 "json": false,
111 "compact": true,
112 "lowercaseHex": false,
113 "numbers": "decimal",
114 "indent": " ",
115 "indentLevel": 0,
116 "__inline1__": false,
117 "__inline2__": false
118 };
119 const json = options && options.json;
120 if (json) {
121 defaults.quotes = "double";
122 defaults.wrap = true;
123 }
124 options = extend(defaults, options);
125 if (options.quotes != "single" && options.quotes != "double" && options.quotes != "backtick") {
126 options.quotes = "single";
127 }
128 const quote = options.quotes == "double" ? '"' : options.quotes == "backtick" ? "`" : "'";
129 const compact = options.compact;
130 const lowercaseHex = options.lowercaseHex;
131 let indent = options.indent.repeat(options.indentLevel);
132 let oldIndent = "";
133 const inline1 = options.__inline1__;
134 const inline2 = options.__inline2__;
135 const newLine = compact ? "" : "\n";
136 let result;
137 let isEmpty = true;
138 const useBinNumbers = options.numbers == "binary";
139 const useOctNumbers = options.numbers == "octal";
140 const useDecNumbers = options.numbers == "decimal";
141 const useHexNumbers = options.numbers == "hexadecimal";
142 if (json && argument && isFunction(argument.toJSON)) {
143 argument = argument.toJSON();
144 }
145 if (!isString(argument)) {
146 if (isMap(argument)) {
147 if (argument.size == 0) {
148 return "new Map()";
149 }
150 if (!compact) {
151 options.__inline1__ = true;
152 options.__inline2__ = false;
153 }
154 return "new Map(" + jsesc2(Array.from(argument), options) + ")";

Callers

nothing calls this directly

Calls 15

extendFunction · 0.85
isFunctionFunction · 0.85
isStringFunction · 0.85
isMapFunction · 0.85
isSetFunction · 0.85
isBufferFunction · 0.85
increaseIndentationFunction · 0.85
forEachFunction · 0.85
isNumberFunction · 0.85
forOwnFunction · 0.85
hexadecimalFunction · 0.85
fourHexEscapeFunction · 0.85

Tested by

no test coverage detected