@thi.ng/vectors
Version:
Optimized 2d/3d/4d and arbitrary length vector operations, support for memory mapping/layouts
21 lines (20 loc) • 592 B
JavaScript
import { isFunction } from "@thi.ng/checks/is-function";
import { float, floatFixedWidth } from "@thi.ng/strings/float";
const defFormat = (opts = {}) => {
const { prec = 3, delim = ", ", wrap = "[]", width } = opts;
const fmt = width ? floatFixedWidth(width, prec) : float(prec);
return (src) => {
let res = [];
for (const x of src) res.push(fmt(x));
return `${wrap[0]}${res.join(delim)}${wrap[1]}`;
};
};
const setFormat = (fmt) => {
FORMATTER = isFunction(fmt) ? fmt : defFormat(fmt);
};
let FORMATTER = defFormat();
export {
FORMATTER,
defFormat,
setFormat
};