Smart and dynamic pricing engine for global applications, supporting real-time currency conversion, quantity, discounts, tax calculations, and formatted output.
π Features
- π Supports 160+ currencies
- π Auto-fetches latest exchange rates
- π§Ύ VAT / GST / custom tax support
- πΈ Discount by percentage or fixed value
- π¦ Quantity multiplier
- πͺ Currency symbol & locale-aware formatting
- π§ Works offline using cached or fallback rates
- π
.env
support for premium API keys
π¦ Installation
npm install globalprice
β¨ Usage Example
const { calculatePrice, updateRates } = require("globalprice");
await updateRates(); // optional, updates latest rates
const result = await calculatePrice({
basePrice: 100,
quantity: 2,
currency: "LKR",
discount: { type: "percent", value: 10 },
tax: { type: "VAT", rate: 12 },
format: true
});
console.log(result.formatted); // 'Rs 7320.00'
π§ͺ Test Locally
npm test
π Environment Setup
Add .env
for custom API keys:
EXCHANGE_API_KEY=your_api_key_here
π Folder Structure
globalprice/
βββ src/
β βββ index.js
β βββ rates.js
β βββ currencies.js
βββ cache/
β βββ exchangeRates.json
βββ test/
β βββ globalprice.test.js
βββ .env
βββ package.json
βββ LICENSE
βββ README.md
π License
MIT Β© Menula De Silva
Top comments (0)