"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/index.ts var src_exports = {}; __export(src_exports, { calculatePercent: () => calculatePercent, getNumberOfDecimalPlaces: () => getNumberOfDecimalPlaces, getPercent: () => getPercent, getPercentGrowth: () => getPercentGrowth, roundCurrency: () => roundCurrency, roundNumberToDigits: () => roundNumberToDigits }); module.exports = __toCommonJS(src_exports); // src/get-number-of-decimal-places/get-number-of-decimal-places.ts function getNumberOfDecimalPlaces(input) { if (input == null || isNaN(Number(input))) { return 0; } const numberString = String(input); const decimalPart = numberString.split(".")[1]; return decimalPart ? decimalPart.length : 0; } // src/round-number-to-digits/round-number-to-digits.ts function roundNumberToDigits(number, precision) { if (number == null || isNaN(number)) { return NaN; } if (precision == null) { return number; } const numStr = number + "e" + precision; const roundedStr = Math.round(Number(numStr)) + "e-" + precision; const result = Number(roundedStr); return result; } // src/calculate-percent/calculate-percent.ts function calculatePercent(amount, percent) { const amountNum = parseFloat(String(amount)); const percentNum = parseFloat(String(percent)); if (isNaN(amountNum) || isNaN(percentNum)) { return NaN; } const result = amountNum * percentNum / 100; const amountDecimals = getNumberOfDecimalPlaces(amountNum); const percentDecimals = getNumberOfDecimalPlaces(percentNum); const totalDecimals = amountDecimals + percentDecimals + 2; return roundNumberToDigits(result, totalDecimals); } // src/get-percent/get-percent.ts function getPercent(numerator, denominator, precision = 2) { const num = parseFloat(String(numerator)); const den = parseFloat(String(denominator)); if (isNaN(num) || isNaN(den) || den === 0) { return NaN; } const percent = num / den * 100; return roundNumberToDigits(percent, precision); } // src/get-percent-growth/get-percent-growth.ts function getPercentGrowth(oldValue, newValue, precision = 2) { const oldNum = parseFloat(String(oldValue)); const newNum = parseFloat(String(newValue)); if (isNaN(oldNum) || isNaN(newNum) || oldNum === 0) { return NaN; } const growth = newNum - oldNum; return getPercent(growth, oldNum, precision); } // src/round-currency/round-currency.ts function roundCurrency(amount) { if (amount == null || isNaN(amount)) { return NaN; } return roundNumberToDigits(amount, 2); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { calculatePercent, getNumberOfDecimalPlaces, getPercent, getPercentGrowth, roundCurrency, roundNumberToDigits });