function stringify(
obj,
{ showValues = true, keysToShow = 3, charsToShow = 10 } = {}
) {
if (!obj || typeof obj !== "object" || obj instanceof Date) return obj;
if (Array.isArray(obj)) {
if (obj.length === 0) return "[]";
return `${obj.length} × ${stringify(obj[0], { showValues: false })}`;
}
const keys = Object.keys(obj);
return `{${keys
.slice(0, keysToShow)
.map(
showValues
? (key) => {
const str = String(stringify(obj[key]));
return `${key}: ${str.substring(0, charsToShow)}${
str.length > charsToShow ? "…" : ""
}`;
}
: (d) => d
)
.join(", ")}${keys.length > keysToShow ? ", …" : ""}}`;
}