UNPKG

newmax-utils

Version:
18 lines (17 loc) 578 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.thousandsSeparator = void 0; function thousandsSeparator(value, d = 2) { const str = value.toFixed(d).replace(/\s+/g, ''); if (str.includes('.')) { const [wholePart, fractionalPart] = str.split('.'); return `${formatWholePart(wholePart)}.${fractionalPart}`; } else { return formatWholePart(str); } } exports.thousandsSeparator = thousandsSeparator; function formatWholePart(wholePart) { return wholePart.replace(/\B(?=(\d{3})+(?!\d))/g, ' '); }