@thi.ng/text-canvas
Version:
Text based canvas, drawing, plotting, tables with arbitrary formatting (incl. ANSI/HTML)
19 lines (18 loc) • 441 B
JavaScript
import { format, formatNone } from "@thi.ng/text-format/format";
const formatCanvas = (canvas, fmt) => {
const { data, width, height } = canvas;
const res = [];
if (fmt) {
for (let y = 0; y < height; y++) {
res.push(format(fmt, data, width, y * width));
}
} else {
for (let y = 0; y < height; y++) {
res.push(formatNone(data, width, y * width));
}
}
return res.join("");
};
export {
formatCanvas
};