fable-core
Advanced tools
Comparing version 1.0.0-narumi-906 to 1.0.0-narumi-909
@@ -18,3 +18,3 @@ import FSymbol from "./Symbol"; | ||
ToString() { | ||
return "[" + Array.from(this).map(toString).join("; ") + "]"; | ||
return "[" + Array.from(this).map(x => toString(x)).join("; ") + "]"; | ||
} | ||
@@ -21,0 +21,0 @@ Equals(x) { |
@@ -417,3 +417,3 @@ import List from "./ListClass"; | ||
ToString() { | ||
return "map [" + Array.from(this).map(toString).join("; ") + "]"; | ||
return "map [" + Array.from(this).map(x => toString(x)).join("; ") + "]"; | ||
} | ||
@@ -420,0 +420,0 @@ Equals(m2) { |
{ | ||
"name": "fable-core", | ||
"version": "1.0.0-narumi-906", | ||
"version": "1.0.0-narumi-909", | ||
"description": "Fable core library", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -90,3 +90,3 @@ import { equals } from "./Util"; | ||
let iter = xs[Symbol.iterator](); | ||
let output = null; | ||
let output = { value: null }; | ||
return unfold(innerIter => { | ||
@@ -107,3 +107,3 @@ let hasFinished = false; | ||
if (!cur.done) { | ||
output = cur.value; | ||
output = { value: cur.value }; | ||
hasFinished = true; | ||
@@ -116,3 +116,3 @@ } | ||
} | ||
return innerIter != null && output != null ? [output, innerIter] : null; | ||
return innerIter != null && output != null ? [output.value, innerIter] : null; | ||
}, null); | ||
@@ -119,0 +119,0 @@ }); |
@@ -631,3 +631,3 @@ import List from "./List"; | ||
ToString() { | ||
return "set [" + Array.from(this).map(toString).join("; ") + "]"; | ||
return "set [" + Array.from(this).map(x => toString(x)).join("; ") + "]"; | ||
} | ||
@@ -634,0 +634,0 @@ Equals(s2) { |
@@ -94,5 +94,2 @@ import { toString } from "./Util"; | ||
export function fsFormat(str, ...args) { | ||
function isObject(x) { | ||
return x !== null && typeof x === "object" && !(x instanceof Number) && !(x instanceof String) && !(x instanceof Boolean); | ||
} | ||
function formatOnce(str, rep) { | ||
@@ -117,11 +114,3 @@ return str.replace(fsFormatRegExp, function (_, prefix, flags, pad, precision, format) { | ||
case "A": | ||
try { | ||
rep = JSON.stringify(rep, function (k, v) { | ||
return v && v[Symbol.iterator] && !Array.isArray(v) && isObject(v) ? Array.from(v) | ||
: v && typeof v.ToString === "function" ? toString(v) : v; | ||
}); | ||
} | ||
catch (err) { | ||
rep = "{" + Object.getOwnPropertyNames(rep).map(k => k + ": " + String(rep[k])).join(", ") + "}"; | ||
} | ||
rep = toString(rep, true); | ||
break; | ||
@@ -128,0 +117,0 @@ case "x": |
36
Util.js
@@ -90,4 +90,36 @@ import FSymbol from "./Symbol"; | ||
} | ||
export function toString(o) { | ||
return o != null && typeof o.ToString == "function" ? o.ToString() : String(o); | ||
export function toString(obj, quoteStrings = false) { | ||
function isObject(x) { | ||
return x !== null && typeof x === "object" && !(x instanceof Number) && !(x instanceof String) && !(x instanceof Boolean); | ||
} | ||
if (obj == null || typeof obj === "number") { | ||
return String(obj); | ||
} | ||
if (typeof obj === "string") { | ||
return quoteStrings ? JSON.stringify(obj) : obj; | ||
} | ||
if (typeof obj.ToString == "function") { | ||
return obj.ToString(); | ||
} | ||
if (hasInterface(obj, "FSharpUnion")) { | ||
const info = obj[FSymbol.reflection](); | ||
const uci = info.cases[obj.tag]; | ||
switch (uci.length) { | ||
case 1: | ||
return uci[0]; | ||
case 2: | ||
return uci[0] + " (" + toString(obj.data, true) + ")"; | ||
default: | ||
return uci[0] + " (" + obj.data.map((x) => toString(x, true)).join(",") + ")"; | ||
} | ||
} | ||
try { | ||
return JSON.stringify(obj, function (k, v) { | ||
return v && v[Symbol.iterator] && !Array.isArray(v) && isObject(v) ? Array.from(v) | ||
: v && typeof v.ToString === "function" ? toString(v) : v; | ||
}); | ||
} | ||
catch (err) { | ||
return "{" + Object.getOwnPropertyNames(obj).map(k => k + ": " + String(obj[k])).join(", ") + "}"; | ||
} | ||
} | ||
@@ -94,0 +126,0 @@ export function hash(x) { |
229999
7287