/* currency.js - v2.0.4 http://scurker.github.io/currency.js Copyright (c) 2021 Jason Wilson Released under MIT license */ (function (e, g) { "object" === typeof exports && "undefined" !== typeof module ? (module.exports = g()) : "function" === typeof define && define.amd ? define(g) : ((e = e || self), (e.currency = g())); })(this, function () { function e(b, a) { if (!(this instanceof e)) return new e(b, a); a = Object.assign({}, m, a); var d = Math.pow(10, a.precision); this.intValue = b = g(b, a); this.value = b / d; a.increment = a.increment || 1 / d; a.groups = a.useVedic ? n : p; this.s = a; this.p = d; } function g(b, a) { var d = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : !0; var c = a.decimal; var h = a.errorOnInvalid, k = a.fromCents, l = Math.pow(10, a.precision), f = b instanceof e; if (f && k) return b.intValue; if ("number" === typeof b || f) c = f ? b.value : b; else if ("string" === typeof b) (h = new RegExp("[^-\\d" + c + "]", "g")), (c = new RegExp("\\" + c, "g")), (c = (c = b .replace(/\((.*)\)/, "-$1") .replace(h, "") .replace(c, ".")) || 0); else { if (h) throw Error("Invalid Input"); c = 0; } k || (c = (c * l).toFixed(4)); return d ? Math.round(c) : c; } var m = { symbol: "$", separator: ",", decimal: ".", errorOnInvalid: !1, precision: 2, pattern: "!#", negativePattern: "-!#", format: function (b, a) { var d = a.pattern, c = a.negativePattern, h = a.symbol, k = a.separator, l = a.decimal; a = a.groups; var f = ("" + b).replace(/^-/, "").split("."), q = f[0]; f = f[1]; return (0 <= b.value ? d : c) .replace("!", h) .replace("#", q.replace(a, "$1" + k) + (f ? l + f : "")); }, fromCents: !1, }, p = /(\d)(?=(\d{3})+\b)/g, n = /(\d)(?=(\d\d)+\d\b)/g; e.prototype = { add: function (b) { var a = this.s, d = this.p; return e((this.intValue + g(b, a)) / (a.fromCents ? 1 : d), a); }, subtract: function (b) { var a = this.s, d = this.p; return e((this.intValue - g(b, a)) / (a.fromCents ? 1 : d), a); }, multiply: function (b) { var a = this.s; return e( (this.intValue * b) / (a.fromCents ? 1 : Math.pow(10, a.precision)), a ); }, divide: function (b) { var a = this.s; return e(this.intValue / g(b, a, !1), a); }, distribute: function (b) { var a = this.intValue, d = this.p, c = this.s, h = [], k = Math[0 <= a ? "floor" : "ceil"](a / b), l = Math.abs(a - k * b); for (d = c.fromCents ? 1 : d; 0 !== b; b--) { var f = e(k / d, c); 0 < l-- && (f = f[0 <= a ? "add" : "subtract"](1 / d)); h.push(f); } return h; }, dollars: function () { return ~~this.value; }, cents: function () { return ~~(this.intValue % this.p); }, format: function (b) { var a = this.s; return "function" === typeof b ? b(this, a) : a.format(this, Object.assign({}, a, b)); }, toString: function () { var b = this.s, a = b.increment; return (Math.round(this.intValue / this.p / a) * a).toFixed(b.precision); }, toJSON: function () { return this.value; }, }; return e; });