DEV Community

Cover image for Introducing to globalprice
Menula De Silva
Menula De Silva

Posted on

Introducing to globalprice

Smart and dynamic pricing engine for global applications, supporting real-time currency conversion, quantity, discounts, tax calculations, and formatted output.

Github Repo Here


πŸš€ 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
Enter fullscreen mode Exit fullscreen mode

✨ 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'
Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ Test Locally

npm test
Enter fullscreen mode Exit fullscreen mode

πŸ” Environment Setup

Add .env for custom API keys:

EXCHANGE_API_KEY=your_api_key_here
Enter fullscreen mode Exit fullscreen mode

πŸ“ Folder Structure

globalprice/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.js
β”‚   β”œβ”€β”€ rates.js
β”‚   └── currencies.js
β”œβ”€β”€ cache/
β”‚   └── exchangeRates.json
β”œβ”€β”€ test/
β”‚   └── globalprice.test.js
β”œβ”€β”€ .env
β”œβ”€β”€ package.json
β”œβ”€β”€ LICENSE
└── README.md
Enter fullscreen mode Exit fullscreen mode

πŸ“„ License

MIT Β© Menula De Silva

Top comments (0)