UNPKG

fus-ext

Version:
105 lines (103 loc) 6.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.format = exports.pad = exports.approxLessThan = exports.approxGreaterThan = exports.approxEquals = undefined; var _main = require("./main"); var dotDotCalc_573300145710716007 = function (dotDot, a, b, c) { return dotDot(a)[b](a, ...c); };var approxEquals, approxGreaterThan, approxLessThan, pad, format;exports.approxEquals = approxEquals = function (num, x) { return (() => { return dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, Math, "approxEquals", [num.valueOf(), x]); })(); };exports.approxGreaterThan = approxGreaterThan = function (num, x) { return (() => { return dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, Math, "approxGreaterThan", [num.valueOf(), x]); })(); };exports.approxLessThan = approxLessThan = function (num, x) { return (() => { return dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, Math, "approxLessThan", [num.valueOf(), x]); })(); };exports.pad = pad = function (num, integerSize, fractionalSize) { return (() => { return dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, num.valueOf(), "format", [{ integerSize: integerSize, fractionalSize: fractionalSize }]); })(); };exports.format = format = function (num, options) { return (() => { var o, x, s, t, ePos, isNegative, var_573300145710716007_2;o = dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, Object, "absorb", [dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, Object, "clone", [(var_573300145710716007_2 = options) === undefined ? {} : var_573300145710716007_2]), { integerSize: 1, fractionalSize: 0, forcesSign: false, radix: 10, integerGroupEnabled: false, integerGroupSeparator: ",", integerGroupSize: 3, fractionalGroupEnabled: false, fractionalGroupSeparator: " ", fractionalGroupSize: 3 }]);o.radix !== 10 ? (() => { o.fractionalSize = 0; })() : undefined;x = num.valueOf();o.integerSize > 80 || o.fractionalSize > 20 || x >= 1e21 || x <= -1e21 || o.integerGroupSize < 1 || o.fractionalGroupSize < 1 ? (() => { return (0, _main.fail)("Number or argument out of range"); })() : undefined;s = o.radix === 10 ? (() => { t = dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, Math, "roundDecimal", [x, o.fractionalSize]).toString();ePos = t.indexOf("e");return ePos === -1 ? (() => { return t; })() : (() => { return t[ePos + 1] === "+" ? (() => { return (0, _main.fail)("Number too large"); })() : (() => { return x.toFixed(o.fractionalSize); })(); })(); })() : (() => { return Math.round(x).toString(o.radix); })();isNegative = s[0] === "-";s[0] === "+" || s[0] === "-" ? (() => { s = dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, s, "remove", [0]); })() : undefined;(function () { return (() => { var pos, rawIntegerSize, integerMissing, rawFractionalSize, fractionalMissing;pos = s.indexOf(".");rawIntegerSize = pos === -1 ? (() => { return s.length; })() : (() => { return pos; })();integerMissing = Math.max(o.integerSize - rawIntegerSize, 0);rawFractionalSize = pos === -1 ? (() => { return 0; })() : (() => { return s.length - 1 - pos; })();fractionalMissing = o.fractionalSize - rawFractionalSize;s = s.substr(0, s.length + fractionalMissing);s[s.length - 1] === "." ? (() => { s = s.substr(0, s.length - 1); })() : undefined;pos === -1 && o.fractionalSize > 0 ? (() => { s = s + "."; })() : undefined;s = "0".repeat(integerMissing) + s + "0".repeat(Math.max(fractionalMissing, 0)); })(); })();o.integerGroupEnabled || o.fractionalGroupEnabled ? (() => { return function () { return (() => { var pos, fractionalStart, integerStart;pos = s.indexOf(".");o.fractionalGroupEnabled ? (() => { fractionalStart = (pos === -1 ? (() => { return s.length; })() : (() => { return pos; })()) + 1 + o.fractionalGroupSize;return dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, (0, _main.repeat)({ [""]: fractionalStart, to: s.length - 1, by: o.fractionalGroupSize }), "reverse", []).forEach(function (i) { return (() => { s = dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, s, "insert", [i, o.fractionalGroupSeparator]); })(); }); })() : undefined;return o.integerGroupEnabled ? (() => { integerStart = (pos === -1 ? (() => { return s.length; })() : (() => { return pos; })()) - o.integerGroupSize;return (0, _main.repeat)({ [""]: integerStart, to: 1, by: -o.integerGroupSize }).forEach(function (i) { return (() => { s = dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, s, "insert", [i, o.integerGroupSeparator]); })(); }); })() : undefined; })(); }(); })() : undefined;o.forcesSign ? (() => { return isNegative ? (() => { s = "-" + s; })() : (() => { s = "+" + s; })(); })() : (() => { return isNegative ? (() => { s = "-" + s; })() : undefined; })();return s; })(); };exports.approxEquals = approxEquals; exports.approxGreaterThan = approxGreaterThan; exports.approxLessThan = approxLessThan; exports.pad = pad; exports.format = format;