UNPKG

@julo-ui/number-utils

Version:

Number Utilities across Julo UI package

44 lines (42 loc) 1.63 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/thousand-separator.ts var thousand_separator_exports = {}; __export(thousand_separator_exports, { default: () => thousand_separator_default }); module.exports = __toCommonJS(thousand_separator_exports); function thousandSeparator(value, options = {}) { const { separator = ".", isReturnEmptyStringOnEmptyValue } = options; if (!value) { return isReturnEmptyStringOnEmptyValue ? "" : "0"; } const num = value.toString().replace(/\D/g, ""); if (num === "") { return isReturnEmptyStringOnEmptyValue ? "" : "0"; } if (num.length <= 3) { return num; } const result = num.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, `$1${separator}`); return result; } var thousand_separator_default = thousandSeparator; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = {});