@dinero.js/core
Advanced tools
Comparing version 2.0.0-alpha.6 to 2.0.0-alpha.7
@@ -1,2 +0,2 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.6 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
/*! @dinero.js/core 2.0.0-alpha.7 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
'use strict'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,3 +0,3 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.6 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
/*! @dinero.js/core 2.0.0-alpha.7 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
"use strict";function r(r,n){return t(r)||function(r,n){var t=null==r?null:"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(n){var t=function(r){return function(n,t){return r.compare(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 g(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 N(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 b(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 J(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 M(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 E(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 T(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 C(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)||G,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 G(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 g({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=g,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.safeCompare=function(n){var t=n.calculator,a=A({calculator:t}),e=w({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.safeGreaterThan=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.safeGreaterThanOrEqual=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.safeLessThan=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.safeLessThanOrEqual=function(n){var t=n.calculator,a=A({calculator:t}),e=M({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=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.safeMinimum=function(r){var n=r.calculator,t=A({calculator:n}),a=T({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=C({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.unsafeCompare=w,exports.unsafeGreaterThan=N,exports.unsafeGreaterThanOrEqual=b,exports.unsafeLessThan=J,exports.unsafeLessThanOrEqual=M,exports.unsafeMaximum=E,exports.unsafeMinimum=T,exports.unsafeSubtract=C,exports.up=function(r){return Math.ceil(r)}; | ||
//# sourceMappingURL=index.production.js.map |
import type { Calculator } from '../types'; | ||
declare type ComparisonCalculator<TAmount> = Pick<Calculator<TAmount>, 'compare'>; | ||
declare type ComparisonCalculator<TAmount> = Calculator<TAmount>; | ||
/** | ||
@@ -4,0 +4,0 @@ * Returns a compare function. |
import type { Calculator } from '../types'; | ||
declare type CountTrailingZerosCalculator<TAmount> = Pick<Calculator<TAmount>, 'compare' | 'integerDivide' | 'increment' | 'zero' | 'modulo'>; | ||
declare type CountTrailingZerosCalculator<TAmount> = Calculator<TAmount>; | ||
export declare function countTrailingZeros<TAmount>(calculator: CountTrailingZerosCalculator<TAmount>): (input: TAmount, base: TAmount) => TAmount; | ||
export {}; |
import type { Calculator } from '../types'; | ||
declare type DistributeCalculator<TAmount> = Pick<Calculator<TAmount>, 'add' | 'compare' | 'integerDivide' | 'increment' | 'decrement' | 'multiply' | 'subtract' | 'zero' | 'modulo'>; | ||
declare type DistributeCalculator<TAmount> = Calculator<TAmount>; | ||
/** | ||
@@ -4,0 +4,0 @@ * Returns a distribute function. |
import type { Calculator } from '../types'; | ||
declare type EqualCalculator<TAmount> = Pick<Calculator<TAmount>, 'compare'>; | ||
declare type EqualCalculator<TAmount> = Calculator<TAmount>; | ||
/** | ||
@@ -4,0 +4,0 @@ * Returns an equal function. |
import type { Calculator } from '../types'; | ||
declare type GreaterThanCalculator<TAmount> = Pick<Calculator<TAmount>, 'compare'>; | ||
declare type GreaterThanCalculator<TAmount> = Calculator<TAmount>; | ||
/** | ||
@@ -4,0 +4,0 @@ * Returns a greaterThan function. |
import type { Calculator } from '../types'; | ||
declare type GreaterThanOrEqualCalculator<TAmount> = Pick<Calculator<TAmount>, 'compare'>; | ||
declare type GreaterThanOrEqualCalculator<TAmount> = Calculator<TAmount>; | ||
/** | ||
@@ -4,0 +4,0 @@ * Returns a greaterThanOrEqual function. |
import type { Calculator } from '../types'; | ||
declare type LessThanCalculator<TAmount> = Pick<Calculator<TAmount>, 'compare'>; | ||
declare type LessThanCalculator<TAmount> = Calculator<TAmount>; | ||
/** | ||
@@ -4,0 +4,0 @@ * Returns a lessThan function. |
import type { Calculator } from '../types'; | ||
declare type LessThanOrEqualCalculator<TAmount> = Pick<Calculator<TAmount>, 'compare'>; | ||
declare type LessThanOrEqualCalculator<TAmount> = Calculator<TAmount>; | ||
/** | ||
@@ -4,0 +4,0 @@ * Returns a lessThanOrEqual function. |
import type { Calculator } from '../types'; | ||
declare type MaximumCalculator<TAmount> = Pick<Calculator<TAmount>, 'compare'>; | ||
declare type MaximumCalculator<TAmount> = Calculator<TAmount>; | ||
/** | ||
@@ -4,0 +4,0 @@ * Returns a maximum function. |
import type { Calculator } from '../types'; | ||
declare type MinimumCalculator<TAmount> = Pick<Calculator<TAmount>, 'compare'>; | ||
declare type MinimumCalculator<TAmount> = Calculator<TAmount>; | ||
/** | ||
@@ -4,0 +4,0 @@ * Returns a minimum function. |
@@ -1,2 +0,2 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.6 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
/*! @dinero.js/core 2.0.0-alpha.7 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
(function (global, factory) { | ||
@@ -3,0 +3,0 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : |
@@ -1,3 +0,3 @@ | ||
/*! @dinero.js/core 2.0.0-alpha.6 | MIT License | © Sarah Dayan and contributors | https://v2.dinerojs.com */ | ||
/*! @dinero.js/core 2.0.0-alpha.7 | 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=null==r?null:"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 t=function(r){return function(n,t){return r.compare(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 J(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 M(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 E(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 T(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 C(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 G(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 _(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 x(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)||z,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 z(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 J({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=J,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.safeCompare=function(r){var t=r.calculator,a=w({calculator:t}),e=b({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.safeGreaterThan=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.safeGreaterThanOrEqual=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.safeLessThan=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.safeLessThanOrEqual=function(r){var t=r.calculator,a=w({calculator:t}),e=C({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=G({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=_({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=x({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=x,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.unsafeCompare=b,r.unsafeGreaterThan=M,r.unsafeGreaterThanOrEqual=E,r.unsafeLessThan=T,r.unsafeLessThanOrEqual=C,r.unsafeMaximum=L,r.unsafeMinimum=G,r.unsafeSubtract=_,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.6", | ||
"version": "2.0.0-alpha.7", | ||
"description": "Common code between Dinero.js packages", | ||
@@ -23,3 +23,3 @@ "keywords": [ | ||
"sideEffects": false, | ||
"main": "dist/cjs/index.production.js", | ||
"main": "dist/cjs/index.js", | ||
"umd:main": "dist/umd/index.production.js", | ||
@@ -45,4 +45,4 @@ "jsdelivr": "dist/umd/index.production.js", | ||
"dependencies": { | ||
"@dinero.js/currencies": "2.0.0-alpha.6" | ||
"@dinero.js/currencies": "2.0.0-alpha.7" | ||
} | ||
} |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
157
4380
477666
1
+ Added@dinero.js/currencies@2.0.0-alpha.7(transitive)
- Removed@dinero.js/currencies@2.0.0-alpha.6(transitive)