@nexim/financial-calculate
Version:
Provides a set of utils to handle common financial operations.
8 lines (7 loc) • 3.71 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/main.ts"],
"sourcesContent": ["import { packageTracer } from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Calculate the price after applying a discount.\n *\n * @param price - The original price.\n * @param discount - The discount percentage to apply.\n * @param decimal - The number of decimal places to round to (default is 2).\n *\n * @example\n * ```ts\n * calculateDiscountedPrice(100, 10, 1); // returns 90.0\n * ```\n */\nexport function calculateDiscountedPrice(price: number, discount: number, decimal = 2): number {\n // logger.logMethodArgs?.('calculateDiscountedPrice', { price, discount, decimal });\n\n const discountedPrice = price * (1 - discount / 100);\n return parseFloat(discountedPrice.toFixed(decimal));\n}\n\n/**\n * Calculate the discount amount from the original price.\n *\n * @param price - The original price.\n * @param discount - The discount percentage.\n * @param decimal - The number of decimal places to round to (default is 2).\n *\n * @example\n * ```ts\n * calculateDiscountAmount(100, 10, 1); // returns 10.0\n * ```\n */\nexport function calculateDiscountAmount(price: number, discount: number, decimal = 2): number {\n // logger.logMethodArgs?.('calculateDiscountAmount', { price, discount, decimal });\n\n const discountAmount = (price * discount) / 100;\n return parseFloat(discountAmount.toFixed(decimal));\n}\n\n/**\n * Calculates the discount percentage between the market price and the sale price for profit.\n *\n * @param marketPrice - The original market price of the item.\n * @param salePrice - The sale price of the item.\n * @param decimal - The number of decimal places to round the result to(optional with default value = 2).\n *\n * @example\n * ```ts\n * calculatePercentageProfit(100, 80); // Returns 20.00\n * calculatePercentageProfit(100, 80, 1, false); // Returns 25.0\n * ```\n */\nexport function calculatePercentageProfit(marketPrice: number, salePrice: number, decimal = 2): number {\n // logger.logMethodArgs?.('calculatePercentageProfit', { marketPrice, salePrice, decimal });\n\n const percentage = ((marketPrice - salePrice) / salePrice) * 100;\n return parseFloat(percentage.toFixed(decimal));\n}\n\n/**\n * Calculates the discount percentage between the market price and the sale price for discount.\n *\n * @param marketPrice - The original market price of the item.\n * @param salePrice - The sale price of the item.\n * @param decimal - The number of decimal places to round the result to(optional with default value = 2).\n *\n * @example\n * ```ts\n * calculatePercentageDiscount(100, 80); // Returns 20.00\n * calculatePercentageDiscount(100, 80, 1, false); // Returns 25.0\n * ```\n */\nexport function calculatePercentageDiscount(marketPrice: number, salePrice: number, decimal = 2): number {\n // logger.logMethodArgs?.('calculatePercentageDiscount', { marketPrice, salePrice, decimal });\n\n const percentage = ((marketPrice - salePrice) / marketPrice) * 100;\n return parseFloat(percentage.toFixed(decimal));\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA8B;AAE9B,aAAc,qCAAc,IAAI,8BAAkB,OAAmB;AAc9D,SAAS,yBAAyB,OAAe,UAAkB,UAAU,GAAW;AAG7F,QAAM,kBAAkB,SAAS,IAAI,WAAW;AAChD,SAAO,WAAW,gBAAgB,QAAQ,OAAO,CAAC;AACpD;AAcO,SAAS,wBAAwB,OAAe,UAAkB,UAAU,GAAW;AAG5F,QAAM,iBAAkB,QAAQ,WAAY;AAC5C,SAAO,WAAW,eAAe,QAAQ,OAAO,CAAC;AACnD;AAeO,SAAS,0BAA0B,aAAqB,WAAmB,UAAU,GAAW;AAGrG,QAAM,cAAe,cAAc,aAAa,YAAa;AAC7D,SAAO,WAAW,WAAW,QAAQ,OAAO,CAAC;AAC/C;AAeO,SAAS,4BAA4B,aAAqB,WAAmB,UAAU,GAAW;AAGvG,QAAM,cAAe,cAAc,aAAa,cAAe;AAC/D,SAAO,WAAW,WAAW,QAAQ,OAAO,CAAC;AAC/C;",
"names": []
}