1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var numStrict = require('@typen/num-strict');
|
6 |
|
7 | class Mag {
|
8 | constructor(digit = 2, sep = 3) {
|
9 | this.dg = digit;
|
10 | this.reg = new RegExp(`\\d(?=(\\d{${sep || 3}})+${digit > 0 ? '\\.' : '$'})`, 'g');
|
11 | }
|
12 |
|
13 | static build(digit, sep) {
|
14 | return new Mag(digit, sep);
|
15 | }
|
16 |
|
17 | parse(any) {
|
18 | return numStrict.isNumeric(any) ? this.format(any) : String(any);
|
19 | }
|
20 |
|
21 | format(num) {
|
22 | return num.toFixed(this.dg).replace(this.reg, '$&,');
|
23 | }
|
24 |
|
25 | }
|
26 |
|
27 | exports.Mag = Mag;
|