3.0.0 • Published 9 months ago

@enesbaspinar/money v3.0.0

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

A comprehensive library for precise monetary calculations and customizable locale-based currency formatting.

Installation

You can install via your favorite package manager:

npm install @enesbaspinar/money
yarn add @enesbaspinar/money
pnpm install @enesbaspinar/money

Quick Start

Import the library and start using it to handle monetary values:

import { money } from "@enesbaspinar/money";

const manipulatedMoney = money(12345.67).add(200).discount(0.5).round(2).amount;

console.log(manipulatedMoney); // 6272.84

Also format monetary values by locale:

import { monetizer, RoundStrategy } from "@enesbaspinar/money";

const money = monetizer({ locale: "tr-TR" });
console.log(money(12345.67).format()); // ₺12.345,67

const advancedMoney = monetizer({
  locale: "tr-TR",
  precision: {
    digit: 2,
    strategy: RoundStrategy.DOWN,
  },
  preventGrouping: false,
  trimDoubleZeros: true,
  trimPaddingZeros: true,
  overridedSymbols: {
    TR: "TL",
  },
  templates: {
    "*": "{currency}{integer|,}{fraction|.}",
    TR: "{integer|,}{fraction|.} {currency}",
  },
});
console.log(advancedMoney(12345.67).format()); // 12,345.67 TL
console.log(advancedMoney(12345.67).format({ locale: "de-DE" })); // €12,345.67

Documentation

Contributing

We welcome contributions. To get started:

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Make your changes and write tests if applicable.
  4. Submit a pull request.

License

Licensed under the MIT License.