1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.formatDecimal = void 0;
|
4 | const NUMBER_REGEX = new RegExp('(\\d+?)(?=(\\d{3})+(?!\\d)|$)', 'g');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function formatDecimal(value, separator = ',') {
|
10 |
|
11 |
|
12 | const isNegative = value[0].startsWith('-');
|
13 | const matched = isNegative
|
14 | ? value.substring(1).match(NUMBER_REGEX)
|
15 | : value.match(NUMBER_REGEX);
|
16 | return matched
|
17 | ? `${isNegative ? '-' : ''}${matched.join(separator)}`
|
18 | : value;
|
19 | }
|
20 | exports.formatDecimal = formatDecimal;
|