Installation
npm install moneyutils-inCurrency
Format INR amounts and convert between rupees and paise.
formatINR
formatINR(amount: number, options?: FormatINROptions): stringFormats a number as Indian Rupees with lakh-style grouping. Options: decimals (default 2), symbol (default true).
Returns: Formatted INR string
formatINR(125000);
// "₹1,25,000.00"
formatINR(125000, { decimals: 0, symbol: false });
// "1,25,000"rupeesToPaise
rupeesToPaise(rupees: number): numberConverts rupees to paise as an integer. Useful for payment gateways that expect amounts in paise.
Returns: Integer paise value
rupeesToPaise(499.99);
// 49999paiseToRupees
paiseToRupees(paise: number): numberConverts paise back to rupees.
Returns: Rupees as a number
paiseToRupees(49999);
// 499.99GST
Add or remove GST with CGST/SGST for intra-state or IGST for inter-state transactions. Transaction type defaults to INTRA_STATE.
addGST
addGST(amount: number, gstRate: number, transactionType?: GSTTransactionType): GSTResultAdds GST to a taxable amount. Intra-state splits tax into CGST and SGST; inter-state uses IGST.
Returns: GSTResult — taxableAmount, cgst, sgst, igst, totalTax, totalAmount
addGST(1000, 18);
// { taxableAmount: 1000, gstRate: 18, cgst: 90, sgst: 90, igst: 0, totalTax: 180, totalAmount: 1180 }
addGST(1000, 18, "INTER_STATE");
// { taxableAmount: 1000, gstRate: 18, cgst: 0, sgst: 0, igst: 180, totalTax: 180, totalAmount: 1180 }removeGST
removeGST(inclusiveAmount: number, gstRate: number, transactionType?: GSTTransactionType): GSTResultExtracts the taxable base and tax components from a GST-inclusive price.
Returns: GSTResult
removeGST(1180, 18);
// { taxableAmount: 1000, gstRate: 18, cgst: 90, sgst: 90, igst: 0, totalTax: 180, totalAmount: 1180 }Discounts
Percentage and fixed-amount discount calculations.
calculatePercentageDiscount
calculatePercentageDiscount(amount: number, percentage: number): DiscountResultApplies a percentage discount and returns original, discount, and final amounts.
Returns: DiscountResult
calculatePercentageDiscount(2000, 15);
// { originalAmount: 2000, discountAmount: 300, finalAmount: 1700, percentage: 15 }calculateFixedDiscount
calculateFixedDiscount(amount: number, discount: number): FixedDiscountResultApplies a fixed rupee discount to an amount.
Returns: FixedDiscountResult
calculateFixedDiscount(2000, 300);
// { originalAmount: 2000, discountAmount: 300, finalAmount: 1700 }Percentage
calculatePercentage
calculatePercentage(amount: number, percentage: number): numberReturns a percentage of the given amount.
Returns: Calculated percentage value
calculatePercentage(5000, 12);
// 600Fees
Platform and convenience fee calculations.
calculatePercentageFee
calculatePercentageFee(amount: number, feeRate: number): PercentageFeeResultCalculates a percentage-based platform or convenience fee on a base amount.
Returns: PercentageFeeResult
calculatePercentageFee(1000, 2.5);
// { baseAmount: 1000, feeRate: 2.5, feeAmount: 25, totalAmount: 1025 }Commission
Marketplace commission and net payout calculations.
calculateCommission
calculateCommission(amount: number, commissionRate: number): CommissionResultCalculates marketplace commission and net payout from a gross amount.
Returns: CommissionResult
calculateCommission(5000, 12);
// { amount: 5000, commissionRate: 12, commissionAmount: 600, netAmount: 4400 }Order Total
Full cart calculation with line items, optional percentage or fixed discount, named fees, and GST.
calculateOrderTotal
calculateOrderTotal(input: CalculateOrderTotalInput): OrderTotalResultComputes full cart totals: subtotal, discount, fees, tax, and grand total from line items.
Returns: OrderTotalResult
calculateOrderTotal({
items: [
{ price: 999, quantity: 2 },
{ price: 2499, quantity: 1 },
],
discount: { type: "percentage", value: 10 },
fees: [{ name: "Delivery", amount: 50 }],
tax: { rate: 18 },
});
// {
// subtotal: 4497,
// discountAmount: 449.7,
// subtotalAfterDiscount: 4047.3,
// feeTotal: 50,
// taxableAmount: 4097.3,
// taxAmount: 737.51,
// grandTotal: 4834.81
// }CalculateOrderTotalInput
items— array of { price, quantity }discount?— { type: "percentage" | "fixed", value: number }fees?— array of { name, amount }tax?— { rate: number }
TypeScript Exports
All functions and result types are fully typed.
import {
formatINR,
rupeesToPaise,
paiseToRupees,
addGST,
removeGST,
calculatePercentageDiscount,
calculateFixedDiscount,
calculatePercentage,
calculatePercentageFee,
calculateCommission,
calculateOrderTotal,
} from "moneyutils-in";
import type {
FormatINROptions,
DiscountResult,
FixedDiscountResult,
GSTResult,
GSTTransactionType,
PercentageFeeResult,
CommissionResult,
OrderItem,
OrderFee,
OrderDiscount,
OrderTax,
CalculateOrderTotalInput,
OrderTotalResult,
} from "moneyutils-in";Disclaimer
GST and tax utilities perform calculations based on the values provided by the developer. They do not determine the legally applicable tax rate or tax treatment for a transaction.