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

moneydew

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

moneydew - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

index.js

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

"use strict";class u{_isNegative=!1;_integerPart="0";_fractionalPart="0";_floatingPointPrecision=1;static _intRegex=/^\d+$/;constructor(r){this.value=r}set value(r){if(/^-[0]+(?:\.0+)?$/.test(r)&&(r=r.substring(1)),/^-\d+(?:\.\d+)?$/.test(r)?(r=r.substring(1),this._isNegative=!0):this._isNegative=!1,/^\d+\.\d+$/.test(r)){const t=r.split(".");this._integerPart=t[0],this._fractionalPart=t[1],this._floatingPointPrecision=t[1].length}else if(u._intRegex.test(r))this._integerPart=r,this._fractionalPart="",this._floatingPointPrecision=0;else throw new Error("Value does not match valid pattern.")}get value(){let r=(this.isNegative?"-":"")+this._integerPart;return this._floatingPointPrecision!==0&&(r+="."+this._fractionalPart),r}get integerPart(){return this._integerPart}get fractionalPart(){return this._fractionalPart}set integerPart(r){if(!u._intRegex.test(r))throw new Error("Input number is not a valid positive integer.");this._integerPart=r.toString(),this.isNull()&&(this.isNegative=!1)}set fractionalPart(r){if(!u._intRegex.test(r))throw new Error("Input number is not a valid positive integer to represent floating point numbers.");this._fractionalPart=r.toString(),this._floatingPointPrecision=r.length,this.isNull()&&(this._isNegative=!1)}get floatingPointPrecision(){return this._floatingPointPrecision}get isNegative(){return this._isNegative}set isNegative(r){this.isNull()||(this._isNegative=r)}isNull(){return/^[0]+$/.test(this._integerPart)&&/^[0]*$/.test(this._fractionalPart)}}class M{static addDigits(r,t,e){if(!/^\d$/.test(r)||!/^\d$/.test(t))throw new Error("Strings need to be single ascii digits.");let s=parseInt(r)+parseInt(t)+(e?1:0),a=s.toString();return[a.length===1?a:a.charAt(1),s>=10]}static min(r,t){const e=M.max(r,t);return e!==M.max(t,r)||e===t?r:t}static max(r,t){const e=r.integerPart,s=t.integerPart;if(r.isNegative&&!t.isNegative)return t;if(!r.isNegative&&t.isNegative)return r;{const a=r.isNegative&&t.isNegative;if(e.length>s.length)return a?t:r;if(e.length<s.length)return a?r:t;{for(let _=0;_<e.length;_++){let n=parseInt(e.charAt(_)),o=parseInt(s.charAt(_));if(n>o)return a?t:r;if(o>n)return a?r:t}const g=r.fractionalPart,p=t.fractionalPart;for(let _=0;_<Math.max(g.length,p.length);_++){let n=g.length>_?parseInt(g.charAt(_)):0,o=p.length>_?parseInt(p.charAt(_)):0;if(n>o)return a?t:r;if(o>n)return a?r:t}}}return r}static add(r,t){const e=r.floatingPointPrecision;if(e!==t.floatingPointPrecision)throw new Error("Amounts to add need to have the same floating point precision.");let s="",a="";const g=r.isNegative&&!t.isNegative,p=!r.isNegative&&t.isNegative;if(g||p){let _=!1;const n=r.isNegative,o=t.isNegative;r.isNegative=!1,t.isNegative=!1;const h=M.max(r,t),c=h===r?t:r;r.isNegative=n,t.isNegative=o;let S="",N="",y="";for(let l=e>0?0:1;l<2;l++){let d=l===0?h.fractionalPart:h.integerPart,m=l===0?c.fractionalPart:c.integerPart;l===1&&d.length>m.length&&(m="0".repeat(d.length-m.length)+m);for(let E=d.length-1;E>=0;E--){S=d.charAt(E),N=m.charAt(E);const B=parseInt(S),O=parseInt(N)+(_?1:0);B>=O?(y=(B-O).toString(),_=!1):(y=(10-(O-B)).toString(),_=!0),l===0?a=y+a:s=y+s}l===0&&(r.fractionalPart=a)}r.integerPart=s==="0"?"0":s.replace(/^0+/,""),r.isNegative=h.isNegative}else{let _=r.integerPart,n=t.integerPart;const o=Math.max(_.length,n.length);_=_.split("").reverse().join(""),n=n.split("").reverse().join("");let h=!1;if(e>0){const c=r.fractionalPart,S=t.fractionalPart;for(let N=e-1;N>=0;N--){const y=M.addDigits(c.charAt(N),S.charAt(N),h);h=y[1],a=y[0]+a}r.fractionalPart=a}for(let c=0;c<o;c++){const S=M.addDigits(c<_.length?_.charAt(c):"0",c<n.length?n.charAt(c):"0",h);h=S[1],s=S[0]+s}h&&(s="1"+s),r.integerPart=s}return r}static subtract(r,t){const e=t.isNegative;t.isNegative=!e;try{this.add(r,t)}catch(s){throw t.isNegative=e,s}return t.isNegative=e,r}}exports.DisplayOrder=void 0,function(i){i[i.SIGN_SYMBOL_NAME_NUMBER=0]="SIGN_SYMBOL_NAME_NUMBER",i[i.SIGN_NAME_SYMBOL_NUMBER=1]="SIGN_NAME_SYMBOL_NUMBER",i[i.SIGN_SYMBOL_NUMBER_NAME=2]="SIGN_SYMBOL_NUMBER_NAME",i[i.SIGN_NAME_NUMBER_SYMBOL=3]="SIGN_NAME_NUMBER_SYMBOL",i[i.SIGN_NUMBER_SYMBOL_NAME=4]="SIGN_NUMBER_SYMBOL_NAME",i[i.SIGN_NUMBER_NAME_SYMBOL=5]="SIGN_NUMBER_NAME_SYMBOL",i[i.SYMBOL_SIGN_NAME_NUMBER=6]="SYMBOL_SIGN_NAME_NUMBER",i[i.SYMBOL_NAME_SIGN_NUMBER=7]="SYMBOL_NAME_SIGN_NUMBER",i[i.SYMBOL_SIGN_NUMBER_NAME=8]="SYMBOL_SIGN_NUMBER_NAME",i[i.SYMBOL_NAME_NUMBER_SIGN=9]="SYMBOL_NAME_NUMBER_SIGN",i[i.SYMBOL_NUMBER_SIGN_NAME=10]="SYMBOL_NUMBER_SIGN_NAME",i[i.SYMBOL_NUMBER_NAME_SIGN=11]="SYMBOL_NUMBER_NAME_SIGN",i[i.NAME_SIGN_SYMBOL_NUMBER=12]="NAME_SIGN_SYMBOL_NUMBER",i[i.NAME_SYMBOL_SIGN_NUMBER=13]="NAME_SYMBOL_SIGN_NUMBER",i[i.NAME_SIGN_NUMBER_SYMBOL=14]="NAME_SIGN_NUMBER_SYMBOL",i[i.NAME_SYMBOL_NUMBER_SIGN=15]="NAME_SYMBOL_NUMBER_SIGN",i[i.NAME_NUMBER_SIGN_SYMBOL=16]="NAME_NUMBER_SIGN_SYMBOL",i[i.NAME_NUMBER_SYMBOL_SIGN=17]="NAME_NUMBER_SYMBOL_SIGN",i[i.NUMBER_NAME_SYMBOL_SIGN=18]="NUMBER_NAME_SYMBOL_SIGN",i[i.NUMBER_NAME_SIGN_SYMBOL=19]="NUMBER_NAME_SIGN_SYMBOL",i[i.NUMBER_SIGN_NAME_SYMBOL=20]="NUMBER_SIGN_NAME_SYMBOL",i[i.NUMBER_SIGN_SYMBOL_NAME=21]="NUMBER_SIGN_SYMBOL_NAME",i[i.NUMBER_SYMBOL_NAME_SIGN=22]="NUMBER_SYMBOL_NAME_SIGN",i[i.NUMBER_SYMBOL_SIGN_NAME=23]="NUMBER_SYMBOL_SIGN_NAME"}(exports.DisplayOrder||(exports.DisplayOrder={})),exports.MyriadMode=void 0,function(i){i[i.JAPANESE=0]="JAPANESE",i[i.CHINESE=1]="CHINESE"}(exports.MyriadMode||(exports.MyriadMode={}));class b{_currencySymbol="$";_symbolSeparator="";_currencyName="";_nameSeparator=" ";_positiveSign="";_negativeSign="-";_signSeparator="";_displayOrder=exports.DisplayOrder.SIGN_SYMBOL_NUMBER_NAME;_digitCharacters=["0","1","2","3","4","5","6","7","8","9"];_myriadMode=exports.MyriadMode.JAPANESE;_myriadCharacters=["\u5341","\u767E","\u5343","\u4E07","\u5104","\u5146","\u4EAC","\u5793","\u{25771}","\u7A63","\u6E9D","\u6F97","\u6B63","\u8F09"];_decimalSeparator=".";_groupSeparator=",";_groupSize=3;constructor(r){typeof r.currencySymbol=="string"&&(this.currencySymbol=r.currencySymbol),typeof r.symbolSeparator=="string"&&(this.symbolSeparator=r.symbolSeparator),typeof r.currencyName=="string"&&(this.currencyName=r.currencyName),typeof r.nameSeparator=="string"&&(this.nameSeparator=r.nameSeparator),typeof r.positiveSign=="string"&&(this.positiveSign=r.positiveSign),typeof r.negativeSign=="string"&&(this.negativeSign=r.negativeSign),typeof r.signSeparator=="string"&&(this.signSeparator=r.signSeparator),typeof r.displayOrder<"u"&&typeof r.displayOrder==typeof exports.DisplayOrder.SIGN_NUMBER_SYMBOL_NAME&&(this.displayOrder=r.displayOrder),typeof r.myriadMode<"u"&&typeof r.myriadMode==typeof exports.MyriadMode.JAPANESE&&(this.myriadMode=r.myriadMode),typeof r.digitCharacters=="object"&&(this.digitCharacters=r.digitCharacters),typeof r.myriadCharacters=="object"&&(this.myriadCharacters=r.myriadCharacters),typeof r.groupSeparator=="string"&&(this.groupSeparator=r.groupSeparator),typeof r.decimalSeparator=="string"&&(this.decimalSeparator=r.decimalSeparator),typeof r.groupSize=="number"&&(this.groupSize=r.groupSize)}handleJapaneseMyriad(r){let t=0,e="",s=!1;for(let a=0;a<r.length;a++)switch(t=parseInt(r.charAt(a)),s=r.length>a+1&&r.charAt(a+1)!=="0"||r.length>a+2&&r.charAt(a+2)!=="0"||r.length>a+3&&r.charAt(a+3)!=="0",a){case 0:t!==0&&(e=this._digitCharacters[t]+e);break;case 1:case 2:case 3:t!==0&&(t===1?e=this._myriadCharacters[a-1]+e:e=this._digitCharacters[t]+this._myriadCharacters[a-1]+e);break;case 4:t!==0?e=this._digitCharacters[t]+this._myriadCharacters[a-1]+e:s&&(e=this._myriadCharacters[Math.trunc(a/4)+2]+e);break;default:a%4===0?t!==0?e=this._digitCharacters[t]+this._myriadCharacters[Math.trunc(a/4)+2]+e:s&&(e=this._myriadCharacters[Math.trunc(a/4)+2]+e):a%4===1&&t!==0?t===1?e=this._myriadCharacters[0]+e:e=this._digitCharacters[t]+this._myriadCharacters[0]+e:a%4===2&&t!==0?t===1?e=this._myriadCharacters[1]+e:e=this._digitCharacters[t]+this._myriadCharacters[1]+e:a%4===3&&t!==0&&(e=this._digitCharacters[t]+this._myriadCharacters[2]+e);break}return e}replaceDigits(r){return r=r.replace(/[0]/g,this._digitCharacters[0]),r=r.replace(/[1]/g,this._digitCharacters[1]),r=r.replace(/[2]/g,this._digitCharacters[2]),r=r.replace(/[3]/g,this._digitCharacters[3]),r=r.replace(/[4]/g,this._digitCharacters[4]),r=r.replace(/[5]/g,this._digitCharacters[5]),r=r.replace(/[6]/g,this._digitCharacters[6]),r=r.replace(/[7]/g,this._digitCharacters[7]),r=r.replace(/[8]/g,this._digitCharacters[8]),r=r.replace(/[9]/g,this._digitCharacters[9]),r}prefix(r){let t="";const e=r?this._negativeSign:this._positiveSign;switch(this._displayOrder){case exports.DisplayOrder.NAME_NUMBER_SIGN_SYMBOL:case exports.DisplayOrder.NAME_NUMBER_SYMBOL_SIGN:this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator);break;case exports.DisplayOrder.NAME_SIGN_NUMBER_SYMBOL:this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),e!==""&&(t+=e+this._signSeparator);break;case exports.DisplayOrder.NAME_SIGN_SYMBOL_NUMBER:this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),e!==""&&(t+=e+this._signSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator);break;case exports.DisplayOrder.NAME_SYMBOL_NUMBER_SIGN:this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator);break;case exports.DisplayOrder.NAME_SYMBOL_SIGN_NUMBER:this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),e!==""&&(t+=e+this._signSeparator);break;case exports.DisplayOrder.SIGN_NAME_NUMBER_SYMBOL:e!==""&&(t+=e+this._signSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator);break;case exports.DisplayOrder.SIGN_NAME_SYMBOL_NUMBER:e!==""&&(t+=e+this._signSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator);break;case exports.DisplayOrder.SIGN_NUMBER_NAME_SYMBOL:case exports.DisplayOrder.SIGN_NUMBER_SYMBOL_NAME:e!==""&&(t+=e+this._signSeparator);break;case exports.DisplayOrder.SIGN_SYMBOL_NAME_NUMBER:e!==""&&(t+=e+this._signSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator);break;case exports.DisplayOrder.SIGN_SYMBOL_NUMBER_NAME:e!==""&&(t+=e+this._signSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator);break;case exports.DisplayOrder.SYMBOL_NAME_NUMBER_SIGN:this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator);break;case exports.DisplayOrder.SYMBOL_NAME_SIGN_NUMBER:this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),e!==""&&(t+=e+this._signSeparator);break;case exports.DisplayOrder.SYMBOL_NUMBER_NAME_SIGN:case exports.DisplayOrder.SYMBOL_NUMBER_SIGN_NAME:this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator);break;case exports.DisplayOrder.SYMBOL_SIGN_NAME_NUMBER:this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),e!==""&&(t+=e+this._signSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator);break;case exports.DisplayOrder.SYMBOL_SIGN_NUMBER_NAME:this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),e!==""&&(t+=e+this._signSeparator);break}return t}suffix(r){let t="";const e=r?this._negativeSign:this._positiveSign;switch(this._displayOrder){case exports.DisplayOrder.NAME_NUMBER_SIGN_SYMBOL:e!==""&&(t+=this._signSeparator+e),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.NAME_NUMBER_SYMBOL_SIGN:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.NAME_SIGN_NUMBER_SYMBOL:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.NAME_SYMBOL_NUMBER_SIGN:e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.NUMBER_NAME_SIGN_SYMBOL:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),e!==""&&(t+=this._signSeparator+e),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.NUMBER_NAME_SYMBOL_SIGN:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.NUMBER_SIGN_NAME_SYMBOL:e!==""&&(t+=this._signSeparator+e),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.NUMBER_SIGN_SYMBOL_NAME:e!==""&&(t+=this._signSeparator+e),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break;case exports.DisplayOrder.NUMBER_SYMBOL_NAME_SIGN:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.NUMBER_SYMBOL_SIGN_NAME:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),e!==""&&(t+=this._signSeparator+e),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break;case exports.DisplayOrder.SIGN_NAME_NUMBER_SYMBOL:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.SIGN_NUMBER_NAME_SYMBOL:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.SIGN_NUMBER_SYMBOL_NAME:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break;case exports.DisplayOrder.SIGN_SYMBOL_NUMBER_NAME:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break;case exports.DisplayOrder.SYMBOL_NAME_NUMBER_SIGN:e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.SYMBOL_NUMBER_NAME_SIGN:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.SYMBOL_NUMBER_SIGN_NAME:e!==""&&(t+=this._signSeparator+e),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break;case exports.DisplayOrder.SYMBOL_SIGN_NUMBER_NAME:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break}return t}formatMyriad(r){if(r.floatingPointPrecision!==0)throw new Error("Only values without decimals are supported for conversion to myriad system.");let t=r.integerPart;if(this._myriadCharacters.length<=4&&t.length!==1&&this._myriadCharacters.length<t.length-1||this._myriadCharacters.length>4&&this._myriadCharacters.length<3+Math.trunc((t.length-1)/4))throw new Error("Not enough characters defined to print myriad string. Use setMyriadCharacters to define more characters.");let e=this.prefix(r.isNegative);if(t.length===1)e+=this._digitCharacters[parseInt(t)];else if(t=t.split("").reverse().join(""),this._myriadMode===exports.MyriadMode.JAPANESE)e+=this.handleJapaneseMyriad(t);else throw new Error("Provided myriad mode not supported.");return e+=this.suffix(r.isNegative),e}format(r){let t=this.prefix(r.isNegative),e=this.replaceDigits(r.integerPart);if(this._groupSize>0&&e.length>this._groupSize&&this._groupSeparator!==""){let s=0;for(let a=Math.trunc((e.length-1)/this._groupSize);a>0;a--)s=e.length-this._groupSize*a,e=e.slice(0,s)+this._groupSeparator+e.slice(s)}return t+=e,r.floatingPointPrecision>0&&(t+=this._decimalSeparator,t+=this.replaceDigits(r.fractionalPart)),t+=this.suffix(r.isNegative),t}set digitCharacters(r){if(r.length!==10)throw new Error("10 digits need to passed as a string array.");for(let t=0;t<r.length;t++)this._digitCharacters[t]=r[t]}set myriadCharacters(r){this._myriadCharacters=r.slice(0)}set symbolSeparator(r){this._symbolSeparator=r}set myriadMode(r){this._myriadMode=r}set currencySymbol(r){this._currencySymbol=r}set positiveSign(r){this._positiveSign=r}set negativeSign(r){this._negativeSign=r}set decimalSeparator(r){this._decimalSeparator=r}set groupSize(r){if(!Number.isInteger(r)||r<0)throw new Error("Size should be a positive integer.");this._groupSize=r}set groupSeparator(r){this._groupSeparator=r}set displayOrder(r){this._displayOrder=r}set signSeparator(r){this._signSeparator=r}set currencyName(r){this._currencyName=r}set nameSeparator(r){this._nameSeparator=r}get currencySymbol(){return this._currencySymbol}get symbolSeparator(){return this._symbolSeparator}get positiveSign(){return this._positiveSign}get negativeSign(){return this._negativeSign}get digitCharacters(){return this._digitCharacters.slice(0)}get myriadMode(){return this._myriadMode}get myriadCharacters(){return this._myriadCharacters.slice(0)}get decimalSeparator(){return this._decimalSeparator}get groupSeparator(){return this._groupSeparator}get groupSize(){return this._groupSize}get displayOrder(){return this._displayOrder}get signSeparator(){return this._signSeparator}get currencyName(){return this._currencyName}get nameSeparator(){return this._nameSeparator}}exports.Money=u,exports.MoneyCalculator=M,exports.MoneyFormatter=b;
"use strict";class u{_isNegative=!1;_integerPart="0";_fractionalPart="0";_floatingPointPrecision=1;static _intRegex=/^\d+$/;constructor(r){this.value=r}set value(r){if(/^-[0]+(?:\.0+)?$/.test(r)&&(r=r.substring(1)),/^-\d+(?:\.\d+)?$/.test(r)?(r=r.substring(1),this._isNegative=!0):this._isNegative=!1,/^\d+\.\d+$/.test(r)){const t=r.split(".");this._integerPart=t[0],this._fractionalPart=t[1],this._floatingPointPrecision=t[1].length}else if(u._intRegex.test(r))this._integerPart=r,this._fractionalPart="",this._floatingPointPrecision=0;else throw new Error("Value does not match valid pattern.")}get value(){let r=(this.isNegative?"-":"")+this._integerPart;return this._floatingPointPrecision!==0&&(r+="."+this._fractionalPart),r}get integerPart(){return this._integerPart}get fractionalPart(){return this._fractionalPart}set integerPart(r){if(!u._intRegex.test(r))throw new Error(`Input number is not a valid positive integer. Received the following value "${r}"`);this._integerPart=r.toString(),this.isNull()&&(this.isNegative=!1)}set fractionalPart(r){if(!u._intRegex.test(r))throw new Error("Input number is not a valid positive integer to represent floating point numbers.");this._fractionalPart=r.toString(),this._floatingPointPrecision=r.length,this.isNull()&&(this._isNegative=!1)}get floatingPointPrecision(){return this._floatingPointPrecision}get isNegative(){return this._isNegative}set isNegative(r){this.isNull()||(this._isNegative=r)}isNull(){return/^[0]+$/.test(this._integerPart)&&/^[0]*$/.test(this._fractionalPart)}}class M{static addDigits(r,t,e){if(!/^\d$/.test(r)||!/^\d$/.test(t))throw new Error("Strings need to be single ascii digits.");let s=parseInt(r)+parseInt(t)+(e?1:0),a=s.toString();return[a.length===1?a:a.charAt(1),s>=10]}static min(r,t){const e=M.max(r,t);return e!==M.max(t,r)||e===t?r:t}static max(r,t){const e=r.integerPart,s=t.integerPart;if(r.isNegative&&!t.isNegative)return t;if(!r.isNegative&&t.isNegative)return r;{const a=r.isNegative&&t.isNegative;if(e.length>s.length)return a?t:r;if(e.length<s.length)return a?r:t;{for(let _=0;_<e.length;_++){let n=parseInt(e.charAt(_)),o=parseInt(s.charAt(_));if(n>o)return a?t:r;if(o>n)return a?r:t}const g=r.fractionalPart,p=t.fractionalPart;for(let _=0;_<Math.max(g.length,p.length);_++){let n=g.length>_?parseInt(g.charAt(_)):0,o=p.length>_?parseInt(p.charAt(_)):0;if(n>o)return a?t:r;if(o>n)return a?r:t}}}return r}static add(r,t){const e=r.floatingPointPrecision;if(e!==t.floatingPointPrecision)throw new Error("Amounts to add need to have the same floating point precision.");let s="",a="";const g=r.isNegative&&!t.isNegative,p=!r.isNegative&&t.isNegative;if(g||p){let _=!1;const n=r.isNegative,o=t.isNegative;r.isNegative=!1,t.isNegative=!1;const h=M.max(r,t),c=h===r?t:r;r.isNegative=n,t.isNegative=o;let S="",N="",y="";for(let l=e>0?0:1;l<2;l++){let d=l===0?h.fractionalPart:h.integerPart,m=l===0?c.fractionalPart:c.integerPart;l===1&&d.length>m.length&&(m="0".repeat(d.length-m.length)+m);for(let E=d.length-1;E>=0;E--){S=d.charAt(E),N=m.charAt(E);const B=parseInt(S),O=parseInt(N)+(_?1:0);B>=O?(y=(B-O).toString(),_=!1):(y=(10-(O-B)).toString(),_=!0),l===0?a=y+a:s=y+s}l===0&&(r.fractionalPart=a)}r.integerPart=/^0+$/.test(s)?"0":s.replace(/^0+/,""),r.isNegative=h.isNegative}else{let _=r.integerPart,n=t.integerPart;const o=Math.max(_.length,n.length);_=_.split("").reverse().join(""),n=n.split("").reverse().join("");let h=!1;if(e>0){const c=r.fractionalPart,S=t.fractionalPart;for(let N=e-1;N>=0;N--){const y=M.addDigits(c.charAt(N),S.charAt(N),h);h=y[1],a=y[0]+a}r.fractionalPart=a}for(let c=0;c<o;c++){const S=M.addDigits(c<_.length?_.charAt(c):"0",c<n.length?n.charAt(c):"0",h);h=S[1],s=S[0]+s}h&&(s="1"+s),r.integerPart=s}return r}static subtract(r,t){const e=t.isNegative;t.isNegative=!e;try{this.add(r,t)}catch(s){throw t.isNegative=e,s}return t.isNegative=e,r}}exports.DisplayOrder=void 0,function(i){i[i.SIGN_SYMBOL_NAME_NUMBER=0]="SIGN_SYMBOL_NAME_NUMBER",i[i.SIGN_NAME_SYMBOL_NUMBER=1]="SIGN_NAME_SYMBOL_NUMBER",i[i.SIGN_SYMBOL_NUMBER_NAME=2]="SIGN_SYMBOL_NUMBER_NAME",i[i.SIGN_NAME_NUMBER_SYMBOL=3]="SIGN_NAME_NUMBER_SYMBOL",i[i.SIGN_NUMBER_SYMBOL_NAME=4]="SIGN_NUMBER_SYMBOL_NAME",i[i.SIGN_NUMBER_NAME_SYMBOL=5]="SIGN_NUMBER_NAME_SYMBOL",i[i.SYMBOL_SIGN_NAME_NUMBER=6]="SYMBOL_SIGN_NAME_NUMBER",i[i.SYMBOL_NAME_SIGN_NUMBER=7]="SYMBOL_NAME_SIGN_NUMBER",i[i.SYMBOL_SIGN_NUMBER_NAME=8]="SYMBOL_SIGN_NUMBER_NAME",i[i.SYMBOL_NAME_NUMBER_SIGN=9]="SYMBOL_NAME_NUMBER_SIGN",i[i.SYMBOL_NUMBER_SIGN_NAME=10]="SYMBOL_NUMBER_SIGN_NAME",i[i.SYMBOL_NUMBER_NAME_SIGN=11]="SYMBOL_NUMBER_NAME_SIGN",i[i.NAME_SIGN_SYMBOL_NUMBER=12]="NAME_SIGN_SYMBOL_NUMBER",i[i.NAME_SYMBOL_SIGN_NUMBER=13]="NAME_SYMBOL_SIGN_NUMBER",i[i.NAME_SIGN_NUMBER_SYMBOL=14]="NAME_SIGN_NUMBER_SYMBOL",i[i.NAME_SYMBOL_NUMBER_SIGN=15]="NAME_SYMBOL_NUMBER_SIGN",i[i.NAME_NUMBER_SIGN_SYMBOL=16]="NAME_NUMBER_SIGN_SYMBOL",i[i.NAME_NUMBER_SYMBOL_SIGN=17]="NAME_NUMBER_SYMBOL_SIGN",i[i.NUMBER_NAME_SYMBOL_SIGN=18]="NUMBER_NAME_SYMBOL_SIGN",i[i.NUMBER_NAME_SIGN_SYMBOL=19]="NUMBER_NAME_SIGN_SYMBOL",i[i.NUMBER_SIGN_NAME_SYMBOL=20]="NUMBER_SIGN_NAME_SYMBOL",i[i.NUMBER_SIGN_SYMBOL_NAME=21]="NUMBER_SIGN_SYMBOL_NAME",i[i.NUMBER_SYMBOL_NAME_SIGN=22]="NUMBER_SYMBOL_NAME_SIGN",i[i.NUMBER_SYMBOL_SIGN_NAME=23]="NUMBER_SYMBOL_SIGN_NAME"}(exports.DisplayOrder||(exports.DisplayOrder={})),exports.MyriadMode=void 0,function(i){i[i.JAPANESE=0]="JAPANESE",i[i.CHINESE=1]="CHINESE"}(exports.MyriadMode||(exports.MyriadMode={}));class b{_currencySymbol="$";_symbolSeparator="";_currencyName="";_nameSeparator=" ";_positiveSign="";_negativeSign="-";_signSeparator="";_displayOrder=exports.DisplayOrder.SIGN_SYMBOL_NUMBER_NAME;_digitCharacters=["0","1","2","3","4","5","6","7","8","9"];_myriadMode=exports.MyriadMode.JAPANESE;_myriadCharacters=["\u5341","\u767E","\u5343","\u4E07","\u5104","\u5146","\u4EAC","\u5793","\u{25771}","\u7A63","\u6E9D","\u6F97","\u6B63","\u8F09"];_decimalSeparator=".";_groupSeparator=",";_groupSize=3;constructor(r){typeof r.currencySymbol=="string"&&(this.currencySymbol=r.currencySymbol),typeof r.symbolSeparator=="string"&&(this.symbolSeparator=r.symbolSeparator),typeof r.currencyName=="string"&&(this.currencyName=r.currencyName),typeof r.nameSeparator=="string"&&(this.nameSeparator=r.nameSeparator),typeof r.positiveSign=="string"&&(this.positiveSign=r.positiveSign),typeof r.negativeSign=="string"&&(this.negativeSign=r.negativeSign),typeof r.signSeparator=="string"&&(this.signSeparator=r.signSeparator),typeof r.displayOrder<"u"&&typeof r.displayOrder==typeof exports.DisplayOrder.SIGN_NUMBER_SYMBOL_NAME&&(this.displayOrder=r.displayOrder),typeof r.myriadMode<"u"&&typeof r.myriadMode==typeof exports.MyriadMode.JAPANESE&&(this.myriadMode=r.myriadMode),typeof r.digitCharacters=="object"&&(this.digitCharacters=r.digitCharacters),typeof r.myriadCharacters=="object"&&(this.myriadCharacters=r.myriadCharacters),typeof r.groupSeparator=="string"&&(this.groupSeparator=r.groupSeparator),typeof r.decimalSeparator=="string"&&(this.decimalSeparator=r.decimalSeparator),typeof r.groupSize=="number"&&(this.groupSize=r.groupSize)}handleJapaneseMyriad(r){let t=0,e="",s=!1;for(let a=0;a<r.length;a++)switch(t=parseInt(r.charAt(a)),s=r.length>a+1&&r.charAt(a+1)!=="0"||r.length>a+2&&r.charAt(a+2)!=="0"||r.length>a+3&&r.charAt(a+3)!=="0",a){case 0:t!==0&&(e=this._digitCharacters[t]+e);break;case 1:case 2:case 3:t!==0&&(t===1?e=this._myriadCharacters[a-1]+e:e=this._digitCharacters[t]+this._myriadCharacters[a-1]+e);break;case 4:t!==0?e=this._digitCharacters[t]+this._myriadCharacters[a-1]+e:s&&(e=this._myriadCharacters[Math.trunc(a/4)+2]+e);break;default:a%4===0?t!==0?e=this._digitCharacters[t]+this._myriadCharacters[Math.trunc(a/4)+2]+e:s&&(e=this._myriadCharacters[Math.trunc(a/4)+2]+e):a%4===1&&t!==0?t===1?e=this._myriadCharacters[0]+e:e=this._digitCharacters[t]+this._myriadCharacters[0]+e:a%4===2&&t!==0?t===1?e=this._myriadCharacters[1]+e:e=this._digitCharacters[t]+this._myriadCharacters[1]+e:a%4===3&&t!==0&&(e=this._digitCharacters[t]+this._myriadCharacters[2]+e);break}return e}replaceDigits(r){return r=r.replace(/[0]/g,this._digitCharacters[0]),r=r.replace(/[1]/g,this._digitCharacters[1]),r=r.replace(/[2]/g,this._digitCharacters[2]),r=r.replace(/[3]/g,this._digitCharacters[3]),r=r.replace(/[4]/g,this._digitCharacters[4]),r=r.replace(/[5]/g,this._digitCharacters[5]),r=r.replace(/[6]/g,this._digitCharacters[6]),r=r.replace(/[7]/g,this._digitCharacters[7]),r=r.replace(/[8]/g,this._digitCharacters[8]),r=r.replace(/[9]/g,this._digitCharacters[9]),r}prefix(r){let t="";const e=r?this._negativeSign:this._positiveSign;switch(this._displayOrder){case exports.DisplayOrder.NAME_NUMBER_SIGN_SYMBOL:case exports.DisplayOrder.NAME_NUMBER_SYMBOL_SIGN:this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator);break;case exports.DisplayOrder.NAME_SIGN_NUMBER_SYMBOL:this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),e!==""&&(t+=e+this._signSeparator);break;case exports.DisplayOrder.NAME_SIGN_SYMBOL_NUMBER:this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),e!==""&&(t+=e+this._signSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator);break;case exports.DisplayOrder.NAME_SYMBOL_NUMBER_SIGN:this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator);break;case exports.DisplayOrder.NAME_SYMBOL_SIGN_NUMBER:this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),e!==""&&(t+=e+this._signSeparator);break;case exports.DisplayOrder.SIGN_NAME_NUMBER_SYMBOL:e!==""&&(t+=e+this._signSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator);break;case exports.DisplayOrder.SIGN_NAME_SYMBOL_NUMBER:e!==""&&(t+=e+this._signSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator);break;case exports.DisplayOrder.SIGN_NUMBER_NAME_SYMBOL:case exports.DisplayOrder.SIGN_NUMBER_SYMBOL_NAME:e!==""&&(t+=e+this._signSeparator);break;case exports.DisplayOrder.SIGN_SYMBOL_NAME_NUMBER:e!==""&&(t+=e+this._signSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator);break;case exports.DisplayOrder.SIGN_SYMBOL_NUMBER_NAME:e!==""&&(t+=e+this._signSeparator),this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator);break;case exports.DisplayOrder.SYMBOL_NAME_NUMBER_SIGN:this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator);break;case exports.DisplayOrder.SYMBOL_NAME_SIGN_NUMBER:this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator),e!==""&&(t+=e+this._signSeparator);break;case exports.DisplayOrder.SYMBOL_NUMBER_NAME_SIGN:case exports.DisplayOrder.SYMBOL_NUMBER_SIGN_NAME:this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator);break;case exports.DisplayOrder.SYMBOL_SIGN_NAME_NUMBER:this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),e!==""&&(t+=e+this._signSeparator),this._currencyName!==""&&(t+=this._currencyName+this._nameSeparator);break;case exports.DisplayOrder.SYMBOL_SIGN_NUMBER_NAME:this._currencySymbol!==""&&(t+=this._currencySymbol+this._symbolSeparator),e!==""&&(t+=e+this._signSeparator);break}return t}suffix(r){let t="";const e=r?this._negativeSign:this._positiveSign;switch(this._displayOrder){case exports.DisplayOrder.NAME_NUMBER_SIGN_SYMBOL:e!==""&&(t+=this._signSeparator+e),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.NAME_NUMBER_SYMBOL_SIGN:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.NAME_SIGN_NUMBER_SYMBOL:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.NAME_SYMBOL_NUMBER_SIGN:e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.NUMBER_NAME_SIGN_SYMBOL:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),e!==""&&(t+=this._signSeparator+e),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.NUMBER_NAME_SYMBOL_SIGN:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.NUMBER_SIGN_NAME_SYMBOL:e!==""&&(t+=this._signSeparator+e),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.NUMBER_SIGN_SYMBOL_NAME:e!==""&&(t+=this._signSeparator+e),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break;case exports.DisplayOrder.NUMBER_SYMBOL_NAME_SIGN:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.NUMBER_SYMBOL_SIGN_NAME:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),e!==""&&(t+=this._signSeparator+e),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break;case exports.DisplayOrder.SIGN_NAME_NUMBER_SYMBOL:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.SIGN_NUMBER_NAME_SYMBOL:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol);break;case exports.DisplayOrder.SIGN_NUMBER_SYMBOL_NAME:this._currencySymbol!==""&&(t+=this._symbolSeparator+this._currencySymbol),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break;case exports.DisplayOrder.SIGN_SYMBOL_NUMBER_NAME:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break;case exports.DisplayOrder.SYMBOL_NAME_NUMBER_SIGN:e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.SYMBOL_NUMBER_NAME_SIGN:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName),e!==""&&(t+=this._signSeparator+e);break;case exports.DisplayOrder.SYMBOL_NUMBER_SIGN_NAME:e!==""&&(t+=this._signSeparator+e),this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break;case exports.DisplayOrder.SYMBOL_SIGN_NUMBER_NAME:this._currencyName!==""&&(t+=this._nameSeparator+this._currencyName);break}return t}formatMyriad(r){if(r.floatingPointPrecision!==0)throw new Error("Only values without decimals are supported for conversion to myriad system.");let t=r.integerPart;if(this._myriadCharacters.length<=4&&t.length!==1&&this._myriadCharacters.length<t.length-1||this._myriadCharacters.length>4&&this._myriadCharacters.length<3+Math.trunc((t.length-1)/4))throw new Error("Not enough characters defined to print myriad string. Use setMyriadCharacters to define more characters.");let e=this.prefix(r.isNegative);if(t.length===1)e+=this._digitCharacters[parseInt(t)];else if(t=t.split("").reverse().join(""),this._myriadMode===exports.MyriadMode.JAPANESE)e+=this.handleJapaneseMyriad(t);else throw new Error("Provided myriad mode not supported.");return e+=this.suffix(r.isNegative),e}format(r){let t=this.prefix(r.isNegative),e=this.replaceDigits(r.integerPart);if(this._groupSize>0&&e.length>this._groupSize&&this._groupSeparator!==""){let s=0;for(let a=Math.trunc((e.length-1)/this._groupSize);a>0;a--)s=e.length-this._groupSize*a,e=e.slice(0,s)+this._groupSeparator+e.slice(s)}return t+=e,r.floatingPointPrecision>0&&(t+=this._decimalSeparator,t+=this.replaceDigits(r.fractionalPart)),t+=this.suffix(r.isNegative),t}set digitCharacters(r){if(r.length!==10)throw new Error("10 digits need to passed as a string array.");for(let t=0;t<r.length;t++)this._digitCharacters[t]=r[t]}set myriadCharacters(r){this._myriadCharacters=r.slice(0)}set symbolSeparator(r){this._symbolSeparator=r}set myriadMode(r){this._myriadMode=r}set currencySymbol(r){this._currencySymbol=r}set positiveSign(r){this._positiveSign=r}set negativeSign(r){this._negativeSign=r}set decimalSeparator(r){this._decimalSeparator=r}set groupSize(r){if(!Number.isInteger(r)||r<0)throw new Error("Size should be a positive integer.");this._groupSize=r}set groupSeparator(r){this._groupSeparator=r}set displayOrder(r){this._displayOrder=r}set signSeparator(r){this._signSeparator=r}set currencyName(r){this._currencyName=r}set nameSeparator(r){this._nameSeparator=r}get currencySymbol(){return this._currencySymbol}get symbolSeparator(){return this._symbolSeparator}get positiveSign(){return this._positiveSign}get negativeSign(){return this._negativeSign}get digitCharacters(){return this._digitCharacters.slice(0)}get myriadMode(){return this._myriadMode}get myriadCharacters(){return this._myriadCharacters.slice(0)}get decimalSeparator(){return this._decimalSeparator}get groupSeparator(){return this._groupSeparator}get groupSize(){return this._groupSize}get displayOrder(){return this._displayOrder}get signSeparator(){return this._signSeparator}get currencyName(){return this._currencyName}get nameSeparator(){return this._nameSeparator}}exports.Money=u,exports.MoneyCalculator=M,exports.MoneyFormatter=b;
//# sourceMappingURL=index.js.map
{
"name": "moneydew",
"version": "1.0.0",
"version": "1.0.1",
"description": "This is a library for formatting currencies designed for frontend applications. Also has arithmetic capabilities. Arithmetic implementation is slow and not designed for large-scale backend applications.",

@@ -5,0 +5,0 @@ "main": "index.js",

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

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