First commit, done on M6 from the PLAN.MD
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
// Compact JSON layout for the card files: anything that fits on one line stays on one line.
|
||||
|
||||
const inline = (v) => {
|
||||
if (Array.isArray(v)) return "[" + v.map(inline).join(", ") + "]";
|
||||
if (v && typeof v === "object") return "{ " + Object.entries(v).map(([k, x]) => JSON.stringify(k) + ": " + inline(x)).join(", ") + " }";
|
||||
return JSON.stringify(v);
|
||||
};
|
||||
|
||||
export function format(v, indent = "") {
|
||||
const flat = inline(v);
|
||||
if (flat.length + indent.length <= 118 || typeof v !== "object" || v === null) return flat;
|
||||
const next = indent + " ";
|
||||
if (Array.isArray(v)) return "[\n" + v.map((x) => next + format(x, next)).join(",\n") + "\n" + indent + "]";
|
||||
return "{\n" + Object.entries(v).map(([k, x]) => next + JSON.stringify(k) + ": " + format(x, next)).join(",\n") + "\n" + indent + "}";
|
||||
}
|
||||
Reference in New Issue
Block a user