UNPKG

@hypst/time-beat-format

Version:
34 lines (33 loc) 862 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function fillNumberWidth(num, width, fill) { if (!num) num = 0; if (!width) width = 0; if (!fill) fill = 0; if (width == -1 && num == 0) return ''; let s = num.toString(); while (s.length < width) { s = fill.toString() + s; } return s; } exports.fillNumberWidth = fillNumberWidth; function fixNumberWidth(num, width, fill) { if (!num) num = 0; if (!width) return num.toString(); if (!fill) fill = 0; if (num.toString().length <= width) { return fillNumberWidth(num, width, fill); } else { return Math.round(Number(num.toPrecision(width))).toString().slice(0, width); } } exports.fixNumberWidth = fixNumberWidth;