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)