Skip to content
Snippets Groups Projects
Commit 97d77d3a authored by Jimmy's avatar Jimmy
Browse files

Style clean-up of stringFrom

parent 1be86a19
No related branches found
No related tags found
No related merge requests found
...@@ -2,66 +2,68 @@ ...@@ -2,66 +2,68 @@
Returns the simple string representation of the given value or, if there is Returns the simple string representation of the given value or, if there is
none, a square bracketed representation. none, a square bracketed representation.
*/ */
stringFrom = function(value) { // eslint-disable-next-line no-global-assign
stringFrom = function (value) {
switch (typeof value) { switch (typeof value) {
case 'function': case "function":
return '[function]'; return "[function]";
case 'number': case "number":
if (Number.isNaN(value)) { if (Number.isNaN(value)) {
return '[number NaN]'; return "[number NaN]";
} }
break; break;
case 'object': case "object":
if (value === null) { if (value === null) {
return '[null]'; return "[null]";
} } else if (value instanceof Array) {
else if (value instanceof Array) { return value.map(val => stringFrom(val)).join(", ");
return value.map(val => stringFrom(val)).join(', '); } else if (value instanceof Set) {
} return Array.from(value)
else if (value instanceof Set) { .map(val => stringFrom(val))
return Array.from(value).map(val => stringFrom(val)).join(', '); .join(", ");
} } else if (value instanceof Map) {
else if (value instanceof Map) { const result = Array.from(value).map(
const result = Array.from(value).map(([key, val]) => `${stringFrom(key)} \u2192 ${stringFrom(val)}`); ([key, val]) => `${stringFrom(key)} \u2192 ${stringFrom(val)}`
return `{\u202F${result.join(', ')}\u202F}`; );
} return `{\u202F${result.join(", ")}\u202F}`;
else if (value instanceof Date) { } else if (value instanceof Date) {
return value.toLocaleString(); return value.toLocaleString();
} } else if (value instanceof Element) {
else if (value instanceof Element) {
if ( if (
value === document.documentElement value === document.documentElement ||
|| value === document.head value === document.head ||
|| value === document.body value === document.body
) { ) {
throw new Error('illegal operation; attempting to convert the <html>, <head>, or <body> tags to string is not allowed'); throw new Error(
"illegal operation; attempting to convert the <html>, <head>, or <body> tags to string is not allowed"
);
} }
return value.outerHTML; return value.outerHTML;
} } else if (value instanceof Node) {
else if (value instanceof Node) {
return value.textContent; return value.textContent;
} } else if (typeof value.toString === "function") {
else if (typeof value.toString === 'function') {
return value.toString(); return value.toString();
} }
return Object.prototype.toString.call(value); return Object.prototype.toString.call(value);
case 'symbol': { case "symbol": {
const desc = typeof value.description !== 'undefined' ? ` "${value.description}"` : ''; const desc = typeof value.description !== "undefined" ? ` "${value.description}"` : "";
return `[symbol${desc}]`; return `[symbol${desc}]`;
} }
case 'undefined': case "undefined":
if (V && (V.debugdisable === 'f' || V.debug === 1)) { if (V && (V.debugdisable === "f" || V.debug === 1)) {
Errors.report('Print macro attempted to return an undefined variable in ' + Utils.GetStack()); Errors.report(
"Print macro attempted to return an undefined variable in " + Utils.GetStack()
);
} }
return V && V.debug ? '[undefined]' : ''; return V && V.debug ? "[undefined]" : "";
} }
return String(value); return String(value);
} };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment