@dinero.js/core
Advanced tools
Comparing version 2.0.0-alpha.3 to 2.0.0-alpha.4
@@ -1,2 +0,2 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.3 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
/*! @dinero.js/core 2.0.0-alpha.4 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
'use strict'; | ||
@@ -359,2 +359,3 @@ | ||
var calculator = _ref.calculator; | ||
var greaterThanFn = greaterThan(calculator); | ||
return function transformScaleFn() { | ||
@@ -373,5 +374,8 @@ for (var _len = arguments.length, _ref2 = new Array(_len), _key = 0; _key < _len; _key++) { | ||
var factor = calculator.power(currency.base, calculator.subtract(scale, newScale)); | ||
var isNewScaleLarger = greaterThanFn(newScale, scale); | ||
var operation = isNewScaleLarger ? calculator.multiply : calculator.integerDivide; | ||
var terms = isNewScaleLarger ? [newScale, scale] : [scale, newScale]; | ||
var factor = calculator.power(currency.base, calculator.subtract.apply(calculator, terms)); | ||
return dineroObject.create({ | ||
amount: calculator.integerDivide(amount, factor), | ||
amount: operation(amount, factor), | ||
currency: currency, | ||
@@ -378,0 +382,0 @@ scale: newScale |
@@ -1,3 +0,3 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.3 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
"use strict";function r(r,n){return t(r)||function(r,n){var t=r&&("undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"]);if(null==t)return;var a,e,o=[],u=!0,c=!1;try{for(t=t.call(r);!(u=(a=t.next()).done)&&(o.push(a.value),!n||o.length!==n);u=!0);}catch(r){c=!0,e=r}finally{try{u||null==t.return||t.return()}finally{if(c)throw e}}return o}(r,n)||a(r,n)||o()}function n(r){return t(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||a(r)||o()}function t(r){if(Array.isArray(r))return r}function a(r,n){if(r){if("string"==typeof r)return e(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)?e(r,n):void 0}}function e(r,n){(null==n||n>r.length)&&(n=r.length);for(var t=0,a=new Array(n);t<n;t++)a[t]=r[t];return a}function o(){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 u,c="Objects must have the same currency.";function l(r,n){if(!r)throw new Error("[Dinero.js] ".concat(n))}function i(r){var t=n(r),a=t[0],e=t.slice(1),o=a.toJSON().currency;return e.every((function(r){return function(r,n){return r.code===n.code&&r.base===n.base&&r.exponent===n.exponent}(r.toJSON().currency,o)}))}function f(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.GT}}function v(r){return function(n,t){return s(r)(n,t)||f(r)(n,t)}}function m(r){return function(n,t){return r.compare(n,t)===exports.ComparisonOperator.LT}}function p(r){return function(n,t){var a=f(r),e=s(r),o=m(r),u=v(r),c=r.zero(),l=r.increment(c),i=t.reduce((function(n,t){return r.add(n,t)}),c);if(a(i,c))return t;for(var p=n,y=t.map((function(t){var a=r.integerDivide(r.multiply(n,t),i)||c;return p=r.subtract(p,a),a})),h=u(n,c),d=h?e:o,S=h?l:r.decrement(c),x=0;d(p,c);)a(t[x],c)||(y[x]=r.add(y[x],S),p=r.subtract(p,S)),x++;return y}}function y(r,n){var t,a;return(null==(a=r)?void 0:a.hasOwnProperty("amount"))?{amount:r.amount,scale:null!==(t=null==r?void 0:r.scale)&&void 0!==t?t:n}:{amount:r,scale:n}}function h(r){return r%2==0}function d(r){return Math.abs(r)%1==.5}function S(r){var n=m(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}function x(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1],u=e.toJSON(),c=u.amount,l=u.currency,i=u.scale,f=n.power(l.base,n.subtract(i,o));return e.create({amount:n.integerDivide(c,f),currency:l,scale:o})}}function A(r){var n=r.calculator,t=S(n),a=x({calculator:n}),e=f(n);return function(){for(var r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];var c=o[0],l=c.reduce((function(r,n){var a=n.toJSON().scale;return t([r,a])}),n.zero());return c.map((function(r){var n=r.toJSON().scale;return e(n,l)?r:a(r,l)}))}}function O(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1],u=e.toJSON(),c=u.amount,l=u.currency,i=u.scale,f=o.toJSON(),s=f.amount,v=n.add(c,s);return e.create({amount:v,currency:l,scale:i})}}function w(r){var t=r.calculator,a=A({calculator:t}),e=f(t);return function(){for(var r=arguments.length,t=new Array(r),o=0;o<r;o++)t[o]=arguments[o];var u=t[0],c=a(u),l=n(c),i=l[0],f=l.slice(1),s=i.toJSON(),v=s.amount;return f.every((function(r){var n=r.toJSON().amount;return e(n,v)}))}}function g(n){var t=s(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=[o,u],l=c.map((function(r){return r.toJSON().amount})),i=r(l,2),f=i[0],s=i[1];return t(f,s)}}function N(n){var t=v(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=[o,u],l=c.map((function(r){return r.toJSON().amount})),i=r(l,2),f=i[0],s=i[1];return t(f,s)}}function b(n){var t=m(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=[o,u],l=c.map((function(r){return r.toJSON().amount})),i=r(l,2),f=i[0],s=i[1];return t(f,s)}}function J(n){var t=function(r){return function(n,t){return m(r)(n,t)||f(r)(n,t)}}(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=[o,u],l=c.map((function(r){return r.toJSON().amount})),i=r(l,2),f=i[0],s=i[1];return t(f,s)}}function M(n){var t=S(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=r(o,1),c=u[0],l=c.toJSON(),i=l.currency,f=l.scale,s=t(o.map((function(r){return r.toJSON().amount})));return c.create({amount:s,currency:i,scale:f})}}function E(n){var t=function(r){var n=s(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=r(o,1),c=u[0],l=c.toJSON(),i=l.currency,f=l.scale,s=t(o.map((function(r){return r.toJSON().amount})));return c.create({amount:s,currency:i,scale:f})}}function T(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1],u=e.toJSON(),c=u.amount,l=u.currency,i=u.scale,f=o.toJSON(),s=f.amount,v=n.subtract(c,s);return e.create({amount:v,currency:l,scale:i})}}function L(r){var n=r.calculator;return function(){for(var r,t=arguments.length,a=new Array(t),e=0;e<t;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=(null==u?void 0:u.round)||C,l=o.toJSON(),i=l.amount,f=l.currency,s=l.scale,v=n.power,m=n.toNumber,p=m(v(f.base,s)),y=m(v(f.base,null!==(r=null==u?void 0:u.digits)&&void 0!==r?r:s));return c(m(i)/p*y)/y}}function C(r){return r}exports.ComparisonOperator=void 0,(u=exports.ComparisonOperator||(exports.ComparisonOperator={}))[u.LT=-1]="LT",u[u.EQ=0]="EQ",u[u.GT=1]="GT";exports.INVALID_AMOUNT_MESSAGE="Amount is invalid.",exports.INVALID_RATIOS_MESSAGE="Ratios are invalid.",exports.INVALID_SCALE_MESSAGE="Scale is invalid.",exports.UNEQUAL_CURRENCIES_MESSAGE=c,exports.UNEQUAL_SCALES_MESSAGE="Objects must have the same scale.",exports.assert=l,exports.convert=function(r){var n=r.calculator,t=x({calculator:n}),a=S(n),e=n.zero();return function(){for(var r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];var c=o[0],l=o[1],i=o[2],f=i[l.code],s=c.toJSON(),v=s.amount,m=s.scale,p=y(f,e),h=p.amount,d=p.scale,S=n.add(m,d);return t(c.create({amount:n.multiply(v,h),currency:l,scale:S}),a([S,l.exponent]))}},exports.createDinero=function(r){var n=r.calculator,t=r.onCreate;return function r(a){var e=a.amount,o=a.currency,u=a.scale,c=void 0===u?o.exponent:u;return null==t||t({amount:e,currency:o,scale:c}),{calculator:n,create:r,toJSON:function(){return{amount:e,currency:o,scale:c}}}}},exports.down=function(r){return Math.floor(r)},exports.equal=function(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1];return w({calculator:n})([e,o])&&i([e,o])}},exports.halfAwayFromZero=function(r){return d(r)?Math.sign(r)*Math.ceil(Math.abs(r)):Math.round(r)},exports.halfDown=function(r){return d(r)?Math.floor(r):Math.round(r)},exports.halfEven=function(r){var n=Math.round(r);return d(r)?h(n)?n:n-1:n},exports.halfOdd=function(r){var n=Math.round(r);return d(r)&&h(n)?n-1:n},exports.halfTowardsZero=function(r){return d(r)?Math.sign(r)*Math.floor(Math.abs(r)):Math.round(r)},exports.halfUp=function(r){return Math.round(r)},exports.hasSubUnits=function(r){var n=r.calculator,t=f(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var o=a[0],u=o.toJSON(),c=u.amount,l=u.currency,i=u.scale;return!t(n.modulo(c,n.power(l.base,i)),n.zero())}},exports.haveSameAmount=w,exports.haveSameCurrency=i,exports.isNegative=function(r){var n=r.calculator,t=m(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var o=a[0],u=o.toJSON(),c=u.amount;return t(c,n.zero())}},exports.isPositive=function(r){var n=r.calculator,t=v(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var o=a[0],u=o.toJSON(),c=u.amount;return t(c,n.zero())}},exports.isZero=function(r){var n=r.calculator,t=f(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var o=a[0],u=o.toJSON(),c=u.amount;return t(c,n.zero())}},exports.multiply=function(r){var n=r.calculator,t=x({calculator:n}),a=n.zero();return function(){for(var r=arguments.length,e=new Array(r),o=0;o<r;o++)e[o]=arguments[o];var u=e[0],c=e[1],l=u.toJSON(),i=l.amount,f=l.currency,s=l.scale,v=y(c,a),m=v.amount,p=v.scale,h=n.add(s,p);return t(u.create({amount:n.multiply(i,m),currency:f,scale:h}),h)}},exports.normalizeScale=A,exports.safeAdd=function(n){var t=n.calculator,a=A({calculator:t}),e=O({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.safeAllocate=function(r){var n=r.calculator,t=function(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1],u=e.toJSON(),c=u.amount,l=u.currency,i=u.scale;return p(n)(c,o.map((function(r){return r.amount}))).map((function(r){return e.create({amount:r,currency:l,scale:i})}))}}({calculator:n}),a=v(n),e=s(n),o=x({calculator:n}),u=S(n),c=f(n),i=n.zero(),m=new Array(10).fill(null).reduce(n.increment,i);return function(){for(var r=arguments.length,f=new Array(r),s=0;s<r;s++)f[s]=arguments[s];var v=f[0],p=f[1],h=p.length>0,d=p.map((function(r){return y(r,i)})),S=h?u(d.map((function(r){return r.scale}))):i,x=d.map((function(r){var t=r.amount,a=r.scale,e=c(a,S)?i:n.subtract(S,a);return{amount:n.multiply(t,n.power(m,e)),scale:a}})),A=x.every((function(r){var n=r.amount;return a(n,i)})),O=x.some((function(r){var n=r.amount;return e(n,i)})),w=h&&A&&O;l(w,"Ratios are invalid.");var g=v.toJSON(),N=g.scale,b=n.add(N,S);return t(o(v,b),x)}},exports.safeGreaterThan=function(n){var t=n.calculator,a=A({calculator:t}),e=g({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.safeGreaterThanOrEqual=function(n){var t=n.calculator,a=A({calculator:t}),e=N({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.safeLessThan=function(n){var t=n.calculator,a=A({calculator:t}),e=b({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.safeLessThanOrEqual=function(n){var t=n.calculator,a=A({calculator:t}),e=J({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.safeMaximum=function(r){var n=r.calculator,t=A({calculator:n}),a=M({calculator:n});return function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];var o=n[0],u=i(o);l(u,c);var f=t(o);return a(f)}},exports.safeMinimum=function(r){var n=r.calculator,t=A({calculator:n}),a=E({calculator:n});return function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];var o=n[0],u=i(o);l(u,c);var f=t(o);return a(f)}},exports.safeSubtract=function(n){var t=n.calculator,a=A({calculator:t}),e=T({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.toFormat=function(r){var n=L({calculator:r.calculator});return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1],u=e.toJSON(),c=u.currency,l=u.scale,i=n(e,{digits:l});return o({amount:i,currency:c,dineroObject:e})}},exports.toSnapshot=function(r){return r.toJSON()},exports.toUnit=L,exports.transformScale=x,exports.trimScale=function(r){var n=r.calculator,t=function(r){var n=f(r);return function(t,a){for(var e=r.zero(),o=e,u=t;n(r.modulo(u,a),e);)u=r.integerDivide(u,a),o=r.increment(o);return o}}(n),a=f(n),e=S(n),o=x({calculator:n});return function(){for(var r=arguments.length,u=new Array(r),c=0;c<r;c++)u[c]=arguments[c];var l=u[0],i=l.toJSON(),f=i.amount,s=i.currency,v=i.scale,m=s.base,p=s.exponent,y=t(f,m),h=n.subtract(v,y),d=e([h,p]);return a(d,v)?l:o(l,d)}},exports.unsafeAdd=O,exports.unsafeGreaterThan=g,exports.unsafeGreaterThanOrEqual=N,exports.unsafeLessThan=b,exports.unsafeLessThanOrEqual=J,exports.unsafeMaximum=M,exports.unsafeMinimum=E,exports.unsafeSubtract=T,exports.up=function(r){return Math.ceil(r)}; | ||
/*! @dinero.js/core 2.0.0-alpha.4 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
"use strict";function r(r,n){return t(r)||function(r,n){var t=r&&("undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"]);if(null==t)return;var a,e,o=[],u=!0,c=!1;try{for(t=t.call(r);!(u=(a=t.next()).done)&&(o.push(a.value),!n||o.length!==n);u=!0);}catch(r){c=!0,e=r}finally{try{u||null==t.return||t.return()}finally{if(c)throw e}}return o}(r,n)||a(r,n)||o()}function n(r){return t(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||a(r)||o()}function t(r){if(Array.isArray(r))return r}function a(r,n){if(r){if("string"==typeof r)return e(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)?e(r,n):void 0}}function e(r,n){(null==n||n>r.length)&&(n=r.length);for(var t=0,a=new Array(n);t<n;t++)a[t]=r[t];return a}function o(){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 u,c="Objects must have the same currency.";function l(r,n){if(!r)throw new Error("[Dinero.js] ".concat(n))}function i(r){var t=n(r),a=t[0],e=t.slice(1),o=a.toJSON().currency;return e.every((function(r){return function(r,n){return r.code===n.code&&r.base===n.base&&r.exponent===n.exponent}(r.toJSON().currency,o)}))}function f(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.GT}}function v(r){return function(n,t){return s(r)(n,t)||f(r)(n,t)}}function m(r){return function(n,t){return r.compare(n,t)===exports.ComparisonOperator.LT}}function p(r){return function(n,t){var a=f(r),e=s(r),o=m(r),u=v(r),c=r.zero(),l=r.increment(c),i=t.reduce((function(n,t){return r.add(n,t)}),c);if(a(i,c))return t;for(var p=n,y=t.map((function(t){var a=r.integerDivide(r.multiply(n,t),i)||c;return p=r.subtract(p,a),a})),h=u(n,c),d=h?e:o,S=h?l:r.decrement(c),x=0;d(p,c);)a(t[x],c)||(y[x]=r.add(y[x],S),p=r.subtract(p,S)),x++;return y}}function y(r,n){var t,a;return(null==(a=r)?void 0:a.hasOwnProperty("amount"))?{amount:r.amount,scale:null!==(t=null==r?void 0:r.scale)&&void 0!==t?t:n}:{amount:r,scale:n}}function h(r){return r%2==0}function d(r){return Math.abs(r)%1==.5}function S(r){var n=m(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}function x(r){var n=r.calculator,t=s(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=o.toJSON(),l=c.amount,i=c.currency,f=c.scale,s=t(u,f),v=s?n.multiply:n.integerDivide,m=s?[u,f]:[f,u],p=n.power(i.base,n.subtract.apply(n,m));return o.create({amount:v(l,p),currency:i,scale:u})}}function A(r){var n=r.calculator,t=S(n),a=x({calculator:n}),e=f(n);return function(){for(var r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];var c=o[0],l=c.reduce((function(r,n){var a=n.toJSON().scale;return t([r,a])}),n.zero());return c.map((function(r){var n=r.toJSON().scale;return e(n,l)?r:a(r,l)}))}}function O(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1],u=e.toJSON(),c=u.amount,l=u.currency,i=u.scale,f=o.toJSON(),s=f.amount,v=n.add(c,s);return e.create({amount:v,currency:l,scale:i})}}function w(r){var t=r.calculator,a=A({calculator:t}),e=f(t);return function(){for(var r=arguments.length,t=new Array(r),o=0;o<r;o++)t[o]=arguments[o];var u=t[0],c=a(u),l=n(c),i=l[0],f=l.slice(1),s=i.toJSON(),v=s.amount;return f.every((function(r){var n=r.toJSON().amount;return e(n,v)}))}}function g(n){var t=s(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=[o,u],l=c.map((function(r){return r.toJSON().amount})),i=r(l,2),f=i[0],s=i[1];return t(f,s)}}function N(n){var t=v(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=[o,u],l=c.map((function(r){return r.toJSON().amount})),i=r(l,2),f=i[0],s=i[1];return t(f,s)}}function b(n){var t=m(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=[o,u],l=c.map((function(r){return r.toJSON().amount})),i=r(l,2),f=i[0],s=i[1];return t(f,s)}}function J(n){var t=function(r){return function(n,t){return m(r)(n,t)||f(r)(n,t)}}(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=[o,u],l=c.map((function(r){return r.toJSON().amount})),i=r(l,2),f=i[0],s=i[1];return t(f,s)}}function M(n){var t=S(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=r(o,1),c=u[0],l=c.toJSON(),i=l.currency,f=l.scale,s=t(o.map((function(r){return r.toJSON().amount})));return c.create({amount:s,currency:i,scale:f})}}function E(n){var t=function(r){var n=s(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}(n.calculator);return function(){for(var n=arguments.length,a=new Array(n),e=0;e<n;e++)a[e]=arguments[e];var o=a[0],u=r(o,1),c=u[0],l=c.toJSON(),i=l.currency,f=l.scale,s=t(o.map((function(r){return r.toJSON().amount})));return c.create({amount:s,currency:i,scale:f})}}function T(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1],u=e.toJSON(),c=u.amount,l=u.currency,i=u.scale,f=o.toJSON(),s=f.amount,v=n.subtract(c,s);return e.create({amount:v,currency:l,scale:i})}}function L(r){var n=r.calculator;return function(){for(var r,t=arguments.length,a=new Array(t),e=0;e<t;e++)a[e]=arguments[e];var o=a[0],u=a[1],c=(null==u?void 0:u.round)||C,l=o.toJSON(),i=l.amount,f=l.currency,s=l.scale,v=n.power,m=n.toNumber,p=m(v(f.base,s)),y=m(v(f.base,null!==(r=null==u?void 0:u.digits)&&void 0!==r?r:s));return c(m(i)/p*y)/y}}function C(r){return r}exports.ComparisonOperator=void 0,(u=exports.ComparisonOperator||(exports.ComparisonOperator={}))[u.LT=-1]="LT",u[u.EQ=0]="EQ",u[u.GT=1]="GT";exports.INVALID_AMOUNT_MESSAGE="Amount is invalid.",exports.INVALID_RATIOS_MESSAGE="Ratios are invalid.",exports.INVALID_SCALE_MESSAGE="Scale is invalid.",exports.UNEQUAL_CURRENCIES_MESSAGE=c,exports.UNEQUAL_SCALES_MESSAGE="Objects must have the same scale.",exports.assert=l,exports.convert=function(r){var n=r.calculator,t=x({calculator:n}),a=S(n),e=n.zero();return function(){for(var r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];var c=o[0],l=o[1],i=o[2],f=i[l.code],s=c.toJSON(),v=s.amount,m=s.scale,p=y(f,e),h=p.amount,d=p.scale,S=n.add(m,d);return t(c.create({amount:n.multiply(v,h),currency:l,scale:S}),a([S,l.exponent]))}},exports.createDinero=function(r){var n=r.calculator,t=r.onCreate;return function r(a){var e=a.amount,o=a.currency,u=a.scale,c=void 0===u?o.exponent:u;return null==t||t({amount:e,currency:o,scale:c}),{calculator:n,create:r,toJSON:function(){return{amount:e,currency:o,scale:c}}}}},exports.down=function(r){return Math.floor(r)},exports.equal=function(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1];return w({calculator:n})([e,o])&&i([e,o])}},exports.halfAwayFromZero=function(r){return d(r)?Math.sign(r)*Math.ceil(Math.abs(r)):Math.round(r)},exports.halfDown=function(r){return d(r)?Math.floor(r):Math.round(r)},exports.halfEven=function(r){var n=Math.round(r);return d(r)?h(n)?n:n-1:n},exports.halfOdd=function(r){var n=Math.round(r);return d(r)&&h(n)?n-1:n},exports.halfTowardsZero=function(r){return d(r)?Math.sign(r)*Math.floor(Math.abs(r)):Math.round(r)},exports.halfUp=function(r){return Math.round(r)},exports.hasSubUnits=function(r){var n=r.calculator,t=f(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var o=a[0],u=o.toJSON(),c=u.amount,l=u.currency,i=u.scale;return!t(n.modulo(c,n.power(l.base,i)),n.zero())}},exports.haveSameAmount=w,exports.haveSameCurrency=i,exports.isNegative=function(r){var n=r.calculator,t=m(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var o=a[0],u=o.toJSON(),c=u.amount;return t(c,n.zero())}},exports.isPositive=function(r){var n=r.calculator,t=v(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var o=a[0],u=o.toJSON(),c=u.amount;return t(c,n.zero())}},exports.isZero=function(r){var n=r.calculator,t=f(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var o=a[0],u=o.toJSON(),c=u.amount;return t(c,n.zero())}},exports.multiply=function(r){var n=r.calculator,t=x({calculator:n}),a=n.zero();return function(){for(var r=arguments.length,e=new Array(r),o=0;o<r;o++)e[o]=arguments[o];var u=e[0],c=e[1],l=u.toJSON(),i=l.amount,f=l.currency,s=l.scale,v=y(c,a),m=v.amount,p=v.scale,h=n.add(s,p);return t(u.create({amount:n.multiply(i,m),currency:f,scale:h}),h)}},exports.normalizeScale=A,exports.safeAdd=function(n){var t=n.calculator,a=A({calculator:t}),e=O({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.safeAllocate=function(r){var n=r.calculator,t=function(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1],u=e.toJSON(),c=u.amount,l=u.currency,i=u.scale;return p(n)(c,o.map((function(r){return r.amount}))).map((function(r){return e.create({amount:r,currency:l,scale:i})}))}}({calculator:n}),a=v(n),e=s(n),o=x({calculator:n}),u=S(n),c=f(n),i=n.zero(),m=new Array(10).fill(null).reduce(n.increment,i);return function(){for(var r=arguments.length,f=new Array(r),s=0;s<r;s++)f[s]=arguments[s];var v=f[0],p=f[1],h=p.length>0,d=p.map((function(r){return y(r,i)})),S=h?u(d.map((function(r){return r.scale}))):i,x=d.map((function(r){var t=r.amount,a=r.scale,e=c(a,S)?i:n.subtract(S,a);return{amount:n.multiply(t,n.power(m,e)),scale:a}})),A=x.every((function(r){var n=r.amount;return a(n,i)})),O=x.some((function(r){var n=r.amount;return e(n,i)})),w=h&&A&&O;l(w,"Ratios are invalid.");var g=v.toJSON(),N=g.scale,b=n.add(N,S);return t(o(v,b),x)}},exports.safeGreaterThan=function(n){var t=n.calculator,a=A({calculator:t}),e=g({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.safeGreaterThanOrEqual=function(n){var t=n.calculator,a=A({calculator:t}),e=N({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.safeLessThan=function(n){var t=n.calculator,a=A({calculator:t}),e=b({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.safeLessThanOrEqual=function(n){var t=n.calculator,a=A({calculator:t}),e=J({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.safeMaximum=function(r){var n=r.calculator,t=A({calculator:n}),a=M({calculator:n});return function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];var o=n[0],u=i(o);l(u,c);var f=t(o);return a(f)}},exports.safeMinimum=function(r){var n=r.calculator,t=A({calculator:n}),a=E({calculator:n});return function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];var o=n[0],u=i(o);l(u,c);var f=t(o);return a(f)}},exports.safeSubtract=function(n){var t=n.calculator,a=A({calculator:t}),e=T({calculator:t});return function(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];var u=t[0],f=t[1],s=i([u,f]);l(s,c);var v=a([u,f]),m=r(v,2),p=m[0],y=m[1];return e(p,y)}},exports.toFormat=function(r){var n=L({calculator:r.calculator});return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],o=t[1],u=e.toJSON(),c=u.currency,l=u.scale,i=n(e,{digits:l});return o({amount:i,currency:c,dineroObject:e})}},exports.toSnapshot=function(r){return r.toJSON()},exports.toUnit=L,exports.transformScale=x,exports.trimScale=function(r){var n=r.calculator,t=function(r){var n=f(r);return function(t,a){for(var e=r.zero(),o=e,u=t;n(r.modulo(u,a),e);)u=r.integerDivide(u,a),o=r.increment(o);return o}}(n),a=f(n),e=S(n),o=x({calculator:n});return function(){for(var r=arguments.length,u=new Array(r),c=0;c<r;c++)u[c]=arguments[c];var l=u[0],i=l.toJSON(),f=i.amount,s=i.currency,v=i.scale,m=s.base,p=s.exponent,y=t(f,m),h=n.subtract(v,y),d=e([h,p]);return a(d,v)?l:o(l,d)}},exports.unsafeAdd=O,exports.unsafeGreaterThan=g,exports.unsafeGreaterThanOrEqual=N,exports.unsafeLessThan=b,exports.unsafeLessThanOrEqual=J,exports.unsafeMaximum=M,exports.unsafeMinimum=E,exports.unsafeSubtract=T,exports.up=function(r){return Math.ceil(r)}; | ||
//# sourceMappingURL=index.production.js.map |
@@ -7,5 +7,5 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type UnsafeAddDependencies<TAmount> = Dependencies<TAmount, 'add'>; | ||
export declare type UnsafeAddDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function unsafeAdd<TAmount>({ calculator, }: UnsafeAddDependencies<TAmount>): (augend: Dinero<TAmount>, addend: Dinero<TAmount>) => Dinero<TAmount>; | ||
export declare type SafeAddDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type SafeAddDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function safeAdd<TAmount>({ calculator }: SafeAddDependencies<TAmount>): (augend: Dinero<TAmount>, addend: Dinero<TAmount>) => Dinero<TAmount>; |
@@ -7,4 +7,4 @@ import type { Dinero, ScaledAmount } from '../types'; | ||
]; | ||
export declare type UnsafeAllocateDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'integerDivide' | 'increment' | 'decrement' | 'multiply' | 'subtract' | 'zero' | 'modulo'>; | ||
export declare type SafeAllocateDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'integerDivide' | 'increment' | 'decrement' | 'multiply' | 'subtract' | 'zero' | 'modulo' | 'power'>; | ||
export declare type UnsafeAllocateDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare type SafeAllocateDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function safeAllocate<TAmount>({ calculator, }: SafeAllocateDependencies<TAmount>): (dineroObject: Dinero<TAmount>, ratios: readonly (TAmount | ScaledAmount<TAmount>)[]) => Dinero<TAmount>[]; |
@@ -9,3 +9,3 @@ import type { Dinero, Rates } from '../types'; | ||
]; | ||
export declare type ConvertDependencies<TAmount> = Dependencies<TAmount, 'add' | 'multiply' | 'zero' | 'power' | 'subtract' | 'integerDivide' | 'compare'>; | ||
export declare type ConvertDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function convert<TAmount>({ calculator }: ConvertDependencies<TAmount>): (dineroObject: Dinero<TAmount>, newCurrency: Currency<TAmount>, rates: Rates<TAmount>) => Dinero<TAmount>; |
@@ -7,3 +7,3 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type EqualDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type EqualDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function equal<TAmount>({ calculator }: EqualDependencies<TAmount>): (dineroObject: Dinero<TAmount>, comparator: Dinero<TAmount>) => boolean; |
@@ -7,5 +7,5 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type UnsafeGreaterThanDependencies<TAmount> = Dependencies<TAmount, 'compare'>; | ||
export declare type UnsafeGreaterThanDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function unsafeGreaterThan<TAmount>({ calculator, }: UnsafeGreaterThanDependencies<TAmount>): (dineroObject: Dinero<TAmount>, comparator: Dinero<TAmount>) => boolean; | ||
export declare type SafeGreaterThanDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type SafeGreaterThanDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function safeGreaterThan<TAmount>({ calculator, }: SafeGreaterThanDependencies<TAmount>): (dineroObject: Dinero<TAmount>, comparator: Dinero<TAmount>) => boolean; |
@@ -7,5 +7,5 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type UnsafeGreaterThanOrEqualDependencies<TAmount> = Dependencies<TAmount, 'compare'>; | ||
export declare type UnsafeGreaterThanOrEqualDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function unsafeGreaterThanOrEqual<TAmount>({ calculator, }: UnsafeGreaterThanOrEqualDependencies<TAmount>): (dineroObject: Dinero<TAmount>, comparator: Dinero<TAmount>) => boolean; | ||
export declare type SafeGreaterThanOrEqualDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type SafeGreaterThanOrEqualDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function safeGreaterThanOrEqual<TAmount>({ calculator, }: SafeGreaterThanOrEqualDependencies<TAmount>): (dineroObject: Dinero<TAmount>, comparator: Dinero<TAmount>) => boolean; |
@@ -6,3 +6,3 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type HasSubUnitsDependencies<TAmount> = Dependencies<TAmount, 'compare' | 'modulo' | 'power' | 'zero'>; | ||
export declare type HasSubUnitsDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function hasSubUnits<TAmount>({ calculator, }: HasSubUnitsDependencies<TAmount>): (dineroObject: Dinero<TAmount>) => boolean; |
@@ -6,3 +6,3 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type HaveSameAmountDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type HaveSameAmountDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function haveSameAmount<TAmount>({ calculator, }: HaveSameAmountDependencies<TAmount>): (dineroObjects: readonly Dinero<TAmount>[]) => boolean; |
@@ -6,3 +6,3 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type IsNegativeDependencies<TAmount> = Dependencies<TAmount, 'compare' | 'zero'>; | ||
export declare type IsNegativeDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function isNegative<TAmount>({ calculator, }: IsNegativeDependencies<TAmount>): (dineroObject: Dinero<TAmount>) => boolean; |
@@ -6,3 +6,3 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type IsPositiveDependencies<TAmount> = Dependencies<TAmount, 'compare' | 'zero'>; | ||
export declare type IsPositiveDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function isPositive<TAmount>({ calculator, }: IsPositiveDependencies<TAmount>): (dineroObject: Dinero<TAmount>) => boolean; |
import type { Dinero } from '../types'; | ||
import type { Dependencies } from './types'; | ||
export declare type IsZeroParams<TAmount> = readonly [dineroObject: Dinero<TAmount>]; | ||
export declare type IsZeroDependencies<TAmount> = Dependencies<TAmount, 'compare' | 'zero'>; | ||
export declare type IsZeroDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function isZero<TAmount>({ calculator }: IsZeroDependencies<TAmount>): (dineroObject: Dinero<TAmount>) => boolean; |
@@ -7,5 +7,5 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type UnsafeLessThanDependencies<TAmount> = Dependencies<TAmount, 'compare'>; | ||
export declare type UnsafeLessThanDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function unsafeLessThan<TAmount>({ calculator, }: UnsafeLessThanDependencies<TAmount>): (dineroObject: Dinero<TAmount>, comparator: Dinero<TAmount>) => boolean; | ||
export declare type SafeLessThanDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type SafeLessThanDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function safeLessThan<TAmount>({ calculator, }: SafeLessThanDependencies<TAmount>): (dineroObject: Dinero<TAmount>, comparator: Dinero<TAmount>) => boolean; |
@@ -7,5 +7,5 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type UnsafeLessThanOrEqualDependencies<TAmount> = Dependencies<TAmount, 'compare'>; | ||
export declare type UnsafeLessThanOrEqualDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function unsafeLessThanOrEqual<TAmount>({ calculator, }: UnsafeLessThanOrEqualDependencies<TAmount>): (dineroObject: Dinero<TAmount>, comparator: Dinero<TAmount>) => boolean; | ||
export declare type SafeLessThanOrEqualDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type SafeLessThanOrEqualDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function safeLessThanOrEqual<TAmount>({ calculator, }: SafeLessThanOrEqualDependencies<TAmount>): (dineroObject: Dinero<TAmount>, comparator: Dinero<TAmount>) => boolean; |
@@ -6,5 +6,5 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type UnsafeMaximumDependencies<TAmount> = Dependencies<TAmount, 'compare'>; | ||
export declare type UnsafeMaximumDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function unsafeMaximum<TAmount>({ calculator, }: UnsafeMaximumDependencies<TAmount>): (dineroObjects: readonly Dinero<TAmount>[]) => Dinero<TAmount>; | ||
export declare type SafeMaximumDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type SafeMaximumDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function safeMaximum<TAmount>({ calculator, }: SafeMaximumDependencies<TAmount>): (dineroObjects: readonly Dinero<TAmount>[]) => Dinero<TAmount>; |
@@ -6,5 +6,5 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type UnsafeMinimumDependencies<TAmount> = Dependencies<TAmount, 'compare'>; | ||
export declare type UnsafeMinimumDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function unsafeMinimum<TAmount>({ calculator, }: UnsafeMinimumDependencies<TAmount>): (dineroObjects: readonly Dinero<TAmount>[]) => Dinero<TAmount>; | ||
export declare type SafeMinimumDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type SafeMinimumDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function safeMinimum<TAmount>({ calculator, }: SafeMinimumDependencies<TAmount>): (dineroObjects: readonly Dinero<TAmount>[]) => Dinero<TAmount>; |
@@ -7,3 +7,3 @@ import type { Dinero, ScaledAmount } from '../types'; | ||
]; | ||
export declare type MultiplyDependencies<TAmount> = Dependencies<TAmount, 'add' | 'multiply' | 'zero' | 'power' | 'subtract' | 'integerDivide'>; | ||
export declare type MultiplyDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function multiply<TAmount>({ calculator, }: MultiplyDependencies<TAmount>): (multiplicand: Dinero<TAmount>, multiplier: TAmount | ScaledAmount<TAmount>) => Dinero<TAmount>; |
@@ -6,3 +6,3 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type NormalizeScaleDependencies<TAmount> = Dependencies<TAmount, 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type NormalizeScaleDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function normalizeScale<TAmount>({ calculator, }: NormalizeScaleDependencies<TAmount>): (dineroObjects: readonly Dinero<TAmount>[]) => Dinero<TAmount>[]; |
@@ -7,5 +7,5 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type UnsafeSubtractDependencies<TAmount> = Dependencies<TAmount, 'subtract'>; | ||
export declare type UnsafeSubtractDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function unsafeSubtract<TAmount>({ calculator, }: UnsafeSubtractDependencies<TAmount>): (minuend: Dinero<TAmount>, subtrahend: Dinero<TAmount>) => Dinero<TAmount>; | ||
export declare type SafeSubtractDependencies<TAmount> = Dependencies<TAmount, 'subtract' | 'add' | 'compare' | 'multiply' | 'power' | 'subtract' | 'zero' | 'integerDivide'>; | ||
export declare type SafeSubtractDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function safeSubtract<TAmount>({ calculator, }: SafeSubtractDependencies<TAmount>): (minuend: Dinero<TAmount>, subtrahend: Dinero<TAmount>) => Dinero<TAmount>; |
@@ -7,3 +7,3 @@ import type { Dinero, Transformer } from '../types'; | ||
]; | ||
export declare type ToFormatDependencies<TAmount> = Dependencies<TAmount, 'multiply' | 'power' | 'toNumber'>; | ||
export declare type ToFormatDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function toFormat<TAmount>({ calculator, }: ToFormatDependencies<TAmount>): (dineroObject: Dinero<TAmount>, transformer: Transformer<TAmount>) => string; |
@@ -7,3 +7,3 @@ import type { Dinero, RoundingOptions } from '../types'; | ||
]; | ||
export declare type ToUnitDependencies<TAmount> = Dependencies<TAmount, 'multiply' | 'power' | 'toNumber'>; | ||
export declare type ToUnitDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function toUnit<TAmount>({ calculator }: ToUnitDependencies<TAmount>): (dineroObject: Dinero<TAmount>, options?: RoundingOptions<TAmount> | undefined) => number; |
@@ -7,3 +7,3 @@ import type { Dinero } from '../types'; | ||
]; | ||
export declare type TransformScaleDependencies<TAmount> = Dependencies<TAmount, 'subtract' | 'integerDivide' | 'power'>; | ||
export declare type TransformScaleDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function transformScale<TAmount>({ calculator, }: TransformScaleDependencies<TAmount>): (dineroObject: Dinero<TAmount>, newScale: TAmount) => Dinero<TAmount>; |
@@ -0,3 +1,5 @@ | ||
import { greaterThan } from '../utils'; | ||
export function transformScale(_ref) { | ||
var calculator = _ref.calculator; | ||
var greaterThanFn = greaterThan(calculator); | ||
return function transformScaleFn() { | ||
@@ -16,5 +18,8 @@ for (var _len = arguments.length, _ref2 = new Array(_len), _key = 0; _key < _len; _key++) { | ||
var factor = calculator.power(currency.base, calculator.subtract(scale, newScale)); | ||
var isNewScaleLarger = greaterThanFn(newScale, scale); | ||
var operation = isNewScaleLarger ? calculator.multiply : calculator.integerDivide; | ||
var terms = isNewScaleLarger ? [newScale, scale] : [scale, newScale]; | ||
var factor = calculator.power(currency.base, calculator.subtract.apply(calculator, terms)); | ||
return dineroObject.create({ | ||
amount: calculator.integerDivide(amount, factor), | ||
amount: operation(amount, factor), | ||
currency: currency, | ||
@@ -21,0 +26,0 @@ scale: newScale |
import type { Dinero } from '../types'; | ||
import type { Dependencies } from './types'; | ||
export declare type TrimScaleParams<TAmount> = readonly [dineroObject: Dinero<TAmount>]; | ||
export declare type TrimScaleDependencies<TAmount> = Dependencies<TAmount, 'compare' | 'increment' | 'integerDivide' | 'modulo' | 'power' | 'subtract' | 'zero'>; | ||
export declare type TrimScaleDependencies<TAmount> = Dependencies<TAmount>; | ||
export declare function trimScale<TAmount>({ calculator, }: TrimScaleDependencies<TAmount>): (dineroObject: Dinero<TAmount>) => Dinero<TAmount>; |
import type { Calculator } from '../../types'; | ||
export declare type CalculatorDependency<TAmount, TCalculatorMethods extends keyof Calculator<TAmount>> = Pick<Calculator<TAmount>, TCalculatorMethods>; | ||
export declare type Dependencies<TAmount, TCalculatorMethods extends keyof Calculator<TAmount>> = { | ||
readonly calculator: CalculatorDependency<TAmount, TCalculatorMethods>; | ||
export declare type Dependencies<TAmount> = { | ||
readonly calculator: Calculator<TAmount>; | ||
}; |
@@ -1,2 +0,2 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.3 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
/*! @dinero.js/core 2.0.0-alpha.4 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
(function (global, factory) { | ||
@@ -361,2 +361,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
var calculator = _ref.calculator; | ||
var greaterThanFn = greaterThan(calculator); | ||
return function transformScaleFn() { | ||
@@ -375,5 +376,8 @@ for (var _len = arguments.length, _ref2 = new Array(_len), _key = 0; _key < _len; _key++) { | ||
var factor = calculator.power(currency.base, calculator.subtract(scale, newScale)); | ||
var isNewScaleLarger = greaterThanFn(newScale, scale); | ||
var operation = isNewScaleLarger ? calculator.multiply : calculator.integerDivide; | ||
var terms = isNewScaleLarger ? [newScale, scale] : [scale, newScale]; | ||
var factor = calculator.power(currency.base, calculator.subtract.apply(calculator, terms)); | ||
return dineroObject.create({ | ||
amount: calculator.integerDivide(amount, factor), | ||
amount: operation(amount, factor), | ||
currency: currency, | ||
@@ -380,0 +384,0 @@ scale: newScale |
@@ -1,3 +0,3 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.3 | 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 a(r)||function(r,n){var t=r&&("undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"]);if(null==t)return;var a,e,u=[],o=!0,c=!1;try{for(t=t.call(r);!(o=(a=t.next()).done)&&(u.push(a.value),!n||u.length!==n);o=!0);}catch(r){c=!0,e=r}finally{try{o||null==t.return||t.return()}finally{if(c)throw e}}return u}(r,n)||e(r,n)||o()}function t(r){return a(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||e(r)||o()}function a(r){if(Array.isArray(r))return r}function e(r,n){if(r){if("string"==typeof r)return u(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)?u(r,n):void 0}}function u(r,n){(null==n||n>r.length)&&(n=r.length);for(var t=0,a=new Array(n);t<n;t++)a[t]=r[t];return a}function o(){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 c,l="Ratios are invalid.",i="Objects must have the same currency.";function f(r,n){if(!r)throw new Error("[Dinero.js] ".concat(n))}function v(r){var n=t(r),a=n[0],e=n.slice(1),u=a.toJSON().currency;return e.every((function(r){return function(r,n){return r.code===n.code&&r.base===n.base&&r.exponent===n.exponent}(r.toJSON().currency,u)}))}function s(n){return function(t,a){return n.compare(t,a)===r.ComparisonOperator.EQ}}function m(n){return function(t,a){return n.compare(t,a)===r.ComparisonOperator.GT}}function y(r){return function(n,t){return m(r)(n,t)||s(r)(n,t)}}function h(n){return function(t,a){return n.compare(t,a)===r.ComparisonOperator.LT}}function d(r){return function(n,t){var a=s(r),e=m(r),u=h(r),o=y(r),c=r.zero(),l=r.increment(c),i=t.reduce((function(n,t){return r.add(n,t)}),c);if(a(i,c))return t;for(var f=n,v=t.map((function(t){var a=r.integerDivide(r.multiply(n,t),i)||c;return f=r.subtract(f,a),a})),d=o(n,c),p=d?e:u,S=d?l:r.decrement(c),A=0;p(f,c);)a(t[A],c)||(v[A]=r.add(v[A],S),f=r.subtract(f,S)),A++;return v}}function p(r,n){var t,a;return(null==(a=r)?void 0:a.hasOwnProperty("amount"))?{amount:r.amount,scale:null!==(t=null==r?void 0:r.scale)&&void 0!==t?t:n}:{amount:r,scale:n}}function S(r){return r%2==0}function A(r){return Math.abs(r)%1==.5}function O(r){var n=h(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}function g(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1],o=e.toJSON(),c=o.amount,l=o.currency,i=o.scale,f=n.power(l.base,n.subtract(i,u));return e.create({amount:n.integerDivide(c,f),currency:l,scale:u})}}function w(r){var n=r.calculator,t=O(n),a=g({calculator:n}),e=s(n);return function(){for(var r=arguments.length,u=new Array(r),o=0;o<r;o++)u[o]=arguments[o];var c=u[0],l=c.reduce((function(r,n){var a=n.toJSON().scale;return t([r,a])}),n.zero());return c.map((function(r){var n=r.toJSON().scale;return e(n,l)?r:a(r,l)}))}}function N(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1],o=e.toJSON(),c=o.amount,l=o.currency,i=o.scale,f=u.toJSON(),v=f.amount,s=n.add(c,v);return e.create({amount:s,currency:l,scale:i})}}function b(r){var n=r.calculator,a=w({calculator:n}),e=s(n);return function(){for(var r=arguments.length,n=new Array(r),u=0;u<r;u++)n[u]=arguments[u];var o=n[0],c=a(o),l=t(c),i=l[0],f=l.slice(1),v=i.toJSON(),s=v.amount;return f.every((function(r){var n=r.toJSON().amount;return e(n,s)}))}}function J(r){var t=m(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=[u,o],l=c.map((function(r){return r.toJSON().amount})),i=n(l,2),f=i[0],v=i[1];return t(f,v)}}function M(r){var t=y(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=[u,o],l=c.map((function(r){return r.toJSON().amount})),i=n(l,2),f=i[0],v=i[1];return t(f,v)}}function E(r){var t=h(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=[u,o],l=c.map((function(r){return r.toJSON().amount})),i=n(l,2),f=i[0],v=i[1];return t(f,v)}}function T(r){var t=function(r){return function(n,t){return h(r)(n,t)||s(r)(n,t)}}(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=[u,o],l=c.map((function(r){return r.toJSON().amount})),i=n(l,2),f=i[0],v=i[1];return t(f,v)}}function L(r){var t=O(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=n(u,1),c=o[0],l=c.toJSON(),i=l.currency,f=l.scale,v=t(u.map((function(r){return r.toJSON().amount})));return c.create({amount:v,currency:i,scale:f})}}function C(r){var t=function(r){var n=m(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=n(u,1),c=o[0],l=c.toJSON(),i=l.currency,f=l.scale,v=t(u.map((function(r){return r.toJSON().amount})));return c.create({amount:v,currency:i,scale:f})}}function G(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1],o=e.toJSON(),c=o.amount,l=o.currency,i=o.scale,f=u.toJSON(),v=f.amount,s=n.subtract(c,v);return e.create({amount:s,currency:l,scale:i})}}function _(r){var n=r.calculator;return function(){for(var r,t=arguments.length,a=new Array(t),e=0;e<t;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=(null==o?void 0:o.round)||x,l=u.toJSON(),i=l.amount,f=l.currency,v=l.scale,s=n.power,m=n.toNumber,y=m(s(f.base,v)),h=m(s(f.base,null!==(r=null==o?void 0:o.digits)&&void 0!==r?r:v));return c(m(i)/y*h)/h}}function x(r){return r}r.ComparisonOperator=void 0,(c=r.ComparisonOperator||(r.ComparisonOperator={}))[c.LT=-1]="LT",c[c.EQ=0]="EQ",c[c.GT=1]="GT";r.INVALID_AMOUNT_MESSAGE="Amount is invalid.",r.INVALID_RATIOS_MESSAGE=l,r.INVALID_SCALE_MESSAGE="Scale is invalid.",r.UNEQUAL_CURRENCIES_MESSAGE=i,r.UNEQUAL_SCALES_MESSAGE="Objects must have the same scale.",r.assert=f,r.convert=function(r){var n=r.calculator,t=g({calculator:n}),a=O(n),e=n.zero();return function(){for(var r=arguments.length,u=new Array(r),o=0;o<r;o++)u[o]=arguments[o];var c=u[0],l=u[1],i=u[2],f=i[l.code],v=c.toJSON(),s=v.amount,m=v.scale,y=p(f,e),h=y.amount,d=y.scale,S=n.add(m,d);return t(c.create({amount:n.multiply(s,h),currency:l,scale:S}),a([S,l.exponent]))}},r.createDinero=function(r){var n=r.calculator,t=r.onCreate;return function r(a){var e=a.amount,u=a.currency,o=a.scale,c=void 0===o?u.exponent:o;return null==t||t({amount:e,currency:u,scale:c}),{calculator:n,create:r,toJSON:function(){return{amount:e,currency:u,scale:c}}}}},r.down=function(r){return Math.floor(r)},r.equal=function(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1];return b({calculator:n})([e,u])&&v([e,u])}},r.halfAwayFromZero=function(r){return A(r)?Math.sign(r)*Math.ceil(Math.abs(r)):Math.round(r)},r.halfDown=function(r){return A(r)?Math.floor(r):Math.round(r)},r.halfEven=function(r){var n=Math.round(r);return A(r)?S(n)?n:n-1:n},r.halfOdd=function(r){var n=Math.round(r);return A(r)&&S(n)?n-1:n},r.halfTowardsZero=function(r){return A(r)?Math.sign(r)*Math.floor(Math.abs(r)):Math.round(r)},r.halfUp=function(r){return Math.round(r)},r.hasSubUnits=function(r){var n=r.calculator,t=s(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=u.toJSON(),c=o.amount,l=o.currency,i=o.scale;return!t(n.modulo(c,n.power(l.base,i)),n.zero())}},r.haveSameAmount=b,r.haveSameCurrency=v,r.isNegative=function(r){var n=r.calculator,t=h(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=u.toJSON(),c=o.amount;return t(c,n.zero())}},r.isPositive=function(r){var n=r.calculator,t=y(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=u.toJSON(),c=o.amount;return t(c,n.zero())}},r.isZero=function(r){var n=r.calculator,t=s(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=u.toJSON(),c=o.amount;return t(c,n.zero())}},r.multiply=function(r){var n=r.calculator,t=g({calculator:n}),a=n.zero();return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var o=e[0],c=e[1],l=o.toJSON(),i=l.amount,f=l.currency,v=l.scale,s=p(c,a),m=s.amount,y=s.scale,h=n.add(v,y);return t(o.create({amount:n.multiply(i,m),currency:f,scale:h}),h)}},r.normalizeScale=w,r.safeAdd=function(r){var t=r.calculator,a=w({calculator:t}),e=N({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.safeAllocate=function(r){var n=r.calculator,t=function(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1],o=e.toJSON(),c=o.amount,l=o.currency,i=o.scale;return d(n)(c,u.map((function(r){return r.amount}))).map((function(r){return e.create({amount:r,currency:l,scale:i})}))}}({calculator:n}),a=y(n),e=m(n),u=g({calculator:n}),o=O(n),c=s(n),i=n.zero(),v=new Array(10).fill(null).reduce(n.increment,i);return function(){for(var r=arguments.length,s=new Array(r),m=0;m<r;m++)s[m]=arguments[m];var y=s[0],h=s[1],d=h.length>0,S=h.map((function(r){return p(r,i)})),A=d?o(S.map((function(r){return r.scale}))):i,O=S.map((function(r){var t=r.amount,a=r.scale,e=c(a,A)?i:n.subtract(A,a);return{amount:n.multiply(t,n.power(v,e)),scale:a}})),g=O.every((function(r){var n=r.amount;return a(n,i)})),w=O.some((function(r){var n=r.amount;return e(n,i)})),N=d&&g&&w;f(N,l);var b=y.toJSON(),J=b.scale,M=n.add(J,A);return t(u(y,M),O)}},r.safeGreaterThan=function(r){var t=r.calculator,a=w({calculator:t}),e=J({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.safeGreaterThanOrEqual=function(r){var t=r.calculator,a=w({calculator:t}),e=M({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.safeLessThan=function(r){var t=r.calculator,a=w({calculator:t}),e=E({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.safeLessThanOrEqual=function(r){var t=r.calculator,a=w({calculator:t}),e=T({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.safeMaximum=function(r){var n=r.calculator,t=w({calculator:n}),a=L({calculator:n});return function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];var u=n[0],o=v(u);f(o,i);var c=t(u);return a(c)}},r.safeMinimum=function(r){var n=r.calculator,t=w({calculator:n}),a=C({calculator:n});return function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];var u=n[0],o=v(u);f(o,i);var c=t(u);return a(c)}},r.safeSubtract=function(r){var t=r.calculator,a=w({calculator:t}),e=G({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.toFormat=function(r){var n=_({calculator:r.calculator});return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1],o=e.toJSON(),c=o.currency,l=o.scale,i=n(e,{digits:l});return u({amount:i,currency:c,dineroObject:e})}},r.toSnapshot=function(r){return r.toJSON()},r.toUnit=_,r.transformScale=g,r.trimScale=function(r){var n=r.calculator,t=function(r){var n=s(r);return function(t,a){for(var e=r.zero(),u=e,o=t;n(r.modulo(o,a),e);)o=r.integerDivide(o,a),u=r.increment(u);return u}}(n),a=s(n),e=O(n),u=g({calculator:n});return function(){for(var r=arguments.length,o=new Array(r),c=0;c<r;c++)o[c]=arguments[c];var l=o[0],i=l.toJSON(),f=i.amount,v=i.currency,s=i.scale,m=v.base,y=v.exponent,h=t(f,m),d=n.subtract(s,h),p=e([d,y]);return a(p,s)?l:u(l,p)}},r.unsafeAdd=N,r.unsafeGreaterThan=J,r.unsafeGreaterThanOrEqual=M,r.unsafeLessThan=E,r.unsafeLessThanOrEqual=T,r.unsafeMaximum=L,r.unsafeMinimum=C,r.unsafeSubtract=G,r.up=function(r){return Math.ceil(r)},Object.defineProperty(r,"__esModule",{value:!0})})); | ||
/*! @dinero.js/core 2.0.0-alpha.4 | 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 a(r)||function(r,n){var t=r&&("undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"]);if(null==t)return;var a,e,u=[],o=!0,c=!1;try{for(t=t.call(r);!(o=(a=t.next()).done)&&(u.push(a.value),!n||u.length!==n);o=!0);}catch(r){c=!0,e=r}finally{try{o||null==t.return||t.return()}finally{if(c)throw e}}return u}(r,n)||e(r,n)||o()}function t(r){return a(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||e(r)||o()}function a(r){if(Array.isArray(r))return r}function e(r,n){if(r){if("string"==typeof r)return u(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)?u(r,n):void 0}}function u(r,n){(null==n||n>r.length)&&(n=r.length);for(var t=0,a=new Array(n);t<n;t++)a[t]=r[t];return a}function o(){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 c,l="Ratios are invalid.",i="Objects must have the same currency.";function f(r,n){if(!r)throw new Error("[Dinero.js] ".concat(n))}function v(r){var n=t(r),a=n[0],e=n.slice(1),u=a.toJSON().currency;return e.every((function(r){return function(r,n){return r.code===n.code&&r.base===n.base&&r.exponent===n.exponent}(r.toJSON().currency,u)}))}function s(n){return function(t,a){return n.compare(t,a)===r.ComparisonOperator.EQ}}function m(n){return function(t,a){return n.compare(t,a)===r.ComparisonOperator.GT}}function y(r){return function(n,t){return m(r)(n,t)||s(r)(n,t)}}function h(n){return function(t,a){return n.compare(t,a)===r.ComparisonOperator.LT}}function d(r){return function(n,t){var a=s(r),e=m(r),u=h(r),o=y(r),c=r.zero(),l=r.increment(c),i=t.reduce((function(n,t){return r.add(n,t)}),c);if(a(i,c))return t;for(var f=n,v=t.map((function(t){var a=r.integerDivide(r.multiply(n,t),i)||c;return f=r.subtract(f,a),a})),d=o(n,c),p=d?e:u,S=d?l:r.decrement(c),A=0;p(f,c);)a(t[A],c)||(v[A]=r.add(v[A],S),f=r.subtract(f,S)),A++;return v}}function p(r,n){var t,a;return(null==(a=r)?void 0:a.hasOwnProperty("amount"))?{amount:r.amount,scale:null!==(t=null==r?void 0:r.scale)&&void 0!==t?t:n}:{amount:r,scale:n}}function S(r){return r%2==0}function A(r){return Math.abs(r)%1==.5}function O(r){var n=h(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}function g(r){var n=r.calculator,t=m(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=u.toJSON(),l=c.amount,i=c.currency,f=c.scale,v=t(o,f),s=v?n.multiply:n.integerDivide,m=v?[o,f]:[f,o],y=n.power(i.base,n.subtract.apply(n,m));return u.create({amount:s(l,y),currency:i,scale:o})}}function w(r){var n=r.calculator,t=O(n),a=g({calculator:n}),e=s(n);return function(){for(var r=arguments.length,u=new Array(r),o=0;o<r;o++)u[o]=arguments[o];var c=u[0],l=c.reduce((function(r,n){var a=n.toJSON().scale;return t([r,a])}),n.zero());return c.map((function(r){var n=r.toJSON().scale;return e(n,l)?r:a(r,l)}))}}function N(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1],o=e.toJSON(),c=o.amount,l=o.currency,i=o.scale,f=u.toJSON(),v=f.amount,s=n.add(c,v);return e.create({amount:s,currency:l,scale:i})}}function b(r){var n=r.calculator,a=w({calculator:n}),e=s(n);return function(){for(var r=arguments.length,n=new Array(r),u=0;u<r;u++)n[u]=arguments[u];var o=n[0],c=a(o),l=t(c),i=l[0],f=l.slice(1),v=i.toJSON(),s=v.amount;return f.every((function(r){var n=r.toJSON().amount;return e(n,s)}))}}function J(r){var t=m(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=[u,o],l=c.map((function(r){return r.toJSON().amount})),i=n(l,2),f=i[0],v=i[1];return t(f,v)}}function M(r){var t=y(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=[u,o],l=c.map((function(r){return r.toJSON().amount})),i=n(l,2),f=i[0],v=i[1];return t(f,v)}}function E(r){var t=h(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=[u,o],l=c.map((function(r){return r.toJSON().amount})),i=n(l,2),f=i[0],v=i[1];return t(f,v)}}function T(r){var t=function(r){return function(n,t){return h(r)(n,t)||s(r)(n,t)}}(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=[u,o],l=c.map((function(r){return r.toJSON().amount})),i=n(l,2),f=i[0],v=i[1];return t(f,v)}}function L(r){var t=O(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=n(u,1),c=o[0],l=c.toJSON(),i=l.currency,f=l.scale,v=t(u.map((function(r){return r.toJSON().amount})));return c.create({amount:v,currency:i,scale:f})}}function C(r){var t=function(r){var n=m(r);return function(r){return r.reduce((function(r,t){return n(r,t)?t:r}))}}(r.calculator);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=n(u,1),c=o[0],l=c.toJSON(),i=l.currency,f=l.scale,v=t(u.map((function(r){return r.toJSON().amount})));return c.create({amount:v,currency:i,scale:f})}}function G(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1],o=e.toJSON(),c=o.amount,l=o.currency,i=o.scale,f=u.toJSON(),v=f.amount,s=n.subtract(c,v);return e.create({amount:s,currency:l,scale:i})}}function _(r){var n=r.calculator;return function(){for(var r,t=arguments.length,a=new Array(t),e=0;e<t;e++)a[e]=arguments[e];var u=a[0],o=a[1],c=(null==o?void 0:o.round)||x,l=u.toJSON(),i=l.amount,f=l.currency,v=l.scale,s=n.power,m=n.toNumber,y=m(s(f.base,v)),h=m(s(f.base,null!==(r=null==o?void 0:o.digits)&&void 0!==r?r:v));return c(m(i)/y*h)/h}}function x(r){return r}r.ComparisonOperator=void 0,(c=r.ComparisonOperator||(r.ComparisonOperator={}))[c.LT=-1]="LT",c[c.EQ=0]="EQ",c[c.GT=1]="GT";r.INVALID_AMOUNT_MESSAGE="Amount is invalid.",r.INVALID_RATIOS_MESSAGE=l,r.INVALID_SCALE_MESSAGE="Scale is invalid.",r.UNEQUAL_CURRENCIES_MESSAGE=i,r.UNEQUAL_SCALES_MESSAGE="Objects must have the same scale.",r.assert=f,r.convert=function(r){var n=r.calculator,t=g({calculator:n}),a=O(n),e=n.zero();return function(){for(var r=arguments.length,u=new Array(r),o=0;o<r;o++)u[o]=arguments[o];var c=u[0],l=u[1],i=u[2],f=i[l.code],v=c.toJSON(),s=v.amount,m=v.scale,y=p(f,e),h=y.amount,d=y.scale,S=n.add(m,d);return t(c.create({amount:n.multiply(s,h),currency:l,scale:S}),a([S,l.exponent]))}},r.createDinero=function(r){var n=r.calculator,t=r.onCreate;return function r(a){var e=a.amount,u=a.currency,o=a.scale,c=void 0===o?u.exponent:o;return null==t||t({amount:e,currency:u,scale:c}),{calculator:n,create:r,toJSON:function(){return{amount:e,currency:u,scale:c}}}}},r.down=function(r){return Math.floor(r)},r.equal=function(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1];return b({calculator:n})([e,u])&&v([e,u])}},r.halfAwayFromZero=function(r){return A(r)?Math.sign(r)*Math.ceil(Math.abs(r)):Math.round(r)},r.halfDown=function(r){return A(r)?Math.floor(r):Math.round(r)},r.halfEven=function(r){var n=Math.round(r);return A(r)?S(n)?n:n-1:n},r.halfOdd=function(r){var n=Math.round(r);return A(r)&&S(n)?n-1:n},r.halfTowardsZero=function(r){return A(r)?Math.sign(r)*Math.floor(Math.abs(r)):Math.round(r)},r.halfUp=function(r){return Math.round(r)},r.hasSubUnits=function(r){var n=r.calculator,t=s(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=u.toJSON(),c=o.amount,l=o.currency,i=o.scale;return!t(n.modulo(c,n.power(l.base,i)),n.zero())}},r.haveSameAmount=b,r.haveSameCurrency=v,r.isNegative=function(r){var n=r.calculator,t=h(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=u.toJSON(),c=o.amount;return t(c,n.zero())}},r.isPositive=function(r){var n=r.calculator,t=y(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=u.toJSON(),c=o.amount;return t(c,n.zero())}},r.isZero=function(r){var n=r.calculator,t=s(n);return function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];var u=a[0],o=u.toJSON(),c=o.amount;return t(c,n.zero())}},r.multiply=function(r){var n=r.calculator,t=g({calculator:n}),a=n.zero();return function(){for(var r=arguments.length,e=new Array(r),u=0;u<r;u++)e[u]=arguments[u];var o=e[0],c=e[1],l=o.toJSON(),i=l.amount,f=l.currency,v=l.scale,s=p(c,a),m=s.amount,y=s.scale,h=n.add(v,y);return t(o.create({amount:n.multiply(i,m),currency:f,scale:h}),h)}},r.normalizeScale=w,r.safeAdd=function(r){var t=r.calculator,a=w({calculator:t}),e=N({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.safeAllocate=function(r){var n=r.calculator,t=function(r){var n=r.calculator;return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1],o=e.toJSON(),c=o.amount,l=o.currency,i=o.scale;return d(n)(c,u.map((function(r){return r.amount}))).map((function(r){return e.create({amount:r,currency:l,scale:i})}))}}({calculator:n}),a=y(n),e=m(n),u=g({calculator:n}),o=O(n),c=s(n),i=n.zero(),v=new Array(10).fill(null).reduce(n.increment,i);return function(){for(var r=arguments.length,s=new Array(r),m=0;m<r;m++)s[m]=arguments[m];var y=s[0],h=s[1],d=h.length>0,S=h.map((function(r){return p(r,i)})),A=d?o(S.map((function(r){return r.scale}))):i,O=S.map((function(r){var t=r.amount,a=r.scale,e=c(a,A)?i:n.subtract(A,a);return{amount:n.multiply(t,n.power(v,e)),scale:a}})),g=O.every((function(r){var n=r.amount;return a(n,i)})),w=O.some((function(r){var n=r.amount;return e(n,i)})),N=d&&g&&w;f(N,l);var b=y.toJSON(),J=b.scale,M=n.add(J,A);return t(u(y,M),O)}},r.safeGreaterThan=function(r){var t=r.calculator,a=w({calculator:t}),e=J({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.safeGreaterThanOrEqual=function(r){var t=r.calculator,a=w({calculator:t}),e=M({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.safeLessThan=function(r){var t=r.calculator,a=w({calculator:t}),e=E({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.safeLessThanOrEqual=function(r){var t=r.calculator,a=w({calculator:t}),e=T({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.safeMaximum=function(r){var n=r.calculator,t=w({calculator:n}),a=L({calculator:n});return function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];var u=n[0],o=v(u);f(o,i);var c=t(u);return a(c)}},r.safeMinimum=function(r){var n=r.calculator,t=w({calculator:n}),a=C({calculator:n});return function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];var u=n[0],o=v(u);f(o,i);var c=t(u);return a(c)}},r.safeSubtract=function(r){var t=r.calculator,a=w({calculator:t}),e=G({calculator:t});return function(){for(var r=arguments.length,t=new Array(r),u=0;u<r;u++)t[u]=arguments[u];var o=t[0],c=t[1],l=v([o,c]);f(l,i);var s=a([o,c]),m=n(s,2),y=m[0],h=m[1];return e(y,h)}},r.toFormat=function(r){var n=_({calculator:r.calculator});return function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];var e=t[0],u=t[1],o=e.toJSON(),c=o.currency,l=o.scale,i=n(e,{digits:l});return u({amount:i,currency:c,dineroObject:e})}},r.toSnapshot=function(r){return r.toJSON()},r.toUnit=_,r.transformScale=g,r.trimScale=function(r){var n=r.calculator,t=function(r){var n=s(r);return function(t,a){for(var e=r.zero(),u=e,o=t;n(r.modulo(o,a),e);)o=r.integerDivide(o,a),u=r.increment(u);return u}}(n),a=s(n),e=O(n),u=g({calculator:n});return function(){for(var r=arguments.length,o=new Array(r),c=0;c<r;c++)o[c]=arguments[c];var l=o[0],i=l.toJSON(),f=i.amount,v=i.currency,s=i.scale,m=v.base,y=v.exponent,h=t(f,m),d=n.subtract(s,h),p=e([d,y]);return a(p,s)?l:u(l,p)}},r.unsafeAdd=N,r.unsafeGreaterThan=J,r.unsafeGreaterThanOrEqual=M,r.unsafeLessThan=E,r.unsafeLessThanOrEqual=T,r.unsafeMaximum=L,r.unsafeMinimum=C,r.unsafeSubtract=G,r.up=function(r){return Math.ceil(r)},Object.defineProperty(r,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@dinero.js/core", | ||
"version": "2.0.0-alpha.3", | ||
"version": "2.0.0-alpha.4", | ||
"description": "Common code between Dinero.js packages", | ||
@@ -34,3 +34,3 @@ "keywords": [ | ||
"scripts": { | ||
"build:clean": "rm -rf ./dist", | ||
"build:clean": "rimraf ./dist", | ||
"build:esm": "babel src --root-mode upward --extensions '.ts' --out-dir dist/esm --ignore '**/*/__tests__/'", | ||
@@ -45,4 +45,4 @@ "build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm", | ||
"dependencies": { | ||
"@dinero.js/currencies": "2.0.0-alpha.3" | ||
"@dinero.js/currencies": "2.0.0-alpha.4" | ||
} | ||
} |
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
4159
456003
+ Added@dinero.js/currencies@2.0.0-alpha.4(transitive)
- Removed@dinero.js/currencies@2.0.0-alpha.3(transitive)