@dinero.js/core
Advanced tools
Comparing version 2.0.0-alpha.12 to 2.0.0-alpha.13
@@ -1,2 +0,2 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.12 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
/*! @dinero.js/core 2.0.0-alpha.13 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
'use strict'; | ||
@@ -1203,12 +1203,16 @@ | ||
var absoluteFn = absolute(calculator); | ||
var equalFn = equal$1(calculator); | ||
var lessThanFn = lessThan(calculator); | ||
var zero = calculator.zero(); | ||
return function (units, scale) { | ||
return units.map(function (unit, index) { | ||
var isFirst = index === 0; | ||
var isLast = units.length - 1 === index; | ||
var unitAsString = formatter.toString(isFirst ? unit : absoluteFn(unit)); | ||
if (isLast) { | ||
return unitAsString.padStart(formatter.toNumber(scale), '0'); | ||
} | ||
return unitAsString; | ||
}).join('.'); | ||
var whole = formatter.toString(units[0]); | ||
var fractional = formatter.toString(absoluteFn(units[1])); | ||
var scaleNumber = formatter.toNumber(scale); | ||
var decimal = "".concat(whole, ".").concat(fractional.padStart(scaleNumber, '0')); | ||
var leadsWithZero = equalFn(units[0], zero); | ||
var isNegative = lessThanFn(units[1], zero); | ||
// A leading negative zero is a special case because the `toString` | ||
// formatter won't preserve its negative sign (since 0 === -0). | ||
return leadsWithZero && isNegative ? "-".concat(decimal) : decimal; | ||
}; | ||
@@ -1215,0 +1219,0 @@ } |
@@ -1,3 +0,3 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.12 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
"use strict";function r(r,n){return e(r)||function(r,n){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null==t)return;var e,o,u=[],a=!0,c=!1;try{for(t=t.call(r);!(a=(e=t.next()).done)&&(u.push(e.value),!n||u.length!==n);a=!0);}catch(r){c=!0,o=r}finally{try{a||null==t.return||t.return()}finally{if(c)throw o}}return u}(r,n)||u(r,n)||c()}function n(r){return e(r)||o(r)||u(r)||c()}function t(r){return function(r){if(Array.isArray(r))return a(r)}(r)||o(r)||u(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function e(r){if(Array.isArray(r))return r}function o(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function u(r,n){if(r){if("string"==typeof r)return a(r,n);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?a(r,n):void 0}}function a(r,n){(null==n||n>r.length)&&(n=r.length);for(var t=0,e=new Array(n);t<n;t++)e[t]=r[t];return e}function c(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}Object.defineProperty(exports,"__esModule",{value:!0});var i,f="Objects must have the same currency.";function l(r,n){if(!r)throw new Error("[Dinero.js] ".concat(n))}function v(r){return function(n,t){return r.compare(n,t)===exports.ComparisonOperator.EQ}}function s(r){return function(n,t){return r.compare(n,t)===exports.ComparisonOperator.LT}}function m(r){var n=v(r),t=s(r),e=r.zero();return function(o){if(n(o,e))return e;if(t(o,e)){var u=r.decrement(e);return r.multiply(u,o)}return o}}function p(r){return Array.isArray(r)}function y(r){return function(n){return p(n)?n.reduce((function(n,t){return r.multiply(n,t)})):n}}function d(r){return function(n,t){return r.compare(n,t)===exports.ComparisonOperator.GT}}function S(r){return function(n,t){return d(r)(n,t)||v(r)(n,t)}}function h(r){return function(n,t){var e=v(r),o=d(r),u=s(r),a=S(r),c=r.zero(),i=r.increment(c),f=t.reduce((function(n,t){return r.add(n,t)}),c);if(e(f,c))return t;for(var l=n,m=t.map((function(t){var e=r.integerDivide(r.multiply(n,t),f)||c;return l=r.subtract(l,e),e})),p=a(n,c),y=p?o:u,h=p?i:r.decrement(c),A=0;y(l,c);)e(t[A],c)||(m[A]=r.add(m[A],h),l=r.subtract(l,h)),A++;return m}}function A(r,n){var t,e;return(null==(e=r)?void 0:e.hasOwnProperty("amount"))?{amount:r.amount,scale:null!==(t=null==r?void 0:r.scale)&&void 0!==t?t:n}:{amount:r,scale:n}}function x(r){var n=v(r),t=r.zero(),e=r.increment(r.increment(t));return function(o){return n(r.modulo(o,e),t)}}function w(r){var n=v(r),t=m(r);return function(e,o){var u=t(r.modulo(e,o)),a=r.subtract(o,u);return n(a,u)}}function O(r){var n=s(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}function g(r){var n=v(r),t=s(r),e=r.zero();return function(o){if(n(o,e))return e;var u=r.increment(e),a=r.decrement(e);return t(o,e)?a:u}}function N(r){var t=n(r),e=t[0],o=t.slice(1),u=y(e.calculator),a=e.toJSON().currency,c=v(e.calculator),i=u(a.base);return o.every((function(r){var n=r.toJSON().currency,t=u(n.base);return n.code===a.code&&c(t,i)&&c(n.exponent,a.exponent)}))}exports.ComparisonOperator=void 0,(i=exports.ComparisonOperator||(exports.ComparisonOperator={}))[i.LT=-1]="LT",i[i.EQ=0]="EQ",i[i.GT=1]="GT";var b=function(r,n,t){var e=S(t)(r,t.zero()),o=t.integerDivide(r,n);return e?o:t.decrement(o)},J=function(r,n,t){var e=d(t),o=w(t),u=m(t),a=t.zero(),c=u(t.modulo(r,n)),i=e(t.subtract(n,c),c),f=e(r,t.increment(a));return o(r,n)||i&&!f||!i&&f?E(r,n,t):b(r,n,t)},E=function(r,n,t){var e=S(t)(r,t.zero()),o=t.integerDivide(r,n);return e?t.increment(o):o};function z(n){var t=d(n),e=y(n);return function(){for(var o=arguments.length,u=new Array(o),a=0;a<o;a++)u[a]=arguments[a];var c=u[0],i=u[1],f=u[2],l=void 0===f?b:f,v=c.toJSON(),s=v.amount,m=v.currency,p=v.scale,y=t(i,p),d=y?n.multiply:l,S=y?[i,p]:[p,i],h=r(S,2),A=h[0],x=h[1],w=e(m.base),O=n.power(w,n.subtract(A,x));return c.create({amount:d(s,O,n),currency:m,scale:i})}}function C(r){var n=O(r),t=z(r),e=v(r);return function(){for(var o=arguments.length,u=new Array(o),a=0;a<o;a++)u[a]=arguments[a];var c=u[0],i=c.reduce((function(r,t){var e=t.toJSON().scale;return n([r,e])}),r.zero());return c.map((function(r){var n=r.toJSON().scale;return e(n,i)?r:t(r,i)}))}}function T(r){var t=C(r),e=v(r);return function(){for(var r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];var a=o[0],c=t(a),i=n(c),f=i[0],l=i.slice(1),v=f.toJSON(),s=v.amount;return l.every((function(r){var n=r.toJSON().amount;return e(n,s)}))}}function _(n){var t=function(r){return function(n,t){return s(r)(n,t)||v(r)(n,t)}}(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=e[0],a=e[1],c=[u,a],i=c.map((function(r){return r.toJSON().amount})),f=r(i,2),l=f[0],v=f[1];return t(l,v)}}function I(n){var t=function(r){var n=d(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=e[0],a=r(u,1),c=a[0],i=c.toJSON(),f=i.currency,l=i.scale,v=t(u.map((function(r){return r.toJSON().amount})));return c.create({amount:v,currency:f,scale:l})}}function D(r){var n=function(r){var n=r.multiply;return function(r){return r.reduce((function(e,o,u){var a=r.slice(u).reduce((function(r,t){return n(r,t)}));return[].concat(t(e),[a])}),[])}}(r);return function(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=a.toJSON(),f=i.amount,l=i.currency,v=i.scale,s=r.power,m=r.integerDivide,y=r.modulo,d=p(l.base)?l.base:[l.base],S=n(d.map((function(r){return s(r,v)}))),h=S.reduce((function(r,n,e){var o=r[e],u=m(o,n),a=y(o,n);return[].concat(t(r.filter((function(r,n){return n!==e}))),[u,a])}),[f]);return c?c({value:h,currency:l}):h}}function L(r,n){var t=m(r);return function(r,e){return r.map((function(o,u){var a=0===u,c=r.length-1===u,i=n.toString(a?o:t(o));return c?i.padStart(n.toNumber(e),"0"):i})).join(".")}}exports.INVALID_AMOUNT_MESSAGE="Amount is invalid.",exports.INVALID_RATIOS_MESSAGE="Ratios are invalid.",exports.INVALID_SCALE_MESSAGE="Scale is invalid.",exports.NON_DECIMAL_CURRENCY_MESSAGE="Currency is not decimal.",exports.UNEQUAL_CURRENCIES_MESSAGE=f,exports.UNEQUAL_SCALES_MESSAGE="Objects must have the same scale.",exports.assert=l,exports.convert=function(r){var n=z(r),t=O(r),e=r.zero();return function(){for(var o=arguments.length,u=new Array(o),a=0;a<o;a++)u[a]=arguments[a];var c=u[0],i=u[1],f=u[2],l=f[i.code],v=c.toJSON(),s=v.amount,m=v.scale,p=A(l,e),y=p.amount,d=p.scale,S=r.add(m,d);return n(c.create({amount:r.multiply(s,y),currency:i,scale:S}),t([S,i.exponent]))}},exports.createDinero=function(r){var n=r.calculator,t=r.onCreate,e=r.formatter,o=void 0===e?{toNumber:Number,toString:String}:e;return function r(e){var u=e.amount,a=e.currency,c=a.code,i=a.base,f=a.exponent,l=e.scale,v=void 0===l?f:l,s={code:c,base:i,exponent:f};return null==t||t({amount:u,currency:s,scale:v}),{calculator:n,formatter:o,create:r,toJSON:function(){return{amount:u,currency:s,scale:v}}}}},exports.down=b,exports.equal=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var o=t[0],u=t[1];return T(r)([o,u])&&N([o,u])}},exports.halfAwayFromZero=function(r,n,t){var e=g(t),o=w(t),u=m(t);return o(r,n)?t.multiply(e(r),E(u(r),n,t)):J(r,n,t)},exports.halfDown=function(r,n,t){return w(t)(r,n)?b(r,n,t):J(r,n,t)},exports.halfEven=function(r,n,t){var e=x(t),o=w(t),u=J(r,n,t);return o(r,n)?e(u)?u:t.decrement(u):u},exports.halfOdd=function(r,n,t){var e=x(t),o=w(t),u=J(r,n,t);return o(r,n)&&e(u)?t.decrement(u):u},exports.halfTowardsZero=function(r,n,t){var e=g(t),o=w(t),u=m(t);return o(r,n)?t.multiply(e(r),b(u(r),n,t)):J(r,n,t)},exports.halfUp=J,exports.hasSubUnits=function(r){var n=v(r),t=y(r);return function(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];var a=o[0],c=a.toJSON(),i=c.amount,f=c.currency,l=c.scale,v=t(f.base);return!n(r.modulo(i,r.power(v,l)),r.zero())}},exports.haveSameAmount=T,exports.haveSameCurrency=N,exports.isNegative=function(r){var n=s(r);return function(){for(var t=arguments.length,e=new Array(t),o=0;o<t;o++)e[o]=arguments[o];var u=e[0],a=u.toJSON(),c=a.amount;return n(c,r.zero())}},exports.isPositive=function(r){var n=S(r);return function(){for(var t=arguments.length,e=new Array(t),o=0;o<t;o++)e[o]=arguments[o];var u=e[0],a=u.toJSON(),c=a.amount;return n(c,r.zero())}},exports.isZero=function(r){var n=v(r);return function(){for(var t=arguments.length,e=new Array(t),o=0;o<t;o++)e[o]=arguments[o];var u=e[0],a=u.toJSON(),c=a.amount;return n(c,r.zero())}},exports.multiply=function(r){var n=z(r),t=r.zero();return function(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=a.toJSON(),f=i.amount,l=i.currency,v=i.scale,s=A(c,t),m=s.amount,p=s.scale,y=r.add(v,p);return n(a.create({amount:r.multiply(f,m),currency:l,scale:y}),y)}},exports.normalizeScale=C,exports.safeAdd=function(n){var t=C(n),e=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var o=t[0],u=t[1],a=o.toJSON(),c=a.amount,i=a.currency,f=a.scale,l=u.toJSON().amount,v=r.add(c,l);return o.create({amount:v,currency:i,scale:f})}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeAllocate=function(r){var n=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var o=t[0],u=t[1],a=o.toJSON(),c=a.amount,i=a.currency,f=a.scale;return h(r)(c,u.map((function(r){return r.amount}))).map((function(r){return o.create({amount:r,currency:i,scale:f})}))}}(r),t=S(r),e=d(r),o=z(r),u=O(r),a=v(r),c=r.zero(),i=new Array(10).fill(null).reduce(r.increment,c);return function(){for(var f=arguments.length,v=new Array(f),s=0;s<f;s++)v[s]=arguments[s];var m=v[0],p=v[1],y=p.length>0,d=p.map((function(r){return A(r,c)})),S=y?u(d.map((function(r){return r.scale}))):c,h=d.map((function(n){var t=n.amount,e=n.scale,o=a(e,S)?c:r.subtract(S,e);return{amount:r.multiply(t,r.power(i,o)),scale:e}})),x=h.every((function(r){var n=r.amount;return t(n,c)})),w=h.some((function(r){var n=r.amount;return e(n,c)})),O=y&&x&&w;l(O,"Ratios are invalid.");var g=m.toJSON(),N=g.scale,b=r.add(N,S);return n(o(m,b),h)}},exports.safeCompare=function(n){var t=C(n),e=function(n){var t=function(r){return function(n,t){return r.compare(n,t)}}(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=r([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),a=u[0],c=u[1];return t(a,c)}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeGreaterThan=function(n){var t=C(n),e=function(n){var t=d(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=r([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),a=u[0],c=u[1];return t(a,c)}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeGreaterThanOrEqual=function(n){var t=C(n),e=function(n){var t=S(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=r([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),a=u[0],c=u[1];return t(a,c)}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeLessThan=function(n){var t=C(n),e=function(n){var t=s(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=r([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),a=u[0],c=u[1];return t(a,c)}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeLessThanOrEqual=function(n){var t=C(n),e=_(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeMaximum=function(n){var t=C(n),e=function(n){var t=O(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=e[0],a=r(u,1)[0],c=a.toJSON(),i=c.currency,f=c.scale,l=t(u.map((function(r){return r.toJSON().amount})));return a.create({amount:l,currency:i,scale:f})}}(n);return function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];var u=n[0],a=N(u);l(a,f);var c=t(u);return e(c)}},exports.safeMinimum=function(r){var n=C(r),t=I(r);return function(){for(var r=arguments.length,e=new Array(r),o=0;o<r;o++)e[o]=arguments[o];var u=e[0],a=N(u);l(a,f);var c=n(u);return t(c)}},exports.safeSubtract=function(n){var t=C(n),e=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var o=t[0],u=t[1],a=o.toJSON(),c=a.amount,i=a.currency,f=a.scale,l=u.toJSON().amount,v=r.subtract(c,l);return o.create({amount:v,currency:i,scale:f})}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.toDecimal=function(r){var n=D(r),t=y(r),e=v(r);return function(){for(var o=arguments.length,u=new Array(o),a=0;a<o;a++)u[a]=arguments[a];var c=u[0],i=u[1],f=c.toJSON(),v=f.currency,s=f.scale,m=t(v.base),y=r.zero(),d=new Array(10).fill(null).reduce(r.increment,y),S=p(v.base),h=e(r.modulo(m,d),y),A=!S&&h;l(A,"Currency is not decimal.");var x=n(c),w=L(r,c.formatter),O=w(x,s);return i?i({value:O,currency:v}):O}},exports.toSnapshot=function(r){return r.toJSON()},exports.toUnits=D,exports.transformScale=z,exports.trimScale=function(r){var n=function(r){var n=v(r);return function(t,e){var o=r.zero();if(n(o,t))return r.zero();for(var u=o,a=t;n(r.modulo(a,e),o);)a=r.integerDivide(a,e),u=r.increment(u);return u}}(r),t=v(r),e=O(r),o=z(r),u=y(r);return function(){for(var a=arguments.length,c=new Array(a),i=0;i<a;i++)c[i]=arguments[i];var f=c[0],l=f.toJSON(),v=l.amount,s=l.currency,m=l.scale,p=u(s.base),y=n(v,p),d=r.subtract(m,y),S=e([d,s.exponent]);return t(S,m)?f:o(f,S)}},exports.up=E; | ||
/*! @dinero.js/core 2.0.0-alpha.13 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
"use strict";function r(r,n){return e(r)||function(r,n){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null==t)return;var e,o,u=[],a=!0,c=!1;try{for(t=t.call(r);!(a=(e=t.next()).done)&&(u.push(e.value),!n||u.length!==n);a=!0);}catch(r){c=!0,o=r}finally{try{a||null==t.return||t.return()}finally{if(c)throw o}}return u}(r,n)||u(r,n)||c()}function n(r){return e(r)||o(r)||u(r)||c()}function t(r){return function(r){if(Array.isArray(r))return a(r)}(r)||o(r)||u(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function e(r){if(Array.isArray(r))return r}function o(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function u(r,n){if(r){if("string"==typeof r)return a(r,n);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?a(r,n):void 0}}function a(r,n){(null==n||n>r.length)&&(n=r.length);for(var t=0,e=new Array(n);t<n;t++)e[t]=r[t];return e}function c(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}Object.defineProperty(exports,"__esModule",{value:!0});var i,f="Objects must have the same currency.";function l(r,n){if(!r)throw new Error("[Dinero.js] ".concat(n))}function v(r){return function(n,t){return r.compare(n,t)===exports.ComparisonOperator.EQ}}function s(r){return function(n,t){return r.compare(n,t)===exports.ComparisonOperator.LT}}function m(r){var n=v(r),t=s(r),e=r.zero();return function(o){if(n(o,e))return e;if(t(o,e)){var u=r.decrement(e);return r.multiply(u,o)}return o}}function p(r){return Array.isArray(r)}function y(r){return function(n){return p(n)?n.reduce((function(n,t){return r.multiply(n,t)})):n}}function d(r){return function(n,t){return r.compare(n,t)===exports.ComparisonOperator.GT}}function S(r){return function(n,t){return d(r)(n,t)||v(r)(n,t)}}function A(r){return function(n,t){var e=v(r),o=d(r),u=s(r),a=S(r),c=r.zero(),i=r.increment(c),f=t.reduce((function(n,t){return r.add(n,t)}),c);if(e(f,c))return t;for(var l=n,m=t.map((function(t){var e=r.integerDivide(r.multiply(n,t),f)||c;return l=r.subtract(l,e),e})),p=a(n,c),y=p?o:u,A=p?i:r.decrement(c),h=0;y(l,c);)e(t[h],c)||(m[h]=r.add(m[h],A),l=r.subtract(l,A)),h++;return m}}function h(r,n){var t,e;return(null==(e=r)?void 0:e.hasOwnProperty("amount"))?{amount:r.amount,scale:null!==(t=null==r?void 0:r.scale)&&void 0!==t?t:n}:{amount:r,scale:n}}function x(r){var n=v(r),t=r.zero(),e=r.increment(r.increment(t));return function(o){return n(r.modulo(o,e),t)}}function w(r){var n=v(r),t=m(r);return function(e,o){var u=t(r.modulo(e,o)),a=r.subtract(o,u);return n(a,u)}}function O(r){var n=s(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}function g(r){var n=v(r),t=s(r),e=r.zero();return function(o){if(n(o,e))return e;var u=r.increment(e),a=r.decrement(e);return t(o,e)?a:u}}function N(r){var t=n(r),e=t[0],o=t.slice(1),u=y(e.calculator),a=e.toJSON().currency,c=v(e.calculator),i=u(a.base);return o.every((function(r){var n=r.toJSON().currency,t=u(n.base);return n.code===a.code&&c(t,i)&&c(n.exponent,a.exponent)}))}exports.ComparisonOperator=void 0,(i=exports.ComparisonOperator||(exports.ComparisonOperator={}))[i.LT=-1]="LT",i[i.EQ=0]="EQ",i[i.GT=1]="GT";var b=function(r,n,t){var e=S(t)(r,t.zero()),o=t.integerDivide(r,n);return e?o:t.decrement(o)},J=function(r,n,t){var e=d(t),o=w(t),u=m(t),a=t.zero(),c=u(t.modulo(r,n)),i=e(t.subtract(n,c),c),f=e(r,t.increment(a));return o(r,n)||i&&!f||!i&&f?E(r,n,t):b(r,n,t)},E=function(r,n,t){var e=S(t)(r,t.zero()),o=t.integerDivide(r,n);return e?t.increment(o):o};function z(n){var t=d(n),e=y(n);return function(){for(var o=arguments.length,u=new Array(o),a=0;a<o;a++)u[a]=arguments[a];var c=u[0],i=u[1],f=u[2],l=void 0===f?b:f,v=c.toJSON(),s=v.amount,m=v.currency,p=v.scale,y=t(i,p),d=y?n.multiply:l,S=y?[i,p]:[p,i],A=r(S,2),h=A[0],x=A[1],w=e(m.base),O=n.power(w,n.subtract(h,x));return c.create({amount:d(s,O,n),currency:m,scale:i})}}function C(r){var n=O(r),t=z(r),e=v(r);return function(){for(var o=arguments.length,u=new Array(o),a=0;a<o;a++)u[a]=arguments[a];var c=u[0],i=c.reduce((function(r,t){var e=t.toJSON().scale;return n([r,e])}),r.zero());return c.map((function(r){var n=r.toJSON().scale;return e(n,i)?r:t(r,i)}))}}function T(r){var t=C(r),e=v(r);return function(){for(var r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];var a=o[0],c=t(a),i=n(c),f=i[0],l=i.slice(1),v=f.toJSON(),s=v.amount;return l.every((function(r){var n=r.toJSON().amount;return e(n,s)}))}}function _(n){var t=function(r){return function(n,t){return s(r)(n,t)||v(r)(n,t)}}(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=e[0],a=e[1],c=[u,a],i=c.map((function(r){return r.toJSON().amount})),f=r(i,2),l=f[0],v=f[1];return t(l,v)}}function I(n){var t=function(r){var n=d(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=e[0],a=r(u,1),c=a[0],i=c.toJSON(),f=i.currency,l=i.scale,v=t(u.map((function(r){return r.toJSON().amount})));return c.create({amount:v,currency:f,scale:l})}}function D(r){var n=function(r){var n=r.multiply;return function(r){return r.reduce((function(e,o,u){var a=r.slice(u).reduce((function(r,t){return n(r,t)}));return[].concat(t(e),[a])}),[])}}(r);return function(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=a.toJSON(),f=i.amount,l=i.currency,v=i.scale,s=r.power,m=r.integerDivide,y=r.modulo,d=p(l.base)?l.base:[l.base],S=n(d.map((function(r){return s(r,v)}))),A=S.reduce((function(r,n,e){var o=r[e],u=m(o,n),a=y(o,n);return[].concat(t(r.filter((function(r,n){return n!==e}))),[u,a])}),[f]);return c?c({value:A,currency:l}):A}}function L(r,n){var t=m(r),e=v(r),o=s(r),u=r.zero();return function(r,a){var c=n.toString(r[0]),i=n.toString(t(r[1])),f=n.toNumber(a),l="".concat(c,".").concat(i.padStart(f,"0")),v=e(r[0],u),s=o(r[1],u);return v&&s?"-".concat(l):l}}exports.INVALID_AMOUNT_MESSAGE="Amount is invalid.",exports.INVALID_RATIOS_MESSAGE="Ratios are invalid.",exports.INVALID_SCALE_MESSAGE="Scale is invalid.",exports.NON_DECIMAL_CURRENCY_MESSAGE="Currency is not decimal.",exports.UNEQUAL_CURRENCIES_MESSAGE=f,exports.UNEQUAL_SCALES_MESSAGE="Objects must have the same scale.",exports.assert=l,exports.convert=function(r){var n=z(r),t=O(r),e=r.zero();return function(){for(var o=arguments.length,u=new Array(o),a=0;a<o;a++)u[a]=arguments[a];var c=u[0],i=u[1],f=u[2],l=f[i.code],v=c.toJSON(),s=v.amount,m=v.scale,p=h(l,e),y=p.amount,d=p.scale,S=r.add(m,d);return n(c.create({amount:r.multiply(s,y),currency:i,scale:S}),t([S,i.exponent]))}},exports.createDinero=function(r){var n=r.calculator,t=r.onCreate,e=r.formatter,o=void 0===e?{toNumber:Number,toString:String}:e;return function r(e){var u=e.amount,a=e.currency,c=a.code,i=a.base,f=a.exponent,l=e.scale,v=void 0===l?f:l,s={code:c,base:i,exponent:f};return null==t||t({amount:u,currency:s,scale:v}),{calculator:n,formatter:o,create:r,toJSON:function(){return{amount:u,currency:s,scale:v}}}}},exports.down=b,exports.equal=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var o=t[0],u=t[1];return T(r)([o,u])&&N([o,u])}},exports.halfAwayFromZero=function(r,n,t){var e=g(t),o=w(t),u=m(t);return o(r,n)?t.multiply(e(r),E(u(r),n,t)):J(r,n,t)},exports.halfDown=function(r,n,t){return w(t)(r,n)?b(r,n,t):J(r,n,t)},exports.halfEven=function(r,n,t){var e=x(t),o=w(t),u=J(r,n,t);return o(r,n)?e(u)?u:t.decrement(u):u},exports.halfOdd=function(r,n,t){var e=x(t),o=w(t),u=J(r,n,t);return o(r,n)&&e(u)?t.decrement(u):u},exports.halfTowardsZero=function(r,n,t){var e=g(t),o=w(t),u=m(t);return o(r,n)?t.multiply(e(r),b(u(r),n,t)):J(r,n,t)},exports.halfUp=J,exports.hasSubUnits=function(r){var n=v(r),t=y(r);return function(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];var a=o[0],c=a.toJSON(),i=c.amount,f=c.currency,l=c.scale,v=t(f.base);return!n(r.modulo(i,r.power(v,l)),r.zero())}},exports.haveSameAmount=T,exports.haveSameCurrency=N,exports.isNegative=function(r){var n=s(r);return function(){for(var t=arguments.length,e=new Array(t),o=0;o<t;o++)e[o]=arguments[o];var u=e[0],a=u.toJSON(),c=a.amount;return n(c,r.zero())}},exports.isPositive=function(r){var n=S(r);return function(){for(var t=arguments.length,e=new Array(t),o=0;o<t;o++)e[o]=arguments[o];var u=e[0],a=u.toJSON(),c=a.amount;return n(c,r.zero())}},exports.isZero=function(r){var n=v(r);return function(){for(var t=arguments.length,e=new Array(t),o=0;o<t;o++)e[o]=arguments[o];var u=e[0],a=u.toJSON(),c=a.amount;return n(c,r.zero())}},exports.multiply=function(r){var n=z(r),t=r.zero();return function(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=a.toJSON(),f=i.amount,l=i.currency,v=i.scale,s=h(c,t),m=s.amount,p=s.scale,y=r.add(v,p);return n(a.create({amount:r.multiply(f,m),currency:l,scale:y}),y)}},exports.normalizeScale=C,exports.safeAdd=function(n){var t=C(n),e=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var o=t[0],u=t[1],a=o.toJSON(),c=a.amount,i=a.currency,f=a.scale,l=u.toJSON().amount,v=r.add(c,l);return o.create({amount:v,currency:i,scale:f})}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeAllocate=function(r){var n=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var o=t[0],u=t[1],a=o.toJSON(),c=a.amount,i=a.currency,f=a.scale;return A(r)(c,u.map((function(r){return r.amount}))).map((function(r){return o.create({amount:r,currency:i,scale:f})}))}}(r),t=S(r),e=d(r),o=z(r),u=O(r),a=v(r),c=r.zero(),i=new Array(10).fill(null).reduce(r.increment,c);return function(){for(var f=arguments.length,v=new Array(f),s=0;s<f;s++)v[s]=arguments[s];var m=v[0],p=v[1],y=p.length>0,d=p.map((function(r){return h(r,c)})),S=y?u(d.map((function(r){return r.scale}))):c,A=d.map((function(n){var t=n.amount,e=n.scale,o=a(e,S)?c:r.subtract(S,e);return{amount:r.multiply(t,r.power(i,o)),scale:e}})),x=A.every((function(r){var n=r.amount;return t(n,c)})),w=A.some((function(r){var n=r.amount;return e(n,c)})),O=y&&x&&w;l(O,"Ratios are invalid.");var g=m.toJSON(),N=g.scale,b=r.add(N,S);return n(o(m,b),A)}},exports.safeCompare=function(n){var t=C(n),e=function(n){var t=function(r){return function(n,t){return r.compare(n,t)}}(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=r([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),a=u[0],c=u[1];return t(a,c)}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeGreaterThan=function(n){var t=C(n),e=function(n){var t=d(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=r([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),a=u[0],c=u[1];return t(a,c)}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeGreaterThanOrEqual=function(n){var t=C(n),e=function(n){var t=S(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=r([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),a=u[0],c=u[1];return t(a,c)}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeLessThan=function(n){var t=C(n),e=function(n){var t=s(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=r([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),a=u[0],c=u[1];return t(a,c)}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeLessThanOrEqual=function(n){var t=C(n),e=_(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.safeMaximum=function(n){var t=C(n),e=function(n){var t=O(n);return function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];var u=e[0],a=r(u,1)[0],c=a.toJSON(),i=c.currency,f=c.scale,l=t(u.map((function(r){return r.toJSON().amount})));return a.create({amount:l,currency:i,scale:f})}}(n);return function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];var u=n[0],a=N(u);l(a,f);var c=t(u);return e(c)}},exports.safeMinimum=function(r){var n=C(r),t=I(r);return function(){for(var r=arguments.length,e=new Array(r),o=0;o<r;o++)e[o]=arguments[o];var u=e[0],a=N(u);l(a,f);var c=n(u);return t(c)}},exports.safeSubtract=function(n){var t=C(n),e=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var o=t[0],u=t[1],a=o.toJSON(),c=a.amount,i=a.currency,f=a.scale,l=u.toJSON().amount,v=r.subtract(c,l);return o.create({amount:v,currency:i,scale:f})}}(n);return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];var a=o[0],c=o[1],i=N([a,c]);l(i,f);var v=t([a,c]),s=r(v,2),m=s[0],p=s[1];return e(m,p)}},exports.toDecimal=function(r){var n=D(r),t=y(r),e=v(r);return function(){for(var o=arguments.length,u=new Array(o),a=0;a<o;a++)u[a]=arguments[a];var c=u[0],i=u[1],f=c.toJSON(),v=f.currency,s=f.scale,m=t(v.base),y=r.zero(),d=new Array(10).fill(null).reduce(r.increment,y),S=p(v.base),A=e(r.modulo(m,d),y),h=!S&&A;l(h,"Currency is not decimal.");var x=n(c),w=L(r,c.formatter),O=w(x,s);return i?i({value:O,currency:v}):O}},exports.toSnapshot=function(r){return r.toJSON()},exports.toUnits=D,exports.transformScale=z,exports.trimScale=function(r){var n=function(r){var n=v(r);return function(t,e){var o=r.zero();if(n(o,t))return r.zero();for(var u=o,a=t;n(r.modulo(a,e),o);)a=r.integerDivide(a,e),u=r.increment(u);return u}}(r),t=v(r),e=O(r),o=z(r),u=y(r);return function(){for(var a=arguments.length,c=new Array(a),i=0;i<a;i++)c[i]=arguments[i];var f=c[0],l=f.toJSON(),v=l.amount,s=l.currency,m=l.scale,p=u(s.base),y=n(v,p),d=r.subtract(m,y),S=e([d,s.exponent]);return t(S,m)?f:o(f,S)}},exports.up=E; | ||
//# sourceMappingURL=index.production.js.map |
import { NON_DECIMAL_CURRENCY_MESSAGE } from '../checks'; | ||
import { assert } from '../helpers'; | ||
import { absolute, computeBase, equal, isArray } from '../utils'; | ||
import { absolute, computeBase, equal, isArray, lessThan } from '../utils'; | ||
import { toUnits } from './toUnits'; | ||
@@ -41,13 +41,17 @@ export function toDecimal(calculator) { | ||
var absoluteFn = absolute(calculator); | ||
var equalFn = equal(calculator); | ||
var lessThanFn = lessThan(calculator); | ||
var zero = calculator.zero(); | ||
return function (units, scale) { | ||
return units.map(function (unit, index) { | ||
var isFirst = index === 0; | ||
var isLast = units.length - 1 === index; | ||
var unitAsString = formatter.toString(isFirst ? unit : absoluteFn(unit)); | ||
if (isLast) { | ||
return unitAsString.padStart(formatter.toNumber(scale), '0'); | ||
} | ||
return unitAsString; | ||
}).join('.'); | ||
var whole = formatter.toString(units[0]); | ||
var fractional = formatter.toString(absoluteFn(units[1])); | ||
var scaleNumber = formatter.toNumber(scale); | ||
var decimal = "".concat(whole, ".").concat(fractional.padStart(scaleNumber, '0')); | ||
var leadsWithZero = equalFn(units[0], zero); | ||
var isNegative = lessThanFn(units[1], zero); | ||
// A leading negative zero is a special case because the `toString` | ||
// formatter won't preserve its negative sign (since 0 === -0). | ||
return leadsWithZero && isNegative ? "-".concat(decimal) : decimal; | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.12 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
/*! @dinero.js/core 2.0.0-alpha.13 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
(function (global, factory) { | ||
@@ -1205,12 +1205,16 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
var absoluteFn = absolute(calculator); | ||
var equalFn = equal$1(calculator); | ||
var lessThanFn = lessThan(calculator); | ||
var zero = calculator.zero(); | ||
return function (units, scale) { | ||
return units.map(function (unit, index) { | ||
var isFirst = index === 0; | ||
var isLast = units.length - 1 === index; | ||
var unitAsString = formatter.toString(isFirst ? unit : absoluteFn(unit)); | ||
if (isLast) { | ||
return unitAsString.padStart(formatter.toNumber(scale), '0'); | ||
} | ||
return unitAsString; | ||
}).join('.'); | ||
var whole = formatter.toString(units[0]); | ||
var fractional = formatter.toString(absoluteFn(units[1])); | ||
var scaleNumber = formatter.toNumber(scale); | ||
var decimal = "".concat(whole, ".").concat(fractional.padStart(scaleNumber, '0')); | ||
var leadsWithZero = equalFn(units[0], zero); | ||
var isNegative = lessThanFn(units[1], zero); | ||
// A leading negative zero is a special case because the `toString` | ||
// formatter won't preserve its negative sign (since 0 === -0). | ||
return leadsWithZero && isNegative ? "-".concat(decimal) : decimal; | ||
}; | ||
@@ -1217,0 +1221,0 @@ } |
@@ -1,3 +0,3 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.12 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((r="undefined"!=typeof globalThis?globalThis:r||self)["@dinero.js/core"]={})}(this,(function(r){"use strict";function n(r,n){return u(r)||function(r,n){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null==t)return;var e,u,a=[],o=!0,c=!1;try{for(t=t.call(r);!(o=(e=t.next()).done)&&(a.push(e.value),!n||a.length!==n);o=!0);}catch(r){c=!0,u=r}finally{try{o||null==t.return||t.return()}finally{if(c)throw u}}return a}(r,n)||o(r,n)||i()}function t(r){return u(r)||a(r)||o(r)||i()}function e(r){return function(r){if(Array.isArray(r))return c(r)}(r)||a(r)||o(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(r){if(Array.isArray(r))return r}function a(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function o(r,n){if(r){if("string"==typeof r)return c(r,n);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?c(r,n):void 0}}function c(r,n){(null==n||n>r.length)&&(n=r.length);for(var t=0,e=new Array(n);t<n;t++)e[t]=r[t];return e}function i(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,l="Ratios are invalid.",v="Objects must have the same currency.",m="Currency is not decimal.";function s(r,n){if(!r)throw new Error("[Dinero.js] ".concat(n))}function y(n){return function(t,e){return n.compare(t,e)===r.ComparisonOperator.EQ}}function d(n){return function(t,e){return n.compare(t,e)===r.ComparisonOperator.LT}}function p(r){var n=y(r),t=d(r),e=r.zero();return function(u){if(n(u,e))return e;if(t(u,e)){var a=r.decrement(e);return r.multiply(a,u)}return u}}function S(r){return Array.isArray(r)}function h(r){return function(n){return S(n)?n.reduce((function(n,t){return r.multiply(n,t)})):n}}function A(n){return function(t,e){return n.compare(t,e)===r.ComparisonOperator.GT}}function g(r){return function(n,t){return A(r)(n,t)||y(r)(n,t)}}function w(r){return function(n,t){var e=y(r),u=A(r),a=d(r),o=g(r),c=r.zero(),i=r.increment(c),f=t.reduce((function(n,t){return r.add(n,t)}),c);if(e(f,c))return t;for(var l=n,v=t.map((function(t){var e=r.integerDivide(r.multiply(n,t),f)||c;return l=r.subtract(l,e),e})),m=o(n,c),s=m?u:a,p=m?i:r.decrement(c),S=0;s(l,c);)e(t[S],c)||(v[S]=r.add(v[S],p),l=r.subtract(l,p)),S++;return v}}function O(r,n){var t,e;return(null==(e=r)?void 0:e.hasOwnProperty("amount"))?{amount:r.amount,scale:null!==(t=null==r?void 0:r.scale)&&void 0!==t?t:n}:{amount:r,scale:n}}function b(r){var n=y(r),t=r.zero(),e=r.increment(r.increment(t));return function(u){return n(r.modulo(u,e),t)}}function N(r){var n=y(r),t=p(r);return function(e,u){var a=t(r.modulo(e,u)),o=r.subtract(u,a);return n(o,a)}}function J(r){var n=d(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}function E(r){var n=y(r),t=d(r),e=r.zero();return function(u){if(n(u,e))return e;var a=r.increment(e),o=r.decrement(e);return t(u,e)?o:a}}function z(r){var n=t(r),e=n[0],u=n.slice(1),a=h(e.calculator),o=e.toJSON().currency,c=y(e.calculator),i=a(o.base);return u.every((function(r){var n=r.toJSON().currency,t=a(n.base);return n.code===o.code&&c(t,i)&&c(n.exponent,o.exponent)}))}r.ComparisonOperator=void 0,(f=r.ComparisonOperator||(r.ComparisonOperator={}))[f.LT=-1]="LT",f[f.EQ=0]="EQ",f[f.GT=1]="GT";var C=function(r,n,t){var e=g(t)(r,t.zero()),u=t.integerDivide(r,n);return e?u:t.decrement(u)},T=function(r,n,t){var e=A(t),u=N(t),a=p(t),o=t.zero(),c=a(t.modulo(r,n)),i=e(t.subtract(n,c),c),f=e(r,t.increment(o));return u(r,n)||i&&!f||!i&&f?_(r,n,t):C(r,n,t)},_=function(r,n,t){var e=g(t)(r,t.zero()),u=t.integerDivide(r,n);return e?t.increment(u):u};function I(r){var t=A(r),e=h(r);return function(){for(var u=arguments.length,a=new Array(u),o=0;o<u;o++)a[o]=arguments[o];var c=a[0],i=a[1],f=a[2],l=void 0===f?C:f,v=c.toJSON(),m=v.amount,s=v.currency,y=v.scale,d=t(i,y),p=d?r.multiply:l,S=d?[i,y]:[y,i],h=n(S,2),A=h[0],g=h[1],w=e(s.base),O=r.power(w,r.subtract(A,g));return c.create({amount:p(m,O,r),currency:s,scale:i})}}function D(r){var n=J(r),t=I(r),e=y(r);return function(){for(var u=arguments.length,a=new Array(u),o=0;o<u;o++)a[o]=arguments[o];var c=a[0],i=c.reduce((function(r,t){var e=t.toJSON().scale;return n([r,e])}),r.zero());return c.map((function(r){var n=r.toJSON().scale;return e(n,i)?r:t(r,i)}))}}function L(r){var n=D(r),e=y(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=n(o),i=t(c),f=i[0],l=i.slice(1),v=f.toJSON(),m=v.amount;return l.every((function(r){var n=r.toJSON().amount;return e(n,m)}))}}function M(r){var t=function(r){return function(n,t){return d(r)(n,t)||y(r)(n,t)}}(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=e[0],o=e[1],c=[a,o],i=c.map((function(r){return r.toJSON().amount})),f=n(i,2),l=f[0],v=f[1];return t(l,v)}}function j(r){var t=function(r){var n=A(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=e[0],o=n(a,1),c=o[0],i=c.toJSON(),f=i.currency,l=i.scale,v=t(a.map((function(r){return r.toJSON().amount})));return c.create({amount:v,currency:f,scale:l})}}function x(r){var n=function(r){var n=r.multiply;return function(r){return r.reduce((function(t,u,a){var o=r.slice(a).reduce((function(r,t){return n(r,t)}));return[].concat(e(t),[o])}),[])}}(r);return function(){for(var t=arguments.length,u=new Array(t),a=0;a<t;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=o.toJSON(),f=i.amount,l=i.currency,v=i.scale,m=r.power,s=r.integerDivide,y=r.modulo,d=S(l.base)?l.base:[l.base],p=n(d.map((function(r){return m(r,v)}))),h=p.reduce((function(r,n,t){var u=r[t],a=s(u,n),o=y(u,n);return[].concat(e(r.filter((function(r,n){return n!==t}))),[a,o])}),[f]);return c?c({value:h,currency:l}):h}}function G(r,n){var t=p(r);return function(r,e){return r.map((function(u,a){var o=0===a,c=r.length-1===a,i=n.toString(o?u:t(u));return c?i.padStart(n.toNumber(e),"0"):i})).join(".")}}r.INVALID_AMOUNT_MESSAGE="Amount is invalid.",r.INVALID_RATIOS_MESSAGE=l,r.INVALID_SCALE_MESSAGE="Scale is invalid.",r.NON_DECIMAL_CURRENCY_MESSAGE=m,r.UNEQUAL_CURRENCIES_MESSAGE=v,r.UNEQUAL_SCALES_MESSAGE="Objects must have the same scale.",r.assert=s,r.convert=function(r){var n=I(r),t=J(r),e=r.zero();return function(){for(var u=arguments.length,a=new Array(u),o=0;o<u;o++)a[o]=arguments[o];var c=a[0],i=a[1],f=a[2],l=f[i.code],v=c.toJSON(),m=v.amount,s=v.scale,y=O(l,e),d=y.amount,p=y.scale,S=r.add(s,p);return n(c.create({amount:r.multiply(m,d),currency:i,scale:S}),t([S,i.exponent]))}},r.createDinero=function(r){var n=r.calculator,t=r.onCreate,e=r.formatter,u=void 0===e?{toNumber:Number,toString:String}:e;return function r(e){var a=e.amount,o=e.currency,c=o.code,i=o.base,f=o.exponent,l=e.scale,v=void 0===l?f:l,m={code:c,base:i,exponent:f};return null==t||t({amount:a,currency:m,scale:v}),{calculator:n,formatter:u,create:r,toJSON:function(){return{amount:a,currency:m,scale:v}}}}},r.down=C,r.equal=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var u=t[0],a=t[1];return L(r)([u,a])&&z([u,a])}},r.halfAwayFromZero=function(r,n,t){var e=E(t),u=N(t),a=p(t);return u(r,n)?t.multiply(e(r),_(a(r),n,t)):T(r,n,t)},r.halfDown=function(r,n,t){return N(t)(r,n)?C(r,n,t):T(r,n,t)},r.halfEven=function(r,n,t){var e=b(t),u=N(t),a=T(r,n,t);return u(r,n)?e(a)?a:t.decrement(a):a},r.halfOdd=function(r,n,t){var e=b(t),u=N(t),a=T(r,n,t);return u(r,n)&&e(a)?t.decrement(a):a},r.halfTowardsZero=function(r,n,t){var e=E(t),u=N(t),a=p(t);return u(r,n)?t.multiply(e(r),C(a(r),n,t)):T(r,n,t)},r.halfUp=T,r.hasSubUnits=function(r){var n=y(r),t=h(r);return function(){for(var e=arguments.length,u=new Array(e),a=0;a<e;a++)u[a]=arguments[a];var o=u[0],c=o.toJSON(),i=c.amount,f=c.currency,l=c.scale,v=t(f.base);return!n(r.modulo(i,r.power(v,l)),r.zero())}},r.haveSameAmount=L,r.haveSameCurrency=z,r.isNegative=function(r){var n=d(r);return function(){for(var t=arguments.length,e=new Array(t),u=0;u<t;u++)e[u]=arguments[u];var a=e[0],o=a.toJSON(),c=o.amount;return n(c,r.zero())}},r.isPositive=function(r){var n=g(r);return function(){for(var t=arguments.length,e=new Array(t),u=0;u<t;u++)e[u]=arguments[u];var a=e[0],o=a.toJSON(),c=o.amount;return n(c,r.zero())}},r.isZero=function(r){var n=y(r);return function(){for(var t=arguments.length,e=new Array(t),u=0;u<t;u++)e[u]=arguments[u];var a=e[0],o=a.toJSON(),c=o.amount;return n(c,r.zero())}},r.multiply=function(r){var n=I(r),t=r.zero();return function(){for(var e=arguments.length,u=new Array(e),a=0;a<e;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=o.toJSON(),f=i.amount,l=i.currency,v=i.scale,m=O(c,t),s=m.amount,y=m.scale,d=r.add(v,y);return n(o.create({amount:r.multiply(f,s),currency:l,scale:d}),d)}},r.normalizeScale=D,r.safeAdd=function(r){var t=D(r),e=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var u=t[0],a=t[1],o=u.toJSON(),c=o.amount,i=o.currency,f=o.scale,l=a.toJSON().amount,v=r.add(c,l);return u.create({amount:v,currency:i,scale:f})}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeAllocate=function(r){var n=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var u=t[0],a=t[1],o=u.toJSON(),c=o.amount,i=o.currency,f=o.scale;return w(r)(c,a.map((function(r){return r.amount}))).map((function(r){return u.create({amount:r,currency:i,scale:f})}))}}(r),t=g(r),e=A(r),u=I(r),a=J(r),o=y(r),c=r.zero(),i=new Array(10).fill(null).reduce(r.increment,c);return function(){for(var f=arguments.length,v=new Array(f),m=0;m<f;m++)v[m]=arguments[m];var y=v[0],d=v[1],p=d.length>0,S=d.map((function(r){return O(r,c)})),h=p?a(S.map((function(r){return r.scale}))):c,A=S.map((function(n){var t=n.amount,e=n.scale,u=o(e,h)?c:r.subtract(h,e);return{amount:r.multiply(t,r.power(i,u)),scale:e}})),g=A.every((function(r){var n=r.amount;return t(n,c)})),w=A.some((function(r){var n=r.amount;return e(n,c)})),b=p&&g&&w;s(b,l);var N=y.toJSON(),J=N.scale,E=r.add(J,h);return n(u(y,E),A)}},r.safeCompare=function(r){var t=D(r),e=function(r){var t=function(r){return function(n,t){return r.compare(n,t)}}(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=n([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),o=a[0],c=a[1];return t(o,c)}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeGreaterThan=function(r){var t=D(r),e=function(r){var t=A(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=n([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),o=a[0],c=a[1];return t(o,c)}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeGreaterThanOrEqual=function(r){var t=D(r),e=function(r){var t=g(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=n([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),o=a[0],c=a[1];return t(o,c)}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeLessThan=function(r){var t=D(r),e=function(r){var t=d(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=n([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),o=a[0],c=a[1];return t(o,c)}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeLessThanOrEqual=function(r){var t=D(r),e=M(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeMaximum=function(r){var t=D(r),e=function(r){var t=J(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=e[0],o=n(a,1)[0],c=o.toJSON(),i=c.currency,f=c.scale,l=t(a.map((function(r){return r.toJSON().amount})));return o.create({amount:l,currency:i,scale:f})}}(r);return function(){for(var r=arguments.length,n=new Array(r),u=0;u<r;u++)n[u]=arguments[u];var a=n[0],o=z(a);s(o,v);var c=t(a);return e(c)}},r.safeMinimum=function(r){var n=D(r),t=j(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=e[0],o=z(a);s(o,v);var c=n(a);return t(c)}},r.safeSubtract=function(r){var t=D(r),e=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var u=t[0],a=t[1],o=u.toJSON(),c=o.amount,i=o.currency,f=o.scale,l=a.toJSON().amount,v=r.subtract(c,l);return u.create({amount:v,currency:i,scale:f})}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.toDecimal=function(r){var n=x(r),t=h(r),e=y(r);return function(){for(var u=arguments.length,a=new Array(u),o=0;o<u;o++)a[o]=arguments[o];var c=a[0],i=a[1],f=c.toJSON(),l=f.currency,v=f.scale,y=t(l.base),d=r.zero(),p=new Array(10).fill(null).reduce(r.increment,d),h=S(l.base),A=e(r.modulo(y,p),d),g=!h&&A;s(g,m);var w=n(c),O=G(r,c.formatter),b=O(w,v);return i?i({value:b,currency:l}):b}},r.toSnapshot=function(r){return r.toJSON()},r.toUnits=x,r.transformScale=I,r.trimScale=function(r){var n=function(r){var n=y(r);return function(t,e){var u=r.zero();if(n(u,t))return r.zero();for(var a=u,o=t;n(r.modulo(o,e),u);)o=r.integerDivide(o,e),a=r.increment(a);return a}}(r),t=y(r),e=J(r),u=I(r),a=h(r);return function(){for(var o=arguments.length,c=new Array(o),i=0;i<o;i++)c[i]=arguments[i];var f=c[0],l=f.toJSON(),v=l.amount,m=l.currency,s=l.scale,y=a(m.base),d=n(v,y),p=r.subtract(s,d),S=e([p,m.exponent]);return t(S,s)?f:u(f,S)}},r.up=_,Object.defineProperty(r,"__esModule",{value:!0})})); | ||
/*! @dinero.js/core 2.0.0-alpha.13 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((r="undefined"!=typeof globalThis?globalThis:r||self)["@dinero.js/core"]={})}(this,(function(r){"use strict";function n(r,n){return u(r)||function(r,n){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null==t)return;var e,u,a=[],o=!0,c=!1;try{for(t=t.call(r);!(o=(e=t.next()).done)&&(a.push(e.value),!n||a.length!==n);o=!0);}catch(r){c=!0,u=r}finally{try{o||null==t.return||t.return()}finally{if(c)throw u}}return a}(r,n)||o(r,n)||i()}function t(r){return u(r)||a(r)||o(r)||i()}function e(r){return function(r){if(Array.isArray(r))return c(r)}(r)||a(r)||o(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(r){if(Array.isArray(r))return r}function a(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function o(r,n){if(r){if("string"==typeof r)return c(r,n);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?c(r,n):void 0}}function c(r,n){(null==n||n>r.length)&&(n=r.length);for(var t=0,e=new Array(n);t<n;t++)e[t]=r[t];return e}function i(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,l="Ratios are invalid.",v="Objects must have the same currency.",m="Currency is not decimal.";function s(r,n){if(!r)throw new Error("[Dinero.js] ".concat(n))}function y(n){return function(t,e){return n.compare(t,e)===r.ComparisonOperator.EQ}}function d(n){return function(t,e){return n.compare(t,e)===r.ComparisonOperator.LT}}function p(r){var n=y(r),t=d(r),e=r.zero();return function(u){if(n(u,e))return e;if(t(u,e)){var a=r.decrement(e);return r.multiply(a,u)}return u}}function S(r){return Array.isArray(r)}function h(r){return function(n){return S(n)?n.reduce((function(n,t){return r.multiply(n,t)})):n}}function A(n){return function(t,e){return n.compare(t,e)===r.ComparisonOperator.GT}}function g(r){return function(n,t){return A(r)(n,t)||y(r)(n,t)}}function w(r){return function(n,t){var e=y(r),u=A(r),a=d(r),o=g(r),c=r.zero(),i=r.increment(c),f=t.reduce((function(n,t){return r.add(n,t)}),c);if(e(f,c))return t;for(var l=n,v=t.map((function(t){var e=r.integerDivide(r.multiply(n,t),f)||c;return l=r.subtract(l,e),e})),m=o(n,c),s=m?u:a,p=m?i:r.decrement(c),S=0;s(l,c);)e(t[S],c)||(v[S]=r.add(v[S],p),l=r.subtract(l,p)),S++;return v}}function O(r,n){var t,e;return(null==(e=r)?void 0:e.hasOwnProperty("amount"))?{amount:r.amount,scale:null!==(t=null==r?void 0:r.scale)&&void 0!==t?t:n}:{amount:r,scale:n}}function b(r){var n=y(r),t=r.zero(),e=r.increment(r.increment(t));return function(u){return n(r.modulo(u,e),t)}}function N(r){var n=y(r),t=p(r);return function(e,u){var a=t(r.modulo(e,u)),o=r.subtract(u,a);return n(o,a)}}function J(r){var n=d(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}function E(r){var n=y(r),t=d(r),e=r.zero();return function(u){if(n(u,e))return e;var a=r.increment(e),o=r.decrement(e);return t(u,e)?o:a}}function z(r){var n=t(r),e=n[0],u=n.slice(1),a=h(e.calculator),o=e.toJSON().currency,c=y(e.calculator),i=a(o.base);return u.every((function(r){var n=r.toJSON().currency,t=a(n.base);return n.code===o.code&&c(t,i)&&c(n.exponent,o.exponent)}))}r.ComparisonOperator=void 0,(f=r.ComparisonOperator||(r.ComparisonOperator={}))[f.LT=-1]="LT",f[f.EQ=0]="EQ",f[f.GT=1]="GT";var C=function(r,n,t){var e=g(t)(r,t.zero()),u=t.integerDivide(r,n);return e?u:t.decrement(u)},T=function(r,n,t){var e=A(t),u=N(t),a=p(t),o=t.zero(),c=a(t.modulo(r,n)),i=e(t.subtract(n,c),c),f=e(r,t.increment(o));return u(r,n)||i&&!f||!i&&f?_(r,n,t):C(r,n,t)},_=function(r,n,t){var e=g(t)(r,t.zero()),u=t.integerDivide(r,n);return e?t.increment(u):u};function I(r){var t=A(r),e=h(r);return function(){for(var u=arguments.length,a=new Array(u),o=0;o<u;o++)a[o]=arguments[o];var c=a[0],i=a[1],f=a[2],l=void 0===f?C:f,v=c.toJSON(),m=v.amount,s=v.currency,y=v.scale,d=t(i,y),p=d?r.multiply:l,S=d?[i,y]:[y,i],h=n(S,2),A=h[0],g=h[1],w=e(s.base),O=r.power(w,r.subtract(A,g));return c.create({amount:p(m,O,r),currency:s,scale:i})}}function D(r){var n=J(r),t=I(r),e=y(r);return function(){for(var u=arguments.length,a=new Array(u),o=0;o<u;o++)a[o]=arguments[o];var c=a[0],i=c.reduce((function(r,t){var e=t.toJSON().scale;return n([r,e])}),r.zero());return c.map((function(r){var n=r.toJSON().scale;return e(n,i)?r:t(r,i)}))}}function L(r){var n=D(r),e=y(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=n(o),i=t(c),f=i[0],l=i.slice(1),v=f.toJSON(),m=v.amount;return l.every((function(r){var n=r.toJSON().amount;return e(n,m)}))}}function M(r){var t=function(r){return function(n,t){return d(r)(n,t)||y(r)(n,t)}}(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=e[0],o=e[1],c=[a,o],i=c.map((function(r){return r.toJSON().amount})),f=n(i,2),l=f[0],v=f[1];return t(l,v)}}function x(r){var t=function(r){var n=A(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=e[0],o=n(a,1),c=o[0],i=c.toJSON(),f=i.currency,l=i.scale,v=t(a.map((function(r){return r.toJSON().amount})));return c.create({amount:v,currency:f,scale:l})}}function G(r){var n=function(r){var n=r.multiply;return function(r){return r.reduce((function(t,u,a){var o=r.slice(a).reduce((function(r,t){return n(r,t)}));return[].concat(e(t),[o])}),[])}}(r);return function(){for(var t=arguments.length,u=new Array(t),a=0;a<t;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=o.toJSON(),f=i.amount,l=i.currency,v=i.scale,m=r.power,s=r.integerDivide,y=r.modulo,d=S(l.base)?l.base:[l.base],p=n(d.map((function(r){return m(r,v)}))),h=p.reduce((function(r,n,t){var u=r[t],a=s(u,n),o=y(u,n);return[].concat(e(r.filter((function(r,n){return n!==t}))),[a,o])}),[f]);return c?c({value:h,currency:l}):h}}function U(r,n){var t=p(r),e=y(r),u=d(r),a=r.zero();return function(r,o){var c=n.toString(r[0]),i=n.toString(t(r[1])),f=n.toNumber(o),l="".concat(c,".").concat(i.padStart(f,"0")),v=e(r[0],a),m=u(r[1],a);return v&&m?"-".concat(l):l}}r.INVALID_AMOUNT_MESSAGE="Amount is invalid.",r.INVALID_RATIOS_MESSAGE=l,r.INVALID_SCALE_MESSAGE="Scale is invalid.",r.NON_DECIMAL_CURRENCY_MESSAGE=m,r.UNEQUAL_CURRENCIES_MESSAGE=v,r.UNEQUAL_SCALES_MESSAGE="Objects must have the same scale.",r.assert=s,r.convert=function(r){var n=I(r),t=J(r),e=r.zero();return function(){for(var u=arguments.length,a=new Array(u),o=0;o<u;o++)a[o]=arguments[o];var c=a[0],i=a[1],f=a[2],l=f[i.code],v=c.toJSON(),m=v.amount,s=v.scale,y=O(l,e),d=y.amount,p=y.scale,S=r.add(s,p);return n(c.create({amount:r.multiply(m,d),currency:i,scale:S}),t([S,i.exponent]))}},r.createDinero=function(r){var n=r.calculator,t=r.onCreate,e=r.formatter,u=void 0===e?{toNumber:Number,toString:String}:e;return function r(e){var a=e.amount,o=e.currency,c=o.code,i=o.base,f=o.exponent,l=e.scale,v=void 0===l?f:l,m={code:c,base:i,exponent:f};return null==t||t({amount:a,currency:m,scale:v}),{calculator:n,formatter:u,create:r,toJSON:function(){return{amount:a,currency:m,scale:v}}}}},r.down=C,r.equal=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var u=t[0],a=t[1];return L(r)([u,a])&&z([u,a])}},r.halfAwayFromZero=function(r,n,t){var e=E(t),u=N(t),a=p(t);return u(r,n)?t.multiply(e(r),_(a(r),n,t)):T(r,n,t)},r.halfDown=function(r,n,t){return N(t)(r,n)?C(r,n,t):T(r,n,t)},r.halfEven=function(r,n,t){var e=b(t),u=N(t),a=T(r,n,t);return u(r,n)?e(a)?a:t.decrement(a):a},r.halfOdd=function(r,n,t){var e=b(t),u=N(t),a=T(r,n,t);return u(r,n)&&e(a)?t.decrement(a):a},r.halfTowardsZero=function(r,n,t){var e=E(t),u=N(t),a=p(t);return u(r,n)?t.multiply(e(r),C(a(r),n,t)):T(r,n,t)},r.halfUp=T,r.hasSubUnits=function(r){var n=y(r),t=h(r);return function(){for(var e=arguments.length,u=new Array(e),a=0;a<e;a++)u[a]=arguments[a];var o=u[0],c=o.toJSON(),i=c.amount,f=c.currency,l=c.scale,v=t(f.base);return!n(r.modulo(i,r.power(v,l)),r.zero())}},r.haveSameAmount=L,r.haveSameCurrency=z,r.isNegative=function(r){var n=d(r);return function(){for(var t=arguments.length,e=new Array(t),u=0;u<t;u++)e[u]=arguments[u];var a=e[0],o=a.toJSON(),c=o.amount;return n(c,r.zero())}},r.isPositive=function(r){var n=g(r);return function(){for(var t=arguments.length,e=new Array(t),u=0;u<t;u++)e[u]=arguments[u];var a=e[0],o=a.toJSON(),c=o.amount;return n(c,r.zero())}},r.isZero=function(r){var n=y(r);return function(){for(var t=arguments.length,e=new Array(t),u=0;u<t;u++)e[u]=arguments[u];var a=e[0],o=a.toJSON(),c=o.amount;return n(c,r.zero())}},r.multiply=function(r){var n=I(r),t=r.zero();return function(){for(var e=arguments.length,u=new Array(e),a=0;a<e;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=o.toJSON(),f=i.amount,l=i.currency,v=i.scale,m=O(c,t),s=m.amount,y=m.scale,d=r.add(v,y);return n(o.create({amount:r.multiply(f,s),currency:l,scale:d}),d)}},r.normalizeScale=D,r.safeAdd=function(r){var t=D(r),e=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var u=t[0],a=t[1],o=u.toJSON(),c=o.amount,i=o.currency,f=o.scale,l=a.toJSON().amount,v=r.add(c,l);return u.create({amount:v,currency:i,scale:f})}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeAllocate=function(r){var n=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var u=t[0],a=t[1],o=u.toJSON(),c=o.amount,i=o.currency,f=o.scale;return w(r)(c,a.map((function(r){return r.amount}))).map((function(r){return u.create({amount:r,currency:i,scale:f})}))}}(r),t=g(r),e=A(r),u=I(r),a=J(r),o=y(r),c=r.zero(),i=new Array(10).fill(null).reduce(r.increment,c);return function(){for(var f=arguments.length,v=new Array(f),m=0;m<f;m++)v[m]=arguments[m];var y=v[0],d=v[1],p=d.length>0,S=d.map((function(r){return O(r,c)})),h=p?a(S.map((function(r){return r.scale}))):c,A=S.map((function(n){var t=n.amount,e=n.scale,u=o(e,h)?c:r.subtract(h,e);return{amount:r.multiply(t,r.power(i,u)),scale:e}})),g=A.every((function(r){var n=r.amount;return t(n,c)})),w=A.some((function(r){var n=r.amount;return e(n,c)})),b=p&&g&&w;s(b,l);var N=y.toJSON(),J=N.scale,E=r.add(J,h);return n(u(y,E),A)}},r.safeCompare=function(r){var t=D(r),e=function(r){var t=function(r){return function(n,t){return r.compare(n,t)}}(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=n([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),o=a[0],c=a[1];return t(o,c)}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeGreaterThan=function(r){var t=D(r),e=function(r){var t=A(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=n([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),o=a[0],c=a[1];return t(o,c)}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeGreaterThanOrEqual=function(r){var t=D(r),e=function(r){var t=g(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=n([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),o=a[0],c=a[1];return t(o,c)}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeLessThan=function(r){var t=D(r),e=function(r){var t=d(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=n([e[0],e[1]].map((function(r){return r.toJSON().amount})),2),o=a[0],c=a[1];return t(o,c)}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeLessThanOrEqual=function(r){var t=D(r),e=M(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.safeMaximum=function(r){var t=D(r),e=function(r){var t=J(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=e[0],o=n(a,1)[0],c=o.toJSON(),i=c.currency,f=c.scale,l=t(a.map((function(r){return r.toJSON().amount})));return o.create({amount:l,currency:i,scale:f})}}(r);return function(){for(var r=arguments.length,n=new Array(r),u=0;u<r;u++)n[u]=arguments[u];var a=n[0],o=z(a);s(o,v);var c=t(a);return e(c)}},r.safeMinimum=function(r){var n=D(r),t=x(r);return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var a=e[0],o=z(a);s(o,v);var c=n(a);return t(c)}},r.safeSubtract=function(r){var t=D(r),e=function(r){return function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var u=t[0],a=t[1],o=u.toJSON(),c=o.amount,i=o.currency,f=o.scale,l=a.toJSON().amount,v=r.subtract(c,l);return u.create({amount:v,currency:i,scale:f})}}(r);return function(){for(var r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var o=u[0],c=u[1],i=z([o,c]);s(i,v);var f=t([o,c]),l=n(f,2),m=l[0],y=l[1];return e(m,y)}},r.toDecimal=function(r){var n=G(r),t=h(r),e=y(r);return function(){for(var u=arguments.length,a=new Array(u),o=0;o<u;o++)a[o]=arguments[o];var c=a[0],i=a[1],f=c.toJSON(),l=f.currency,v=f.scale,y=t(l.base),d=r.zero(),p=new Array(10).fill(null).reduce(r.increment,d),h=S(l.base),A=e(r.modulo(y,p),d),g=!h&&A;s(g,m);var w=n(c),O=U(r,c.formatter),b=O(w,v);return i?i({value:b,currency:l}):b}},r.toSnapshot=function(r){return r.toJSON()},r.toUnits=G,r.transformScale=I,r.trimScale=function(r){var n=function(r){var n=y(r);return function(t,e){var u=r.zero();if(n(u,t))return r.zero();for(var a=u,o=t;n(r.modulo(o,e),u);)o=r.integerDivide(o,e),a=r.increment(a);return a}}(r),t=y(r),e=J(r),u=I(r),a=h(r);return function(){for(var o=arguments.length,c=new Array(o),i=0;i<o;i++)c[i]=arguments[i];var f=c[0],l=f.toJSON(),v=l.amount,m=l.currency,s=l.scale,y=a(m.base),d=n(v,y),p=r.subtract(s,d),S=e([p,m.exponent]);return t(S,s)?f:u(f,S)}},r.up=_,Object.defineProperty(r,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@dinero.js/core", | ||
"version": "2.0.0-alpha.12", | ||
"version": "2.0.0-alpha.13", | ||
"description": "Common code between Dinero.js packages", | ||
@@ -45,4 +45,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@dinero.js/currencies": "2.0.0-alpha.12" | ||
"@dinero.js/currencies": "2.0.0-alpha.13" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
689245
4142
+ Added@dinero.js/currencies@2.0.0-alpha.13(transitive)
- Removed@dinero.js/currencies@2.0.0-alpha.12(transitive)