New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

js-big-counter

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-big-counter - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

src/JSBigCounter.test.js

127

dist/es6/JSBigCounter.js

@@ -28,6 +28,34 @@ /*

export default class JSBigCounter {
/**
* Construct a new big counter.
*
* @param {number|number[]} initialValue The initial value (an integer greater than or equal to 0) or an array of integers greater than or equal to 0.
* A negative integer (less than 0) will be normalized to 0.
*/
constructor(initialValue = 0) {
this.bigCounterArray = [initialValue >= 0 ? initialValue : 0];
let bigCounterArray;
if (Object.prototype.hasOwnProperty.call(initialValue, "length")) {
bigCounterArray = initialValue.map(value => value >= 0 ? value : 0);
} else {
bigCounterArray = [initialValue >= 0 ? initialValue : 0];
}
this.bigCounterArray = bigCounterArray;
if (!this.bigCounterArray.length) {
this.bigCounterArray = [0];
}
if (this.bigCounterArray.length > 1 && !this.bigCounterArray[this.bigCounterArray.length - 1]) {
this.bigCounterArray[this.bigCounterArray.length - 1] = 1;
}
}
/**
* Increment the big counter by 1.
*
* @return {undefined}
*/
increment() {

@@ -47,3 +75,9 @@ let currentBucketPos = 0;

}
/**
* Decrement the big counter by 1.
*
* @return {undefined}
*/
decrement() {

@@ -74,3 +108,9 @@ if (this.bigCounterArray[0] > 0) {

}
/**
* Returns a string representing the integer value of the big counter.
*
* @return {string} The integer string representing the integer value of the big counter.
*/
toString() {

@@ -89,4 +129,20 @@ const baseDecimal = Decimal.from(MAX_SAFE_INTEGER).add(1);

}
/**
* Compares this big counter with another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {number} The return value can be:
*
* - 1 if this big counter is greater than the given big counter;
* - 0 if they are equal;
* - 1 if this big counter is less than the given big counter;
*
*/
compareTo(bigCounter) {
if (this === bigCounter) {
return 0;
}
const l1 = this.bigCounterArray.length;

@@ -114,3 +170,65 @@ const l2 = bigCounter.bigCounterArray.length;

}
/**
* Tests whether this big counter is equal to another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {boolean} True this big counter is equal to the given big counter.
*/
isEqualTo(bigCounter) {
return this.compareTo(bigCounter) === 0;
}
/**
* Tests whether this big counter is greater than another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {boolean} True this big counter is greater than the given big counter.
*/
isGreaterThan(bigCounter) {
return this.compareTo(bigCounter) > 0;
}
/**
* Tests whether this big counter is less than another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {boolean} True this big counter is less than the given big counter.
*/
isLessThan(bigCounter) {
return this.compareTo(bigCounter) < 0;
}
/**
* Tests whether this big counter is greater than or equal to another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {boolean} True this big counter is greater than or equal to the given big counter.
*/
isGreaterThanOrEqualTo(bigCounter) {
return this.isGreaterThan(bigCounter) || this.isEqualTo(bigCounter);
}
/**
* Tests whether this big counter is less than or equal to another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {boolean} True this big counter is less than or equal to the given big counter.
*/
isLessThanOrEqualTo(bigCounter) {
return this.isLessThan(bigCounter) || this.isEqualTo(bigCounter);
}
/**
* Static method to serialize a big counter to JSON.
*
* @param {JSBigCounter} bigCounter A big counter.
* @return {string} The JSON representing the given big counter.
*/
static toJSON(bigCounter) {

@@ -121,3 +239,10 @@ return JSON.stringify({

}
/**
* Static method to unserialize a big counter from its JSON representation.
*
* @param {string} json A big counter JSON representation, previously returned by `JSBigCounter.toJSON`.
* @return {JSBigCounter} The unserialized big counter.
*/
static fromJSON(json) {

@@ -124,0 +249,0 @@ const parsed = JSON.parse(json);

2

dist/js-big-counter.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("JSBigCounter",[],t):"object"==typeof exports?exports.JSBigCounter=t():e.JSBigCounter=t()}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(function(){return(()=>{"use strict";var e={247:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(713)),l=r(217),o=n(r(489)),u=n(r(279)),i=n(r(626)),f=n(r(656)),s=n(r(997)),c=n(r(161)),g=n(r(436)),d=n(r(207)),h=n(r(373)),v=n(r(630));class I{constructor(e,t,r,n){this.length=e,this.scale=t,this.value=r,this.sign=n}add(e,t){return I.fromInfo(a.default(this,I.from(e),t))}subtract(e,t){return I.fromInfo(v.default(this,I.from(e),t))}multiply(e,t){return I.fromInfo(d.default(this,I.from(e),t))}divide(e,t){return I.fromInfo(u.default(this,I.from(e),t))}raise(e,t){return I.fromInfo(h.default(this,I.from(e),t))}modulo(e,t){return I.fromInfo(g.default(this,I.from(e),t))}divideModulo(e,t){const[r,n]=i.default(this,I.from(e),t);return[I.from(r),I.from(n)]}compareTo(e){return o.default(this,I.from(e))}isEqualTo(e){return 0===this.compareTo(e)}isGreaterThan(e){return 1===this.compareTo(e)}isGreaterThanOrEqualTo(e){return this.compareTo(e)>=0}isLowerThan(e){return-1===this.compareTo(e)}isLowerThanOrEqualTo(e){return this.compareTo(e)<=0}isZero(){return f.default(this)}isOne(){return this.isEqualTo(I.ONE)}isMinusOne(){return this.isEqualTo(I.MINUS_ONE)}negate(){return I.fromInfo(l.negate(this))}isNegative(){return this.sign===l.DecimalSign.MINUS}isPositive(){return this.sign===l.DecimalSign.PLUS}toString(){return l.createStringFromInfo(this)}toInt(){return parseInt(this.toString(),l.DECIMAL_RADIX)}toFloat(){return parseFloat(this.toString())}toFixed(e){return l.createStringFromInfo(this,e)}static max(...e){return I.from(s.default(...e.map(I.from)))}static min(...e){return I.from(c.default(...e.map(I.from)))}static fromString(e){return I.fromInfo(l.createInfoFromString(e))}static fromInfo(e){return new I(e.length,e.scale,e.value,e.sign)}static fromNumber(e){return I.fromInfo(l.createInfoFromString(e.toString(l.DECIMAL_RADIX)))}static from(e){if(e instanceof I)return e;if("string"==typeof e)return I.fromString(e);if("number"==typeof e)return I.fromNumber(e);if(l.isInfo(e))return I.fromInfo(e);throw Error(`Don't know how to parse value of type ${typeof e} to decimal`)}static isDecimal(e){return e instanceof I}static isDecimalLike(e){return e instanceof I||["string","number"].includes(typeof e)||l.isInfo(e)}}I.ZERO=I.fromInfo(l.INFO_ZERO),I.ONE=I.fromInfo(l.INFO_ONE),I.MINUS_ONE=I.fromInfo(l.INFO_MINUS_ONE),t.default=I},713:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(20)),l=r(217),o=n(r(489)),u=n(r(369)),{max:i}=Math;t.default=function(e,t,r=i(e.scale,t.scale)){let n;if(e.sign===t.sign)return n=a.default(e,t,r),n.sign=e.sign,n;switch(o.default(e,t,!1)){case-1:n=u.default(t,e,r),n.sign=t.sign;break;case 0:const a=i(r,i(e.scale,t.scale));n=l.createInfo(1,a);break;case 1:n=u.default(e,t,r),n.sign=e.sign;break;default:throw Error("Invalid decimal comparison result")}return n}},20:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(549)),{max:o}=Math;t.default=function(e,t,r=0){const n=o(e.scale,t.scale),u=o(e.length,t.length)+1,i=a.createInfo(u,o(n,r));let f=e.scale,s=t.scale,c=e.length+f-1,g=t.length+s-1,d=n+u-1;if(f!==s)if(f>s)for(;f>s;d-=1,c-=1,f-=1)i.value[d]=e.value[c];else for(;s>f;d-=1,g-=1,s-=1)i.value[d]=t.value[g];f+=e.length,s+=t.length;let h,v=0;for(;f>0&&s>0;c-=1,g-=1,d-=1,f-=1,s-=1)h=e.value[c]+t.value[g]+v,h>=a.DECIMAL_RADIX?(v=1,h-=a.DECIMAL_RADIX):v=0,i.value[d]=h;if(0===f)for(;s>0;s-=1,g-=1,d-=1)h=t.value[g]+v,h>=a.DECIMAL_RADIX?(v=1,h-=a.DECIMAL_RADIX):v=0,i.value[d]=h;else for(;f>0;f-=1,c-=1,d-=1)h=e.value[c]+v,h>=a.DECIMAL_RADIX?(v=1,h-=a.DECIMAL_RADIX):v=0,i.value[d]=h;return 1===v&&(i.value[d]+=1),l.default(i)}},217:(e,t)=>{var r;function n(e=1,t=0){return{length:e,scale:t,sign:r.PLUS,value:new Uint8Array(e+t)}}function a(e,t=e.length,r=e.length-t,a=0){const l=n(t,r);return l.value.set(e,a),l}function l(e){return Object.assign({},e,{sign:e.sign===r.PLUS?r.MINUS:r.PLUS})}Object.defineProperty(t,"__esModule",{value:!0}),t.DECIMAL_VALIDATION_REGEX=/^[+\-]?\d+(\.\d+)?$/,t.DECIMAL_RADIX=10,function(e){e.PLUS="+",e.MINUS="-"}(r=t.DecimalSign||(t.DecimalSign={})),t.INFO_ZERO=n(),t.INFO_ONE=a([1]),t.INFO_MINUS_ONE=l(a([1])),t.createInfo=n,t.createInfoFromArray=a,t.createInfoFromString=function(e){if("string"!=typeof e)throw new TypeError(`Invalid ${typeof e} argument passed, string expected`);if(!e.match(t.DECIMAL_VALIDATION_REGEX))throw Error(`Invalid decimal string ${e} provided`);let n=e,l=r.PLUS;const o=e.charAt(0);o!==r.PLUS&&o!==r.MINUS||(o===r.MINUS&&(l=r.MINUS),n=n.substr(1)),n=n.replace(/^0+([0-9])/,"$1");const u=n.indexOf(".");let i=n.length,f=0;return-1!==u&&(f=i-(u+1),i-=f+1,n=n.replace(".","")),Object.assign({},a(n.split("").map(e=>parseInt(e,t.DECIMAL_RADIX)),i,f),{sign:l})},t.createStringFromInfo=function(e,t=e.scale){let n=e.value.subarray(0,e.length).join("");return t>0&&(n+="."+e.value.subarray(e.length,e.length+t).join("")),(e.sign===r.MINUS?r.MINUS:"")+n},t.createSubInfo=function(e,t=e.length,r=e.scale,n=0,l=0){return a(e.value.subarray(n),t,r,l)},t.copyInfo=function(e){return{sign:e.sign,length:e.length,scale:e.scale,value:new Uint8Array(e.value)}},t.isInfo=function(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&"number"==typeof e.scale&&"string"==typeof e.sign&&[r.PLUS,r.MINUS].includes(e.sign)&&"object"==typeof e.value&&e.value instanceof Uint8Array},t.negate=l},489:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});const n=r(217),{min:a}=Math;t.default=function(e,t,r=!0,l=!1){if(r&&e.sign!==t.sign)return e.sign===n.DecimalSign.PLUS?1:-1;if(e.length!==t.length)return e.length>t.length?r&&e.sign!==n.DecimalSign.PLUS?-1:1:r&&e.sign!==n.DecimalSign.PLUS?1:-1;let o=e.length+a(e.scale,t.scale),u=0,i=0;for(;o>0&&e.value[u]===t.value[i];)u+=1,i+=1,o-=1;if(l&&1===o&&e.scale===t.scale)return 0;if(0!==o)return e.value[u]>t.value[i]?r&&e.sign!==n.DecimalSign.PLUS?-1:1:r&&e.sign!==n.DecimalSign.PLUS?1:-1;if(e.scale!==t.scale)if(e.scale>t.scale){for(o=e.scale-t.scale;o>0;o-=1,u+=1)if(0!==e.value[u])return r&&e.sign!==n.DecimalSign.PLUS?-1:1}else for(o=t.scale-e.scale;o>0;o-=1,i+=1)if(0!==t.value[i])return r&&e.sign!==n.DecimalSign.PLUS?1:-1;return 0}},279:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(489)),o=n(r(656)),u=n(r(549)),{min:i,max:f,floor:s}=Math;function c(e,t,r,n,l,o){if(0===n)return void l.fill(0,0,r);if(1===n)return void l.set(e.subarray(t,t+r),o);let u,i,f=t+r-1,c=o+r-1;u=0;let g=r;for(;g>0;g-=1,f-=1,c-=1)i=e[f]*n+u,l[c]=i%a.DECIMAL_RADIX,u=s(i/a.DECIMAL_RADIX);0!==u&&(l[c]=u)}t.default=function(e,t,r=f(e.scale,t.scale)){if(o.default(t))throw Error("Division by zero");if(o.default(e))return a.createInfo(1,r);if(0===l.default(e,t))return a.createInfoFromArray([1],1,r);let n;if(0===t.scale&&1===t.length&&1===t.value[0])return n=a.createInfo(e.length,r),n.sign=e.sign===t.sign?a.DecimalSign.PLUS:a.DecimalSign.MINUS,n.value.fill(0,e.length,e.length+r),n.value.set(e.value.subarray(e.length+i(e.scale,r))),n;let g=t.scale,d=t.length+g-1;for(;g>0&&0===t.value[d];d-=1)g-=1;const h=e.length+g,v=e.scale-g,I=v<r?r-v:0,m=new Uint8Array(e.length+e.scale+I+2).fill(0);m.set(e.value,1);let _=t.length+g;const y=new Uint8Array(_+1);for(y.set(t.value),d=0;0===y[d];)d+=1,_-=1;let p,b;_>h+r?(b=r+1,p=!0):(p=!1,b=_>h?r+1:h-_+r+1),n=a.createInfo(b-r,r);const S=new Uint8Array(_+1),A=a.copyInfo(t);if(!p){const e=s(10/(t.value[d]+1));1!==e&&(c(m,0,h+v+I+1,e,m,0),c(t.value,d,_,e,t.value,d));let a=0,l=_>h?_-h:0;for(;a<=h+r-_;){let e;e=t.value[d]===m[a]?9:s((10*m[a]+m[a+1])/t.value[d]),t.value[d+1]*e>10*(10*m[a]+m[a+1]-t.value[d]*e)+m[a+2]&&(e-=1,t.value[d+1]*e>10*(10*m[a]+m[a+1]-t.value[d]*e)+m[a+2]&&(e-=1));let r=0;if(0!==e){S[0]=0,c(t.value,d,_,e,S,1);let n=a+_,l=_;for(let e=0;e<_+1;e+=1,n-=1){let e;l<0?e=m[n]-r:(e=m[n]-S[l]-r,l-=1),e<0?(e+=10,r=1):r=0,m[n]=e}}if(1===r){e-=1;let r=a+_,n=_-1,l=0;for(let e=0;e<_;e+=1,r-=1){let e;n<0?e=m[r]+l:(e=m[r]+t.value[n]+l,n-=1),e>9?(e-=10,l=1):l=0,m[r]=e}1===l&&(m[r]=(m[r]+1)%10)}n.value[l]=e,l+=1,a+=1}}return n.sign=e.sign===t.sign?a.DecimalSign.PLUS:a.DecimalSign.MINUS,o.default(n)&&(n.sign=a.DecimalSign.PLUS),Object.assign(t,A),u.default(n)}},626:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(279)),o=n(r(656)),u=n(r(997)),i=n(r(207)),f=n(r(630));t.default=function(e,t,r=Math.max(e.scale,t.scale)){if(o.default(t))throw Error("Division by zero");const n=Math.max(e.scale,t.scale+r),s=l.default(e,t,0),c=i.default(s,t,n),g=f.default(e,c,n);return[s,u.default(g,a.INFO_ZERO)]}},350:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(713));t.add=a.default;const l=n(r(20));t.addUnsigned=l.default;const o=r(217);t.copyInfo=o.copyInfo,t.createInfo=o.createInfo,t.createInfoFromArray=o.createInfoFromArray,t.createInfoFromString=o.createInfoFromString,t.createStringFromInfo=o.createStringFromInfo,t.createSubInfo=o.createSubInfo;const u=n(r(489));t.compare=u.default;const i=n(r(247)),f=n(r(279));t.divide=f.default;const s=n(r(656));t.isZero=s.default;const c=n(r(207));t.multiply=c.default;const g=n(r(549));t.removeLeadingZeroes=g.default;const d=n(r(630));t.subtract=d.default;const h=n(r(369));t.subtractUnsigned=h.default,t.default=i.default},656:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){const t=e.length+e.scale;for(let r=0;r<t;r+=1)if(0!==e.value[r])return!1;return!0}},997:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(489));t.default=function(...e){if(e.length<2)throw Error("At least two values must be given");return 2===e.length?1===a.default(e[0],e[1])?e[0]:e[1]:(e.sort(a.default),e[e.length-1])}},161:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(489));t.default=function(...e){if(e.length<2)throw Error("At least two values must be given");return 2===e.length?1===a.default(e[0],e[1])?e[1]:e[0]:(e.sort(a.default),e[0])}},436:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(626)),{max:l}=Math;t.default=function(e,t,r=l(e.scale,t.scale)){return a.default(e,t,r)[1]}},207:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(656)),o=n(r(549)),u=n(r(630)),{min:i,max:f,floor:s}=Math;function c(e,t,r,n,l=0){const o=t+n+1,u=a.createInfo(o),c=t-1,g=n-1;let d,h,v=o-1,I=0;for(let t=0;t<o-1;t+=1,v-=1){for(d=c-f(0,t-n+1),h=g-i(t,n-1);d>=0&&h<=g;d-=1,h+=1)I+=e.value[d]*r.value[h];u.value[v]=s(I%a.DECIMAL_RADIX),I=s(I/a.DECIMAL_RADIX)}return u.value[v]=I,u}function g(e,t,r,n,i=0){if(t+n<80||t<20||n<20)return c(e,t,r,n,i);const h=s((f(t,n)+1)/2);let v,I,m,_;t<h?(I=a.createInfo(),v=a.createSubInfo(e,t,0)):(I=a.createSubInfo(e,t-h,0),v=a.createSubInfo(e,h,0,t-h)),n<h?(_=a.createInfo(),m=a.createSubInfo(r,n,0)):(_=a.createSubInfo(r,n-h,0),m=a.createSubInfo(r,h,0,n-h)),I=o.default(I),v=o.default(v),_=o.default(_),m=o.default(m);const y=l.default(I)||l.default(_),p=u.default(I,v),b=p.length,S=u.default(m,_),A=S.length;let D,M,E;D=y?a.createInfo():g(I,I.length,_,_.length),M=l.default(p)||l.default(S)?a.createInfo():g(p,b,S,A),E=l.default(v)||l.default(m)?a.createInfo():g(v,v.length,m,m.length);const C=t+n+1;let O=a.createInfo(C);return y||(O=d(O,D,2*h),O=d(O,D,h)),O=d(O,E,h),O=d(O,E,0),O=d(O,M,h,p.sign!==S.sign),O}function d(e,t,r,n=!1){const l=a.copyInfo(e);let o=t.length;if(0===t.value[0]&&(o-=1),l.length+l.scale<r+o)throw Error("len + scale < shift + count");let u=l.length+l.scale-r-1,i=t.length-1,f=0;if(n){for(;o>=0;o-=1,i-=1,u-=1)l.value[u]-=t.value[i]+f,l.value[u]<0?(f=1,l.value[u]+=a.DECIMAL_RADIX):f=0;for(;f;u-=1)l.value[u]-=f,l.value[u]<0?l.value[u]+=a.DECIMAL_RADIX:f=0}else{for(;o>=0;o-=1,i-=1,u-=1)l.value[u]+=t.value[i]+f,l.value[u]>a.DECIMAL_RADIX-1?(f=1,l.value[u]-=a.DECIMAL_RADIX):f=0;for(;f;u-=1)l.value[u]+=f,l.value[u]>a.DECIMAL_RADIX-1?l.value[u]-=a.DECIMAL_RADIX:f=0}return l}t.default=function(e,t,r=f(e.scale,t.scale)){const n=e.length+e.scale,u=t.length+t.scale,s=e.scale+t.scale,c=i(r,s);let d=g(e,n,t,u,s);return d.sign=e.sign===t.sign?a.DecimalSign.PLUS:a.DecimalSign.MINUS,d.length=u+n+1-s,d.scale=c,d.scale<d.value.length&&(d.value=d.value.subarray(0,d.length+d.scale)),d=o.default(d),l.default(d)&&(d.sign=a.DecimalSign.PLUS),d},t.multiplySimple=c,t.multiplyRecursive=g,t.shiftAddSubtract=d},373:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(279)),o=n(r(207)),{min:u,max:i}=Math;t.default=function(e,t,r=i(e.scale,t.scale)){if(t.scale>0)throw Error("Trying to build power with non-integral exponent");let n,f,s=parseInt(a.createStringFromInfo(t),a.DECIMAL_RADIX);if(isNaN(s)||0===s&&(t.length>1||0!==t.value[0]))throw Error("Exponent too large in raise");if(0===s)return a.createInfoFromArray([1],r);s<0?(n=!0,s=-s,f=r):(n=!1,f=u(e.scale*s,i(r,e.scale)));let c=a.copyInfo(e),g=e.scale;for(;0==(1&s);)g*=2,c=o.default(c,c,g),s>>=1;let d,h=a.copyInfo(c),v=g;for(s>>=1;s>0;)g*=2,c=o.default(c,c,g),1==(1&s)&&(v=g+v,h=o.default(h,c,v)),s>>=1;return n?d=l.default(a.INFO_ONE,h,f):(d=h,d.scale>f&&(d.scale=f,d.value.length>d.length+d.scale&&(d.value=d.value.subarray(0,d.length+d.scale)))),d}},549:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){let t=0;for(;0===e.value[t]&&e.length-t>1;)t+=1;return t>0?{length:e.length-t,scale:e.scale,sign:e.sign,value:e.value.subarray(t)}:e}},630:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(20)),l=r(217),o=n(r(489)),u=n(r(369)),{max:i}=Math;t.default=function(e,t,r=i(e.scale,t.scale)){let n;if(e.sign!==t.sign)return n=a.default(e,t,r),n.sign=e.sign,n;switch(o.default(e,t,!1)){case-1:n=u.default(t,e,r),n.sign=t.sign===l.DecimalSign.PLUS?l.DecimalSign.MINUS:l.DecimalSign.PLUS;break;case 0:const a=i(r,i(e.scale,t.scale));n=l.createInfo(1,a);break;case 1:n=u.default(e,t,r),n.sign=e.sign;break;default:throw Error("Invalid decimal comparison result")}return n}},369:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(549)),{max:o,min:u}=Math;t.default=function(e,t,r=0){const n=o(e.length,t.length),i=o(e.scale,t.scale),f=u(e.length,t.length),s=u(e.scale,t.scale),c=a.createInfo(n,o(i,r));let g,d,h=e.length+e.scale-1,v=t.length+t.scale-1,I=n+i-1,m=0;if(e.scale!==s)for(g=e.scale-s;g>0;g-=1)c.value[I]=e.value[h],I-=1,h-=1;else for(g=t.scale-s;g>0;g-=1,v-=1,I-=1)d=0-t.value[v]-m,v-=1,d<0?(d+=a.DECIMAL_RADIX,m=1):m=0,c.value[I]=d;for(g=0;g<f+s;g+=1,h-=1,v-=1,I-=1)d=e.value[h]-t.value[v]-m,d<0?(d+=a.DECIMAL_RADIX,m=1):m=0,c.value[I]=d;if(n!==f)for(g=n-f;g>0;g-=1,h-=1,I-=1)d=e.value[h]-m,d<0?(d+=a.DECIMAL_RADIX,m=1):m=0,c.value[I]=d;return l.default(c)}}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var l=t[n]={exports:{}};return e[n].call(l.exports,l,l.exports,r),l.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};return(()=>{r.d(n,{default:()=>u});var e=r(350),t=r.n(e),a=Number.MAX_SAFE_INTEGER;function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(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)}}const u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;l(this,e),this.bigCounterArray=[t>=0?t:0]}var r,n,u;return r=e,u=[{key:"toJSON",value:function(e){return JSON.stringify({bigCounterArray:e.bigCounterArray})}},{key:"fromJSON",value:function(t){var r=JSON.parse(t),n=new e;return n.bigCounterArray=r.bigCounterArray,n}}],(n=[{key:"increment",value:function(){for(var e=0;this.bigCounterArray[e]===a;)this.bigCounterArray[e]=0,e++;this.bigCounterArray[e]||(this.bigCounterArray[e]=0),this.bigCounterArray[e]++}},{key:"decrement",value:function(){if(this.bigCounterArray[0]>0)this.bigCounterArray[0]--;else{if(1===this.bigCounterArray.length)return;this.bigCounterArray[0]=a;for(var e=1;0===this.bigCounterArray[e];)this.bigCounterArray[e]=a,e++;this.bigCounterArray[e]--,e===this.bigCounterArray.length-1&&0===this.bigCounterArray[e]&&this.bigCounterArray.pop()}}},{key:"toString",value:function(){for(var e=t().from(a).add(1),r=t().from(e),n=t().from(this.bigCounterArray[0]),l=1;l<this.bigCounterArray.length;l++){var o=this.bigCounterArray[l];r=1===l?r:r.multiply(e),n=n.add(t().from(o).multiply(r))}return n.toString()}},{key:"compareTo",value:function(e){var t=this.bigCounterArray.length,r=e.bigCounterArray.length;if(t>r)return 1;if(r>t)return-1;for(var n=t;n>=0;n--){var a=this.bigCounterArray[n],l=e.bigCounterArray[n];if(a>l)return 1;if(l>a)return-1}return 0}}])&&o(r.prototype,n),u&&o(r,u),e}()})(),n=n.default})()}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("JSBigCounter",[],t):"object"==typeof exports?exports.JSBigCounter=t():e.JSBigCounter=t()}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(function(){return(()=>{"use strict";var e={247:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(713)),l=r(217),o=n(r(489)),u=n(r(279)),i=n(r(626)),s=n(r(656)),f=n(r(997)),c=n(r(161)),g=n(r(436)),h=n(r(207)),d=n(r(373)),v=n(r(630));class m{constructor(e,t,r,n){this.length=e,this.scale=t,this.value=r,this.sign=n}add(e,t){return m.fromInfo(a.default(this,m.from(e),t))}subtract(e,t){return m.fromInfo(v.default(this,m.from(e),t))}multiply(e,t){return m.fromInfo(h.default(this,m.from(e),t))}divide(e,t){return m.fromInfo(u.default(this,m.from(e),t))}raise(e,t){return m.fromInfo(d.default(this,m.from(e),t))}modulo(e,t){return m.fromInfo(g.default(this,m.from(e),t))}divideModulo(e,t){const[r,n]=i.default(this,m.from(e),t);return[m.from(r),m.from(n)]}compareTo(e){return o.default(this,m.from(e))}isEqualTo(e){return 0===this.compareTo(e)}isGreaterThan(e){return 1===this.compareTo(e)}isGreaterThanOrEqualTo(e){return this.compareTo(e)>=0}isLowerThan(e){return-1===this.compareTo(e)}isLowerThanOrEqualTo(e){return this.compareTo(e)<=0}isZero(){return s.default(this)}isOne(){return this.isEqualTo(m.ONE)}isMinusOne(){return this.isEqualTo(m.MINUS_ONE)}negate(){return m.fromInfo(l.negate(this))}isNegative(){return this.sign===l.DecimalSign.MINUS}isPositive(){return this.sign===l.DecimalSign.PLUS}toString(){return l.createStringFromInfo(this)}toInt(){return parseInt(this.toString(),l.DECIMAL_RADIX)}toFloat(){return parseFloat(this.toString())}toFixed(e){return l.createStringFromInfo(this,e)}static max(...e){return m.from(f.default(...e.map(m.from)))}static min(...e){return m.from(c.default(...e.map(m.from)))}static fromString(e){return m.fromInfo(l.createInfoFromString(e))}static fromInfo(e){return new m(e.length,e.scale,e.value,e.sign)}static fromNumber(e){return m.fromInfo(l.createInfoFromString(e.toString(l.DECIMAL_RADIX)))}static from(e){if(e instanceof m)return e;if("string"==typeof e)return m.fromString(e);if("number"==typeof e)return m.fromNumber(e);if(l.isInfo(e))return m.fromInfo(e);throw Error(`Don't know how to parse value of type ${typeof e} to decimal`)}static isDecimal(e){return e instanceof m}static isDecimalLike(e){return e instanceof m||["string","number"].includes(typeof e)||l.isInfo(e)}}m.ZERO=m.fromInfo(l.INFO_ZERO),m.ONE=m.fromInfo(l.INFO_ONE),m.MINUS_ONE=m.fromInfo(l.INFO_MINUS_ONE),t.default=m},713:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(20)),l=r(217),o=n(r(489)),u=n(r(369)),{max:i}=Math;t.default=function(e,t,r=i(e.scale,t.scale)){let n;if(e.sign===t.sign)return n=a.default(e,t,r),n.sign=e.sign,n;switch(o.default(e,t,!1)){case-1:n=u.default(t,e,r),n.sign=t.sign;break;case 0:const a=i(r,i(e.scale,t.scale));n=l.createInfo(1,a);break;case 1:n=u.default(e,t,r),n.sign=e.sign;break;default:throw Error("Invalid decimal comparison result")}return n}},20:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(549)),{max:o}=Math;t.default=function(e,t,r=0){const n=o(e.scale,t.scale),u=o(e.length,t.length)+1,i=a.createInfo(u,o(n,r));let s=e.scale,f=t.scale,c=e.length+s-1,g=t.length+f-1,h=n+u-1;if(s!==f)if(s>f)for(;s>f;h-=1,c-=1,s-=1)i.value[h]=e.value[c];else for(;f>s;h-=1,g-=1,f-=1)i.value[h]=t.value[g];s+=e.length,f+=t.length;let d,v=0;for(;s>0&&f>0;c-=1,g-=1,h-=1,s-=1,f-=1)d=e.value[c]+t.value[g]+v,d>=a.DECIMAL_RADIX?(v=1,d-=a.DECIMAL_RADIX):v=0,i.value[h]=d;if(0===s)for(;f>0;f-=1,g-=1,h-=1)d=t.value[g]+v,d>=a.DECIMAL_RADIX?(v=1,d-=a.DECIMAL_RADIX):v=0,i.value[h]=d;else for(;s>0;s-=1,c-=1,h-=1)d=e.value[c]+v,d>=a.DECIMAL_RADIX?(v=1,d-=a.DECIMAL_RADIX):v=0,i.value[h]=d;return 1===v&&(i.value[h]+=1),l.default(i)}},217:(e,t)=>{var r;function n(e=1,t=0){return{length:e,scale:t,sign:r.PLUS,value:new Uint8Array(e+t)}}function a(e,t=e.length,r=e.length-t,a=0){const l=n(t,r);return l.value.set(e,a),l}function l(e){return Object.assign({},e,{sign:e.sign===r.PLUS?r.MINUS:r.PLUS})}Object.defineProperty(t,"__esModule",{value:!0}),t.DECIMAL_VALIDATION_REGEX=/^[+\-]?\d+(\.\d+)?$/,t.DECIMAL_RADIX=10,function(e){e.PLUS="+",e.MINUS="-"}(r=t.DecimalSign||(t.DecimalSign={})),t.INFO_ZERO=n(),t.INFO_ONE=a([1]),t.INFO_MINUS_ONE=l(a([1])),t.createInfo=n,t.createInfoFromArray=a,t.createInfoFromString=function(e){if("string"!=typeof e)throw new TypeError(`Invalid ${typeof e} argument passed, string expected`);if(!e.match(t.DECIMAL_VALIDATION_REGEX))throw Error(`Invalid decimal string ${e} provided`);let n=e,l=r.PLUS;const o=e.charAt(0);o!==r.PLUS&&o!==r.MINUS||(o===r.MINUS&&(l=r.MINUS),n=n.substr(1)),n=n.replace(/^0+([0-9])/,"$1");const u=n.indexOf(".");let i=n.length,s=0;return-1!==u&&(s=i-(u+1),i-=s+1,n=n.replace(".","")),Object.assign({},a(n.split("").map(e=>parseInt(e,t.DECIMAL_RADIX)),i,s),{sign:l})},t.createStringFromInfo=function(e,t=e.scale){let n=e.value.subarray(0,e.length).join("");return t>0&&(n+="."+e.value.subarray(e.length,e.length+t).join("")),(e.sign===r.MINUS?r.MINUS:"")+n},t.createSubInfo=function(e,t=e.length,r=e.scale,n=0,l=0){return a(e.value.subarray(n),t,r,l)},t.copyInfo=function(e){return{sign:e.sign,length:e.length,scale:e.scale,value:new Uint8Array(e.value)}},t.isInfo=function(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&"number"==typeof e.scale&&"string"==typeof e.sign&&[r.PLUS,r.MINUS].includes(e.sign)&&"object"==typeof e.value&&e.value instanceof Uint8Array},t.negate=l},489:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});const n=r(217),{min:a}=Math;t.default=function(e,t,r=!0,l=!1){if(r&&e.sign!==t.sign)return e.sign===n.DecimalSign.PLUS?1:-1;if(e.length!==t.length)return e.length>t.length?r&&e.sign!==n.DecimalSign.PLUS?-1:1:r&&e.sign!==n.DecimalSign.PLUS?1:-1;let o=e.length+a(e.scale,t.scale),u=0,i=0;for(;o>0&&e.value[u]===t.value[i];)u+=1,i+=1,o-=1;if(l&&1===o&&e.scale===t.scale)return 0;if(0!==o)return e.value[u]>t.value[i]?r&&e.sign!==n.DecimalSign.PLUS?-1:1:r&&e.sign!==n.DecimalSign.PLUS?1:-1;if(e.scale!==t.scale)if(e.scale>t.scale){for(o=e.scale-t.scale;o>0;o-=1,u+=1)if(0!==e.value[u])return r&&e.sign!==n.DecimalSign.PLUS?-1:1}else for(o=t.scale-e.scale;o>0;o-=1,i+=1)if(0!==t.value[i])return r&&e.sign!==n.DecimalSign.PLUS?1:-1;return 0}},279:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(489)),o=n(r(656)),u=n(r(549)),{min:i,max:s,floor:f}=Math;function c(e,t,r,n,l,o){if(0===n)return void l.fill(0,0,r);if(1===n)return void l.set(e.subarray(t,t+r),o);let u,i,s=t+r-1,c=o+r-1;u=0;let g=r;for(;g>0;g-=1,s-=1,c-=1)i=e[s]*n+u,l[c]=i%a.DECIMAL_RADIX,u=f(i/a.DECIMAL_RADIX);0!==u&&(l[c]=u)}t.default=function(e,t,r=s(e.scale,t.scale)){if(o.default(t))throw Error("Division by zero");if(o.default(e))return a.createInfo(1,r);if(0===l.default(e,t))return a.createInfoFromArray([1],1,r);let n;if(0===t.scale&&1===t.length&&1===t.value[0])return n=a.createInfo(e.length,r),n.sign=e.sign===t.sign?a.DecimalSign.PLUS:a.DecimalSign.MINUS,n.value.fill(0,e.length,e.length+r),n.value.set(e.value.subarray(e.length+i(e.scale,r))),n;let g=t.scale,h=t.length+g-1;for(;g>0&&0===t.value[h];h-=1)g-=1;const d=e.length+g,v=e.scale-g,m=v<r?r-v:0,I=new Uint8Array(e.length+e.scale+m+2).fill(0);I.set(e.value,1);let _=t.length+g;const y=new Uint8Array(_+1);for(y.set(t.value),h=0;0===y[h];)h+=1,_-=1;let p,b;_>d+r?(b=r+1,p=!0):(p=!1,b=_>d?r+1:d-_+r+1),n=a.createInfo(b-r,r);const A=new Uint8Array(_+1),S=a.copyInfo(t);if(!p){const e=f(10/(t.value[h]+1));1!==e&&(c(I,0,d+v+m+1,e,I,0),c(t.value,h,_,e,t.value,h));let a=0,l=_>d?_-d:0;for(;a<=d+r-_;){let e;e=t.value[h]===I[a]?9:f((10*I[a]+I[a+1])/t.value[h]),t.value[h+1]*e>10*(10*I[a]+I[a+1]-t.value[h]*e)+I[a+2]&&(e-=1,t.value[h+1]*e>10*(10*I[a]+I[a+1]-t.value[h]*e)+I[a+2]&&(e-=1));let r=0;if(0!==e){A[0]=0,c(t.value,h,_,e,A,1);let n=a+_,l=_;for(let e=0;e<_+1;e+=1,n-=1){let e;l<0?e=I[n]-r:(e=I[n]-A[l]-r,l-=1),e<0?(e+=10,r=1):r=0,I[n]=e}}if(1===r){e-=1;let r=a+_,n=_-1,l=0;for(let e=0;e<_;e+=1,r-=1){let e;n<0?e=I[r]+l:(e=I[r]+t.value[n]+l,n-=1),e>9?(e-=10,l=1):l=0,I[r]=e}1===l&&(I[r]=(I[r]+1)%10)}n.value[l]=e,l+=1,a+=1}}return n.sign=e.sign===t.sign?a.DecimalSign.PLUS:a.DecimalSign.MINUS,o.default(n)&&(n.sign=a.DecimalSign.PLUS),Object.assign(t,S),u.default(n)}},626:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(279)),o=n(r(656)),u=n(r(997)),i=n(r(207)),s=n(r(630));t.default=function(e,t,r=Math.max(e.scale,t.scale)){if(o.default(t))throw Error("Division by zero");const n=Math.max(e.scale,t.scale+r),f=l.default(e,t,0),c=i.default(f,t,n),g=s.default(e,c,n);return[f,u.default(g,a.INFO_ZERO)]}},350:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(713));t.add=a.default;const l=n(r(20));t.addUnsigned=l.default;const o=r(217);t.copyInfo=o.copyInfo,t.createInfo=o.createInfo,t.createInfoFromArray=o.createInfoFromArray,t.createInfoFromString=o.createInfoFromString,t.createStringFromInfo=o.createStringFromInfo,t.createSubInfo=o.createSubInfo;const u=n(r(489));t.compare=u.default;const i=n(r(247)),s=n(r(279));t.divide=s.default;const f=n(r(656));t.isZero=f.default;const c=n(r(207));t.multiply=c.default;const g=n(r(549));t.removeLeadingZeroes=g.default;const h=n(r(630));t.subtract=h.default;const d=n(r(369));t.subtractUnsigned=d.default,t.default=i.default},656:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){const t=e.length+e.scale;for(let r=0;r<t;r+=1)if(0!==e.value[r])return!1;return!0}},997:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(489));t.default=function(...e){if(e.length<2)throw Error("At least two values must be given");return 2===e.length?1===a.default(e[0],e[1])?e[0]:e[1]:(e.sort(a.default),e[e.length-1])}},161:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(489));t.default=function(...e){if(e.length<2)throw Error("At least two values must be given");return 2===e.length?1===a.default(e[0],e[1])?e[1]:e[0]:(e.sort(a.default),e[0])}},436:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(626)),{max:l}=Math;t.default=function(e,t,r=l(e.scale,t.scale)){return a.default(e,t,r)[1]}},207:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(656)),o=n(r(549)),u=n(r(630)),{min:i,max:s,floor:f}=Math;function c(e,t,r,n,l=0){const o=t+n+1,u=a.createInfo(o),c=t-1,g=n-1;let h,d,v=o-1,m=0;for(let t=0;t<o-1;t+=1,v-=1){for(h=c-s(0,t-n+1),d=g-i(t,n-1);h>=0&&d<=g;h-=1,d+=1)m+=e.value[h]*r.value[d];u.value[v]=f(m%a.DECIMAL_RADIX),m=f(m/a.DECIMAL_RADIX)}return u.value[v]=m,u}function g(e,t,r,n,i=0){if(t+n<80||t<20||n<20)return c(e,t,r,n,i);const d=f((s(t,n)+1)/2);let v,m,I,_;t<d?(m=a.createInfo(),v=a.createSubInfo(e,t,0)):(m=a.createSubInfo(e,t-d,0),v=a.createSubInfo(e,d,0,t-d)),n<d?(_=a.createInfo(),I=a.createSubInfo(r,n,0)):(_=a.createSubInfo(r,n-d,0),I=a.createSubInfo(r,d,0,n-d)),m=o.default(m),v=o.default(v),_=o.default(_),I=o.default(I);const y=l.default(m)||l.default(_),p=u.default(m,v),b=p.length,A=u.default(I,_),S=A.length;let D,M,E;D=y?a.createInfo():g(m,m.length,_,_.length),M=l.default(p)||l.default(A)?a.createInfo():g(p,b,A,S),E=l.default(v)||l.default(I)?a.createInfo():g(v,v.length,I,I.length);const C=t+n+1;let O=a.createInfo(C);return y||(O=h(O,D,2*d),O=h(O,D,d)),O=h(O,E,d),O=h(O,E,0),O=h(O,M,d,p.sign!==A.sign),O}function h(e,t,r,n=!1){const l=a.copyInfo(e);let o=t.length;if(0===t.value[0]&&(o-=1),l.length+l.scale<r+o)throw Error("len + scale < shift + count");let u=l.length+l.scale-r-1,i=t.length-1,s=0;if(n){for(;o>=0;o-=1,i-=1,u-=1)l.value[u]-=t.value[i]+s,l.value[u]<0?(s=1,l.value[u]+=a.DECIMAL_RADIX):s=0;for(;s;u-=1)l.value[u]-=s,l.value[u]<0?l.value[u]+=a.DECIMAL_RADIX:s=0}else{for(;o>=0;o-=1,i-=1,u-=1)l.value[u]+=t.value[i]+s,l.value[u]>a.DECIMAL_RADIX-1?(s=1,l.value[u]-=a.DECIMAL_RADIX):s=0;for(;s;u-=1)l.value[u]+=s,l.value[u]>a.DECIMAL_RADIX-1?l.value[u]-=a.DECIMAL_RADIX:s=0}return l}t.default=function(e,t,r=s(e.scale,t.scale)){const n=e.length+e.scale,u=t.length+t.scale,f=e.scale+t.scale,c=i(r,f);let h=g(e,n,t,u,f);return h.sign=e.sign===t.sign?a.DecimalSign.PLUS:a.DecimalSign.MINUS,h.length=u+n+1-f,h.scale=c,h.scale<h.value.length&&(h.value=h.value.subarray(0,h.length+h.scale)),h=o.default(h),l.default(h)&&(h.sign=a.DecimalSign.PLUS),h},t.multiplySimple=c,t.multiplyRecursive=g,t.shiftAddSubtract=h},373:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(279)),o=n(r(207)),{min:u,max:i}=Math;t.default=function(e,t,r=i(e.scale,t.scale)){if(t.scale>0)throw Error("Trying to build power with non-integral exponent");let n,s,f=parseInt(a.createStringFromInfo(t),a.DECIMAL_RADIX);if(isNaN(f)||0===f&&(t.length>1||0!==t.value[0]))throw Error("Exponent too large in raise");if(0===f)return a.createInfoFromArray([1],r);f<0?(n=!0,f=-f,s=r):(n=!1,s=u(e.scale*f,i(r,e.scale)));let c=a.copyInfo(e),g=e.scale;for(;0==(1&f);)g*=2,c=o.default(c,c,g),f>>=1;let h,d=a.copyInfo(c),v=g;for(f>>=1;f>0;)g*=2,c=o.default(c,c,g),1==(1&f)&&(v=g+v,d=o.default(d,c,v)),f>>=1;return n?h=l.default(a.INFO_ONE,d,s):(h=d,h.scale>s&&(h.scale=s,h.value.length>h.length+h.scale&&(h.value=h.value.subarray(0,h.length+h.scale)))),h}},549:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){let t=0;for(;0===e.value[t]&&e.length-t>1;)t+=1;return t>0?{length:e.length-t,scale:e.scale,sign:e.sign,value:e.value.subarray(t)}:e}},630:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(20)),l=r(217),o=n(r(489)),u=n(r(369)),{max:i}=Math;t.default=function(e,t,r=i(e.scale,t.scale)){let n;if(e.sign!==t.sign)return n=a.default(e,t,r),n.sign=e.sign,n;switch(o.default(e,t,!1)){case-1:n=u.default(t,e,r),n.sign=t.sign===l.DecimalSign.PLUS?l.DecimalSign.MINUS:l.DecimalSign.PLUS;break;case 0:const a=i(r,i(e.scale,t.scale));n=l.createInfo(1,a);break;case 1:n=u.default(e,t,r),n.sign=e.sign;break;default:throw Error("Invalid decimal comparison result")}return n}},369:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(217),l=n(r(549)),{max:o,min:u}=Math;t.default=function(e,t,r=0){const n=o(e.length,t.length),i=o(e.scale,t.scale),s=u(e.length,t.length),f=u(e.scale,t.scale),c=a.createInfo(n,o(i,r));let g,h,d=e.length+e.scale-1,v=t.length+t.scale-1,m=n+i-1,I=0;if(e.scale!==f)for(g=e.scale-f;g>0;g-=1)c.value[m]=e.value[d],m-=1,d-=1;else for(g=t.scale-f;g>0;g-=1,v-=1,m-=1)h=0-t.value[v]-I,v-=1,h<0?(h+=a.DECIMAL_RADIX,I=1):I=0,c.value[m]=h;for(g=0;g<s+f;g+=1,d-=1,v-=1,m-=1)h=e.value[d]-t.value[v]-I,h<0?(h+=a.DECIMAL_RADIX,I=1):I=0,c.value[m]=h;if(n!==s)for(g=n-s;g>0;g-=1,d-=1,m-=1)h=e.value[d]-I,h<0?(h+=a.DECIMAL_RADIX,I=1):I=0,c.value[m]=h;return l.default(c)}}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var l=t[n]={exports:{}};return e[n].call(l.exports,l,l.exports,r),l.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};return(()=>{r.d(n,{default:()=>u});var e=r(350),t=r.n(e),a=Number.MAX_SAFE_INTEGER;function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(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)}}const u=function(){function e(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;l(this,e),t=Object.prototype.hasOwnProperty.call(r,"length")?r.map((function(e){return e>=0?e:0})):[r>=0?r:0],this.bigCounterArray=t,this.bigCounterArray.length||(this.bigCounterArray=[0]),this.bigCounterArray.length>1&&!this.bigCounterArray[this.bigCounterArray.length-1]&&(this.bigCounterArray[this.bigCounterArray.length-1]=1)}var r,n,u;return r=e,u=[{key:"toJSON",value:function(e){return JSON.stringify({bigCounterArray:e.bigCounterArray})}},{key:"fromJSON",value:function(t){var r=JSON.parse(t),n=new e;return n.bigCounterArray=r.bigCounterArray,n}}],(n=[{key:"increment",value:function(){for(var e=0;this.bigCounterArray[e]===a;)this.bigCounterArray[e]=0,e++;this.bigCounterArray[e]||(this.bigCounterArray[e]=0),this.bigCounterArray[e]++}},{key:"decrement",value:function(){if(this.bigCounterArray[0]>0)this.bigCounterArray[0]--;else{if(1===this.bigCounterArray.length)return;this.bigCounterArray[0]=a;for(var e=1;0===this.bigCounterArray[e];)this.bigCounterArray[e]=a,e++;this.bigCounterArray[e]--,e===this.bigCounterArray.length-1&&0===this.bigCounterArray[e]&&this.bigCounterArray.pop()}}},{key:"toString",value:function(){for(var e=t().from(a).add(1),r=t().from(e),n=t().from(this.bigCounterArray[0]),l=1;l<this.bigCounterArray.length;l++){var o=this.bigCounterArray[l];r=1===l?r:r.multiply(e),n=n.add(t().from(o).multiply(r))}return n.toString()}},{key:"compareTo",value:function(e){if(this===e)return 0;var t=this.bigCounterArray.length,r=e.bigCounterArray.length;if(t>r)return 1;if(r>t)return-1;for(var n=t;n>=0;n--){var a=this.bigCounterArray[n],l=e.bigCounterArray[n];if(a>l)return 1;if(l>a)return-1}return 0}},{key:"isEqualTo",value:function(e){return 0===this.compareTo(e)}},{key:"isGreaterThan",value:function(e){return this.compareTo(e)>0}},{key:"isLessThan",value:function(e){return this.compareTo(e)<0}},{key:"isGreaterThanOrEqualTo",value:function(e){return this.isGreaterThan(e)||this.isEqualTo(e)}},{key:"isLessThanOrEqualTo",value:function(e){return this.isLessThan(e)||this.isEqualTo(e)}}])&&o(r.prototype,n),u&&o(r,u),e}()})(),n=n.default})()}));
{
"name": "js-big-counter",
"version": "1.1.0",
"version": "1.2.0",
"description": "Big integer/arbitrary-length counter for JavaScript.",

@@ -27,3 +27,4 @@ "keywords": [

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"test-coverage": "jest --coverage",
"watch": "WEBPACK_ENV=watch webpack --progress --color --watch",

@@ -39,4 +40,9 @@ "mkdir-build": "mkdir -p ./dist/es6",

"publish-major": "npm run build-all && npm version major && npm run publish-git",
"build-module": "cross-env BABEL_ENV=module ./node_modules/.bin/babel ./src --out-dir ./dist/es6 --source-maps --copy-files"
"build-module": "cross-env BABEL_ENV=module ./node_modules/.bin/babel ./src --out-dir ./dist/es6 --source-maps --copy-files --no-copy-ignored"
},
"jest": {
"transform": {
"^.+\\.[t|j]sx?$": "babel-jest"
}
},
"devDependencies": {

@@ -52,8 +58,13 @@ "@babel/cli": "^7.11.6",

"@babel/types": "^7.11.5",
"@types/jest": "^27.0.2",
"@types/node": "^13.13.21",
"@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2",
"babel-jest": "^27.3.1",
"babel-loader": "^8.1.0",
"eslint": "^7.32.0",
"eslint-plugin-jest": "^25.2.2",
"eslint-webpack-plugin": "^3.0.1",
"jest": "^27.3.1",
"jest-cli": "^27.3.1",
"minimist": ">=1.2.3",

@@ -60,0 +71,0 @@ "serialize-javascript": "^5.0.1",

@@ -30,6 +30,34 @@ /*

export default class JSBigCounter {
/**
* Construct a new big counter.
*
* @param {number|number[]} initialValue The initial value (an integer greater than or equal to 0) or an array of integers greater than or equal to 0.
* A negative integer (less than 0) will be normalized to 0.
*/
constructor(initialValue = 0) {
this.bigCounterArray = [initialValue >= 0 ? initialValue : 0];
let bigCounterArray;
if (Object.prototype.hasOwnProperty.call(initialValue, "length")) {
bigCounterArray = initialValue.map(value => (value >= 0 ? value : 0));
} else {
bigCounterArray = [initialValue >= 0 ? initialValue : 0];
}
this.bigCounterArray = bigCounterArray;
if (!this.bigCounterArray.length) {
this.bigCounterArray = [0];
}
if (
this.bigCounterArray.length > 1 &&
!this.bigCounterArray[this.bigCounterArray.length - 1]
) {
this.bigCounterArray[this.bigCounterArray.length - 1] = 1;
}
}
/**
* Increment the big counter by 1.
*
* @return {undefined}
*/
increment() {

@@ -41,8 +69,15 @@ let currentBucketPos = 0;

}
if (!this.bigCounterArray[currentBucketPos]) {
this.bigCounterArray[currentBucketPos] = 0;
}
this.bigCounterArray[currentBucketPos]++;
}
/**
* Decrement the big counter by 1.
*
* @return {undefined}
*/
decrement() {

@@ -56,2 +91,3 @@ if (this.bigCounterArray[0] > 0) {

}
this.bigCounterArray[0] = MAX_SAFE_INTEGER;

@@ -74,2 +110,7 @@ let currentBucketPos = 1;

/**
* Returns a string representing the integer value of the big counter.
*
* @return {string} The integer string representing the integer value of the big counter.
*/
toString() {

@@ -92,3 +133,18 @@ const baseDecimal = Decimal.from(MAX_SAFE_INTEGER).add(1);

/**
* Compares this big counter with another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {number} The return value can be:
*
* - 1 if this big counter is greater than the given big counter;
* - 0 if they are equal;
* - 1 if this big counter is less than the given big counter;
*
*/
compareTo(bigCounter) {
if (this === bigCounter) {
return 0;
}
const l1 = this.bigCounterArray.length;

@@ -101,2 +157,3 @@ const l2 = bigCounter.bigCounterArray.length;

}
for (let i = l1; i >= 0; i--) {

@@ -114,2 +171,58 @@ const bucket1 = this.bigCounterArray[i];

/**
* Tests whether this big counter is equal to another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {boolean} True this big counter is equal to the given big counter.
*/
isEqualTo(bigCounter) {
return this.compareTo(bigCounter) === 0;
}
/**
* Tests whether this big counter is greater than another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {boolean} True this big counter is greater than the given big counter.
*/
isGreaterThan(bigCounter) {
return this.compareTo(bigCounter) > 0;
}
/**
* Tests whether this big counter is less than another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {boolean} True this big counter is less than the given big counter.
*/
isLessThan(bigCounter) {
return this.compareTo(bigCounter) < 0;
}
/**
* Tests whether this big counter is greater than or equal to another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {boolean} True this big counter is greater than or equal to the given big counter.
*/
isGreaterThanOrEqualTo(bigCounter) {
return this.isGreaterThan(bigCounter) || this.isEqualTo(bigCounter);
}
/**
* Tests whether this big counter is less than or equal to another given big counter.
*
* @param {JSBigCounter} bigCounter Another big counter.
* @return {boolean} True this big counter is less than or equal to the given big counter.
*/
isLessThanOrEqualTo(bigCounter) {
return this.isLessThan(bigCounter) || this.isEqualTo(bigCounter);
}
/**
* Static method to serialize a big counter to JSON.
*
* @param {JSBigCounter} bigCounter A big counter.
* @return {string} The JSON representing the given big counter.
*/
static toJSON(bigCounter) {

@@ -119,2 +232,8 @@ return JSON.stringify({ bigCounterArray: bigCounter.bigCounterArray });

/**
* Static method to unserialize a big counter from its JSON representation.
*
* @param {string} json A big counter JSON representation, previously returned by `JSBigCounter.toJSON`.
* @return {JSBigCounter} The unserialized big counter.
*/
static fromJSON(json) {

@@ -121,0 +240,0 @@ const parsed = JSON.parse(json);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc