UNPKG

@cowrie/cowrie

Version:

Cowrie is a JavaScript utility that allows you to add, subtract, multiply, divide, sort & partition monetary values

2 lines 10.7 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Cowrie=t():e.Cowrie=t()}(this,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="dist/",r(r.s=1)}([function(e,t,r){var n;!function(i){"use strict";var o,s="[big.js] ",u=s+"Invalid ",f=u+"decimal places",c={},a=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function l(e,t,r,n){var i=e.c,o=e.e+t+1;if(o<i.length){if(1===r)n=i[o]>=5;else if(2===r)n=i[o]>5||5==i[o]&&(n||o<0||void 0!==i[o+1]||1&i[o-1]);else if(3===r)n=n||!!i[0];else if(n=!1,0!==r)throw Error("[big.js] Invalid rounding mode");if(o<1)i.length=1,n?(e.e=-t,i[0]=1):i[0]=e.e=0;else{if(i.length=o--,n)for(;++i[o]>9;)i[o]=0,o--||(++e.e,i.unshift(1));for(o=i.length;!i[--o];)i.pop()}}else if(r<0||r>3||r!==~~r)throw Error("[big.js] Invalid rounding mode");return e}function h(e,t,r,n){var i,o,s=e.constructor,c=!e.c[0];if(void 0!==r){if(r!==~~r||r<(3==t)||r>1e6)throw Error(3==t?u+"precision":f);for(r=n-(e=new s(e)).e,e.c.length>++n&&l(e,r,s.RM),2==t&&(n=e.e+r+1);e.c.length<n;)e.c.push(0)}if(i=e.e,r=(o=e.c.join("")).length,2!=t&&(1==t||3==t&&n<=i||i<=s.NE||i>=s.PE))o=o.charAt(0)+(r>1?"."+o.slice(1):"")+(i<0?"e":"e+")+i;else if(i<0){for(;++i;)o="0"+o;o="0."+o}else if(i>0)if(++i>r)for(i-=r;i--;)o+="0";else i<r&&(o=o.slice(0,i)+"."+o.slice(i));else r>1&&(o=o.charAt(0)+"."+o.slice(1));return e.s<0&&(!c||4==t)?"-"+o:o}c.abs=function(){var e=new this.constructor(this);return e.s=1,e},c.cmp=function(e){var t,r=this,n=r.c,i=(e=new r.constructor(e)).c,o=r.s,s=e.s,u=r.e,f=e.e;if(!n[0]||!i[0])return n[0]?o:i[0]?-s:0;if(o!=s)return o;if(t=o<0,u!=f)return u>f^t?1:-1;for(s=(u=n.length)<(f=i.length)?u:f,o=-1;++o<s;)if(n[o]!=i[o])return n[o]>i[o]^t?1:-1;return u==f?0:u>f^t?1:-1},c.div=function(e){var t=this,r=t.constructor,n=t.c,i=(e=new r(e)).c,o=t.s==e.s?1:-1,s=r.DP;if(s!==~~s||s<0||s>1e6)throw Error(f);if(!i[0])throw Error("[big.js] Division by zero");if(!n[0])return new r(0*o);var u,c,a,h,v,d=i.slice(),p=u=i.length,w=n.length,g=n.slice(0,u),y=g.length,m=e,b=m.c=[],j=0,E=s+(m.e=t.e-e.e)+1;for(m.s=o,o=E<0?0:E,d.unshift(0);y++<u;)g.push(0);do{for(a=0;a<10;a++){if(u!=(y=g.length))h=u>y?1:-1;else for(v=-1,h=0;++v<u;)if(i[v]!=g[v]){h=i[v]>g[v]?1:-1;break}if(!(h<0))break;for(c=y==u?i:d;y;){if(g[--y]<c[y]){for(v=y;v&&!g[--v];)g[v]=9;--g[v],g[y]+=10}g[y]-=c[y]}for(;!g[0];)g.shift()}b[j++]=h?a:++a,g[0]&&h?g[y]=n[p]||0:g=[n[p]]}while((p++<w||void 0!==g[0])&&o--);return b[0]||1==j||(b.shift(),m.e--),j>E&&l(m,s,r.RM,void 0!==g[0]),m},c.eq=function(e){return!this.cmp(e)},c.gt=function(e){return this.cmp(e)>0},c.gte=function(e){return this.cmp(e)>-1},c.lt=function(e){return this.cmp(e)<0},c.lte=function(e){return this.cmp(e)<1},c.minus=c.sub=function(e){var t,r,n,i,o=this,s=o.constructor,u=o.s,f=(e=new s(e)).s;if(u!=f)return e.s=-f,o.plus(e);var c=o.c.slice(),a=o.e,l=e.c,h=e.e;if(!c[0]||!l[0])return l[0]?(e.s=-f,e):new s(c[0]?o:0);if(u=a-h){for((i=u<0)?(u=-u,n=c):(h=a,n=l),n.reverse(),f=u;f--;)n.push(0);n.reverse()}else for(r=((i=c.length<l.length)?c:l).length,u=f=0;f<r;f++)if(c[f]!=l[f]){i=c[f]<l[f];break}if(i&&(n=c,c=l,l=n,e.s=-e.s),(f=(r=l.length)-(t=c.length))>0)for(;f--;)c[t++]=0;for(f=t;r>u;){if(c[--r]<l[r]){for(t=r;t&&!c[--t];)c[t]=9;--c[t],c[r]+=10}c[r]-=l[r]}for(;0===c[--f];)c.pop();for(;0===c[0];)c.shift(),--h;return c[0]||(e.s=1,c=[h=0]),e.c=c,e.e=h,e},c.mod=function(e){var t,r=this,n=r.constructor,i=r.s,o=(e=new n(e)).s;if(!e.c[0])throw Error("[big.js] Division by zero");return r.s=e.s=1,t=1==e.cmp(r),r.s=i,e.s=o,t?new n(r):(i=n.DP,o=n.RM,n.DP=n.RM=0,r=r.div(e),n.DP=i,n.RM=o,this.minus(r.times(e)))},c.plus=c.add=function(e){var t,r=this,n=r.constructor,i=r.s,o=(e=new n(e)).s;if(i!=o)return e.s=-o,r.minus(e);var s=r.e,u=r.c,f=e.e,c=e.c;if(!u[0]||!c[0])return c[0]?e:new n(u[0]?r:0*i);if(u=u.slice(),i=s-f){for(i>0?(f=s,t=c):(i=-i,t=u),t.reverse();i--;)t.push(0);t.reverse()}for(u.length-c.length<0&&(t=c,c=u,u=t),i=c.length,o=0;i;u[i]%=10)o=(u[--i]=u[i]+c[i]+o)/10|0;for(o&&(u.unshift(o),++f),i=u.length;0===u[--i];)u.pop();return e.c=u,e.e=f,e},c.pow=function(e){var t=this,r=new t.constructor(1),n=r,i=e<0;if(e!==~~e||e<-1e6||e>1e6)throw Error(u+"exponent");for(i&&(e=-e);1&e&&(n=n.times(t)),e>>=1;)t=t.times(t);return i?r.div(n):n},c.round=function(e,t){var r=this.constructor;if(void 0===e)e=0;else if(e!==~~e||e<-1e6||e>1e6)throw Error(f);return l(new r(this),e,void 0===t?r.RM:t)},c.sqrt=function(){var e,t,r,n=this,i=n.constructor,o=n.s,u=n.e,f=new i(.5);if(!n.c[0])return new i(n);if(o<0)throw Error(s+"No square root");0===(o=Math.sqrt(n+""))||o===1/0?((t=n.c.join("")).length+u&1||(t+="0"),u=((u+1)/2|0)-(u<0||1&u),e=new i(((o=Math.sqrt(t))==1/0?"1e":(o=o.toExponential()).slice(0,o.indexOf("e")+1))+u)):e=new i(o),u=e.e+(i.DP+=4);do{r=e,e=f.times(r.plus(n.div(r)))}while(r.c.slice(0,u).join("")!==e.c.slice(0,u).join(""));return l(e,i.DP-=4,i.RM)},c.times=c.mul=function(e){var t,r=this,n=r.constructor,i=r.c,o=(e=new n(e)).c,s=i.length,u=o.length,f=r.e,c=e.e;if(e.s=r.s==e.s?1:-1,!i[0]||!o[0])return new n(0*e.s);for(e.e=f+c,s<u&&(t=i,i=o,o=t,c=s,s=u,u=c),t=new Array(c=s+u);c--;)t[c]=0;for(f=u;f--;){for(u=0,c=s+f;c>f;)u=t[c]+o[f]*i[c-f-1]+u,t[c--]=u%10,u=u/10|0;t[c]=(t[c]+u)%10}for(u?++e.e:t.shift(),f=t.length;!t[--f];)t.pop();return e.c=t,e},c.toExponential=function(e){return h(this,1,e,e)},c.toFixed=function(e){return h(this,2,e,this.e+e)},c.toPrecision=function(e){return h(this,3,e,e-1)},c.toString=function(){return h(this)},c.valueOf=c.toJSON=function(){return h(this,4)},(o=function e(){function t(r){var n=this;if(!(n instanceof t))return void 0===r?e():new t(r);r instanceof t?(n.s=r.s,n.e=r.e,n.c=r.c.slice()):function(e,t){var r,n,i;if(0===t&&1/t<0)t="-0";else if(!a.test(t+=""))throw Error(u+"number");e.s="-"==t.charAt(0)?(t=t.slice(1),-1):1,(r=t.indexOf("."))>-1&&(t=t.replace(".",""));(n=t.search(/e/i))>0?(r<0&&(r=n),r+=+t.slice(n+1),t=t.substring(0,n)):r<0&&(r=t.length);for(i=t.length,n=0;n<i&&"0"==t.charAt(n);)++n;if(n==i)e.c=[e.e=0];else{for(;i>0&&"0"==t.charAt(--i););for(e.e=r-n-1,e.c=[],r=0;n<=i;)e.c[r++]=+t.charAt(n++)}}(n,r),n.constructor=t}return t.prototype=c,t.DP=20,t.RM=1,t.NE=-7,t.PE=21,t.version="5.2.2",t}()).default=o.Big=o,void 0===(n=function(){return o}.call(t,r,t,e))||(e.exports=n)}()},function(e,t,r){"use strict";r.r(t);var n=r(0),i=r.n(n);function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,i=!1,o=void 0;try{for(var s,u=e[Symbol.iterator]();!(n=(s=u.next()).done)&&(r.push(s.value),!t||r.length!==t);n=!0);}catch(e){i=!0,o=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw o}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function f(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e,t){var r=t.get(e);if(!r)throw new TypeError("attempted to get private field on non-instance");return r.get?r.get.call(e):r.value}function a(e,t,r){var n=t.get(e);if(!n)throw new TypeError("attempted to set private field on non-instance");if(n.set)n.set.call(e,r);else{if(!n.writable)throw new TypeError("attempted to set read only private field");n.value=r}return r}var l=new WeakMap,h=new WeakMap,v=new WeakMap,d=new WeakMap,p=new WeakMap,w=function(){function e(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];u(this,e),l.set(this,{writable:!0,value:void 0}),h.set(this,{writable:!0,value:void 0}),v.set(this,{writable:!0,value:void 0}),d.set(this,{writable:!0,value:void 0}),p.set(this,{writable:!0,value:{ROUND_UP:3,ROUND_DOWN:0,ROUND_HALF_UP:1,ROUND_HALF_EVEN:2}}),a(this,v,t),a(this,l,parseFloat(r)||0),a(this,d,n),a(this,h,i)}var t,r,n;return t=e,(r=[{key:"plus",value:function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];var o=r.reduce((function(e,t){return e.plus(t)}),new i.a(c(this,l)));return new e(c(this,v),o,c(this,d))}},{key:"minus",value:function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];var o=r.reduce((function(e,t){return e.minus(t)}),new i.a(c(this,l)));return new e(c(this,v),o,c(this,d))}},{key:"times",value:function(t){var r=new i.a(c(this,l)).times(t);return new e(c(this,v),r,c(this,d))}},{key:"divide",value:function(t){var r=new i.a(c(this,l)).div(t);return new e(c(this,v),r,c(this,d))}},{key:"allocate",value:function(t){var r=this,n=new i.a(100).div(t.reduce((function(e,t){return e+t})));return t.map((function(t,o){var s=n.times(t),u=new i.a(c(r,l)).times(s).div(100),f=o%2==0?u.round(c(r,d),3):u.round(c(r,d),0);return new e(c(r,v),f,c(r,d))}))}},{key:"figure",get:function(){var e=c(this,l);if(e instanceof i.a||(e=new i.a(c(this,l))),c(this,h)){var t=o(e.toFixed(c(this,d)).split("."),2),r=t[0],n=t[1];return r=r.replace(/\B(?=(\d{3})+(?!\d))/g,","),void 0!==n?[r,n].join("."):r}return e.toFixed(c(this,d))}}])&&f(t.prototype,r),n&&f(t,n),e}();t.default=w}]).default})); //# sourceMappingURL=index.js.map