All Projects → frolovdev → Easymoney

frolovdev / Easymoney

Licence: mit
Library for operating with monetary values in JavaScript and Typescript 💵

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Easymoney

react-numeric
A react component for formatted number form fields
Stars: ✭ 30 (-79.31%)
Mutual labels:  money, formatter, currency
Go Money
Go implementation of Fowler's Money pattern
Stars: ✭ 887 (+511.72%)
Mutual labels:  currency, money, formatter
Javascript Number Formatter
Lightweight & Fast JavaScript Number Formatter
Stars: ✭ 119 (-17.93%)
Mutual labels:  currency, formatter
Money
A money and currency library for PHP
Stars: ✭ 855 (+489.66%)
Mutual labels:  currency, money
Django Prices
Django fields for the prices module
Stars: ✭ 135 (-6.9%)
Mutual labels:  currency, money
Dinero.js
Create, calculate, and format money in JavaScript and TypeScript.
Stars: ✭ 5,286 (+3545.52%)
Mutual labels:  currency, money
Money
A precise, type-safe representation of a monetary amount in a given currency
Stars: ✭ 817 (+463.45%)
Mutual labels:  currency, money
Android Money
Simple money and currency converter library for android.
Stars: ✭ 66 (-54.48%)
Mutual labels:  currency, money
Anyformatkit
Simple text formatting in Swift
Stars: ✭ 296 (+104.14%)
Mutual labels:  currency, formatter
Countries
Countries - ISO 3166 (ISO3166-1, ISO3166, Digit, Alpha-2 and Alpha-3) countries codes and names (on eng and rus), ISO 4217 currency designators, ITU-T E.164 IDD calling phone codes, countries capitals, UN M.49 regions codes, ccTLD countries domains, IOC/NOC and FIFA letters codes, VERY FAST, NO maps[], NO slices[], NO init() funcs, NO external links/files/data, NO interface{}, NO specific dependencies, Databases/JSON/GOB/XML/CSV compatible, Emoji countries flags and currencies support, full support ISO-3166-1, ISO-4217, ITU-T E.164, Unicode CLDR and ccTLD standarts.
Stars: ✭ 85 (-41.38%)
Mutual labels:  currency, money
Currencyconverter
Utilities for doing currency conversion with the Money library
Stars: ✭ 78 (-46.21%)
Mutual labels:  currency, money
Money Open Exchange Rates
A gem that calculates the exchange rate using published rates from open-exchange-rates. Compatible with the money gem.
Stars: ✭ 87 (-40%)
Mutual labels:  currency, money
Money
PHP implementation of Fowler's Money pattern.
Stars: ✭ 3,868 (+2567.59%)
Mutual labels:  currency, money
Vue Numeric
Input field component to display a formatted currency value based on Vue.js
Stars: ✭ 341 (+135.17%)
Mutual labels:  currency, money
Cashify
💸 Lightweight currency conversion library, successor of money.js
Stars: ✭ 329 (+126.9%)
Mutual labels:  currency, money
React Currency Formatter
💵 react component for currency formatting
Stars: ✭ 38 (-73.79%)
Mutual labels:  currency, formatter
Exchanger
🏢 Currency exchange rates framework for PHP
Stars: ✭ 133 (-8.28%)
Mutual labels:  currency, money
Laravel Money
Currency formatting and conversion package for Laravel
Stars: ✭ 261 (+80%)
Mutual labels:  currency, money
Jsr354 Api
JSR 354 - Money and Currency API
Stars: ✭ 262 (+80.69%)
Mutual labels:  currency, money
Swap
💱 Currency exchange rates library
Stars: ✭ 1,195 (+724.14%)
Mutual labels:  currency, money

easy money logo

codecov License: MIT

Library for operating with monetary values in JavaScript and Typescript

  • Modular. It's written with modular and composable architecture so that your final bundle will be as small as possible.
  • Statically typed. First-class support of Typescript.
  • Immutable: It has a chainable API, but without mutations.
  • Supports big numbers. Support values greater than MAX_SAFE_INTEGER with Bignumber.js
  • Crypto currencies. It has support for custom currencies and formatting them.
  • Big int support. It has a package for supporting new standard of big int out of the box in a separate pacakge.
  • Custom calculators. You can override functionality with your own custom calculator.

📖 Read more

import { createMoney } from '@easymoney/money';

const money1 = createMoney({ amount: 100, currency: 'USD' });

const money2 = createMoney({ amount: 106, currency: 'USD' });

const money3 = money1.add(money2).getAmount();
// => 206
import { createMoneyIntlFormatter } from "@easymoney/formatter"
import { createMoney } from '@easymoney/money';

const money = createMoney({ amount: 5, currency: "USD" });

const formatted = createMoneyIntlFormatter().format(money);
// => "$0.05"
import { createMoneyCryptoFormatter } from "@easymoney/crypto-formatter"
import { createMoney } from '@easymoney/money';
import { cryptoCurrenciesMap } from "@easymoney/currencies"

const money = createMoney({ amount: 5, currency: "LTC" });

const formatted = createMoneyCryptoFormatter().format(money);
// => "0.00000005LTC"
const currencies = [{ minorUnit: 2, code: "XBT" }, { minorUnit: 5, code: "DXBT" }];

const list = createCurrencyList(currencies);

list.getCurrencies();
/**
 * => {
  XBT: { minorUnit: 2, code: "XBT" },
  DXBT: { minorUnit: 5, code: "DXBT" },
};
 */

Requirements

  • For typescript users TS 3.7+
  • If you use @easymoney/bigint-money you need Node Version or Browser Version that supports this proposal

Quick start

npm i @easymoney/money

or

yarn add @easymoney/money

Why

JavaScript developers attempt to use just numbers or strings (i.g. https://github.com/MikeMcl/bignumber.js) to operate with monetary values. I don't think this is the right way, and strings or numbers are not well suited for financial applications for these main reasons:

  • tricky rounding (described here)
  • conversion
  • allocating (dividing money between parties)
  • formatting
  • working with cents (minor units of currency)

The solution to these problems is the Martin Fowler's Money Type from "Patterns of Enterprise Application Architecture".

It's an old pattern that is implemented in many other languages e.g.:

Further reading

How to Operate with Monetary Values in JavaScript

Main features of easymoney

Why rounding is more important than you think

Comparison with dinero.js

easymoney Dinero.js
Typescript ❌ (only @types/Dinero)
Modular functionality is divided by domains, which allows the library to be divided into separate modules as efficiently as possible written as a monolith, one big object with a bunch of functions, no way to divide it into packages by design
Custom currencies support ❌ (only ISO currencies)
Custom calculators support
Monetary values greater than MAX_SAFE_INTEGER
Bigint support

Packages

Package Version Dependencies Size
@easymoney/bigint-money npm-bigint-money deps-bigint-money size-bigint-money
@easymoney/bignumber.js npm-bignumber deps-bignumber size-bignumber
@easymoney/currencies npm-currencies deps-currencies size-currencies
@easymoney/money npm-money deps-money size-money
@easymoney/formatter npm-formatter deps-formatter size-formatter
@easymoney/crypto-formatter npm-crypto-formatter deps-crypto-formatter size-crypto-formatter

CDN

Comunity

Learn more

API Reference

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Andrey Frolov

⚠️ 📖 💻

oneyan1

⚠️ 📖 💻

Mikchail

📖

Roman Martynenko

📖

Artem676

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].