format-money-js
Advanced tools
Comparing version 1.1.6 to 1.2.0
/*! | ||
* format-money-js v1.1.6 | ||
* format-money-js v1.2.0 | ||
* (c) 2020 Yurii Derevych | ||
@@ -11,4 +11,4 @@ * Released under the BSD-2-Clause License. | ||
decimals?: number; | ||
prefix?: string; | ||
suffix?: string; | ||
symbol?: string; | ||
append?: boolean; | ||
} | ||
@@ -15,0 +15,0 @@ export declare class FormatMoney { |
"use strict"; | ||
/*! | ||
* format-money-js v1.1.6 | ||
* format-money-js v1.2.0 | ||
* (c) 2020 Yurii Derevych | ||
@@ -11,3 +11,3 @@ * Released under the BSD-2-Clause License. | ||
this.options = options; | ||
this.version = '1.1.6'; | ||
this.version = '1.2.0'; | ||
this.defaults = { | ||
@@ -18,4 +18,4 @@ grouping: true, | ||
decimals: 0, | ||
prefix: '', | ||
suffix: '' | ||
symbol: '', | ||
append: false | ||
}; | ||
@@ -25,3 +25,3 @@ this.from = (num, options) => { | ||
const neg = (num < 0) ? '-' : ''; | ||
let result, x, x1, x2, x3; | ||
let result, x, x1, x2, x3, prefix, suffix; | ||
result = Math.abs(num).toFixed(options.decimals); | ||
@@ -42,3 +42,10 @@ result += ''; | ||
} | ||
return neg + options.prefix + x1 + x2 + options.suffix; | ||
prefix = suffix = ''; | ||
if (options.append) { | ||
suffix = options.symbol; | ||
} | ||
else { | ||
prefix = options.symbol; | ||
} | ||
return neg + prefix + x1 + x2 + suffix; | ||
}; | ||
@@ -45,0 +52,0 @@ this.options = Object.assign(Object.assign({}, this.defaults), options); |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class FormatMoney{constructor(t){this.options=t,this.version="1.1.6",this.defaults={grouping:!0,separator:",",decimalPoint:".",decimals:0,prefix:"",suffix:""},this.from=((t,s)=>{s=Object.assign(Object.assign({},this.options),s);const e=t<0?"-":"";let i,o,r,a,n;if(i=Math.abs(t).toFixed(s.decimals),r=(o=(i+="").split("."))[0],a=o.length>1?s.decimalPoint+o[1]:"",s.grouping){n="";for(let t=0,e=r.length;t<e;++t)0!==t&&t%3==0&&(n=s.separator+n),n=r[e-t-1]+n;r=n}return e+s.prefix+r+a+s.suffix}),this.options=Object.assign(Object.assign({},this.defaults),t)}}exports.FormatMoney=FormatMoney; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class FormatMoney{constructor(t){this.options=t,this.version="1.2.0",this.defaults={grouping:!0,separator:",",decimalPoint:".",decimals:0,symbol:"",append:!1},this.from=((t,s)=>{s=Object.assign(Object.assign({},this.options),s);const e=t<0?"-":"";let o,i,a,n,r,l,p;if(o=Math.abs(t).toFixed(s.decimals),a=(i=(o+="").split("."))[0],n=i.length>1?s.decimalPoint+i[1]:"",s.grouping){r="";for(let t=0,e=a.length;t<e;++t)0!==t&&t%3==0&&(r=s.separator+r),r=a[e-t-1]+r;a=r}return l=p="",s.append?p=s.symbol:l=s.symbol,e+l+a+n+p}),this.options=Object.assign(Object.assign({},this.defaults),t)}}exports.FormatMoney=FormatMoney; |
@@ -7,8 +7,14 @@ const { FormatMoney } = require('./dist/format-money.js'); | ||
console.log(fm1.from(12345.67, { prefix: '$' })); // $12,345.67 | ||
console.log(fm1.from(12345.67, { symbol: '$' })); // $12,345.67 | ||
// | ||
const fm2 = new FormatMoney({ prefix: '$' }); | ||
const fm2 = new FormatMoney({ symbol: '$' }); | ||
console.log(fm2.from(12345.67, { prefix: '€' })); // €12,345.67 | ||
console.log(fm2.from(12345.67, { symbol: '€' })); // €12,345.67 | ||
// | ||
const fm3 = new FormatMoney({ symbol: '$' }); | ||
console.log(fm2.from(12345.67, { append: true })); // 12,345.67$ |
{ | ||
"name": "format-money-js", | ||
"description": "Tiny JavaScript library (656 bytes) by CurrencyRate.today, providing simple and advanced number, money and currency formatting.", | ||
"version": "1.1.6", | ||
"description": "Tiny JavaScript library (684 bytes) by CurrencyRate.today, providing simple and advanced number, money and currency formatting.", | ||
"version": "1.2.0", | ||
"license": "BSD-2-Clause", | ||
@@ -6,0 +6,0 @@ "main": "./dist/format-money.js", |
@@ -7,3 +7,3 @@ # format-money-js | ||
Tiny JavaScript library (656 bytes) by CurrencyRate.today, providing simple and advanced number, money and currency formatting. | ||
Tiny JavaScript library (684 bytes) by CurrencyRate.today, providing simple and advanced number, money and currency formatting. | ||
@@ -19,3 +19,3 @@ ## Example | ||
console.log(fm.from(12345.67, { prefix: '$' })); // $12,345.67 | ||
console.log(fm.from(12345.67, { symbol: '$' })); // $12,345.67 | ||
``` | ||
@@ -28,5 +28,5 @@ | ||
``` | ||
const fm = new FormatMoney({ prefix: '$' }); | ||
const fm = new FormatMoney({ symbol: '$' }); | ||
console.log(fm.from(12345.67, { prefix: '€' })); // €12,345.67 | ||
console.log(fm.from(12345.67, { symbol: '€' })); // €12,345.67 | ||
``` | ||
@@ -40,4 +40,4 @@ | ||
| decimals | 0 | Number | 1,234 (0 - without decimals) | | ||
| prefix | None | String | $1,234.56 (before) | | ||
| suffix | None | String | 1,234.56$ (after) | | ||
| symbol | None | String | $1,234.56 (if append false) | | ||
| append | false | String | 1,234.56$ (if append true) | | ||
@@ -44,0 +44,0 @@ ## Source |
/*! | ||
* format-money-js v1.1.6 | ||
* format-money-js v1.2.0 | ||
* (c) 2020 Yurii Derevych | ||
@@ -12,4 +12,4 @@ * Released under the BSD-2-Clause License. | ||
decimals?: number; // Sets the number of decimal points. | ||
prefix?: string; // Text prepended to result | ||
suffix?: string; // Text appended to result | ||
symbol?: string; | ||
append?: boolean; | ||
} | ||
@@ -19,3 +19,3 @@ | ||
version = '1.1.6'; | ||
version = '1.2.0'; | ||
private defaults: FormatMoneyOptions = { | ||
@@ -26,4 +26,4 @@ grouping: true, | ||
decimals: 0, | ||
prefix: '', | ||
suffix: '' | ||
symbol: '', | ||
append: false | ||
}; | ||
@@ -50,3 +50,5 @@ | ||
x2: string, | ||
x3: string; | ||
x3: string, | ||
prefix: string, | ||
suffix: string; | ||
result = Math.abs(num).toFixed(options.decimals); | ||
@@ -67,5 +69,13 @@ result += ''; | ||
} | ||
return neg + options.prefix + x1 + x2 + options.suffix; | ||
prefix = suffix = ''; | ||
if (options.append) { | ||
suffix = options.symbol; | ||
} | ||
else { | ||
prefix = options.symbol; | ||
} | ||
return neg + prefix + x1 + x2 + suffix; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14828
324