RepositoryTypeScriptDEGermany
xxczaki

xxczaki/cashify

💸 Lightweight currency conversion library, successor of money.js

407stars
18forks
3issues
2views

Cashify

Lightweight currency conversion library, successor of money.js

CI install size Mentioned in Awesome Node.js


Motivation

This package was created, because the popular money.js library:

  • is not maintained (last commit was over 10 years ago)
  • has over 20 open issues
  • does not support TypeScript
  • has implicit globals
  • does not have any unit tests
  • has floating point issues

Highlights

Install

$ pnpm add cashify

This package is ESM-only and requires Node.js 24 or higher.

Usage

With constructor

import {Cashify} from 'cashify';

const rates = {
	GBP: 0.92,
	EUR: 1.00,
	USD: 1.12
};

const cashify = new Cashify({base: 'EUR', rates});

const result = cashify.convert(10, {from: 'EUR', to: 'GBP'});

console.log(result); //=> 9.2

Without constructor

Using the Cashify constructor is not required. Instead, you can just use the convert function:

import {convert} from 'cashify';

const rates = {
	GBP: 0.92,
	EUR: 1.00,
	USD: 1.12
};

const result = convert(10, {from: 'EUR', to: 'GBP', base: 'EUR', rates});

console.log(result); //=> 9.2

Parsing

Cashify supports parsing, so you can pass a string to the amount argument and the from and/or to currency will be automatically detected:

import {Cashify} from 'cashify';

const rates = {
	GBP: 0.92,
	EUR: 1.00,
	USD: 1.12
};

const cashify = new Cashify({base: 'EUR', rates});

// Basic parsing
cashify.convert('€10 EUR', {to: 'GBP'});

// Full parsing
cashify.convert('10 EUR to GBP');

Alternatively, if you just want to parse a string without conversion you can use the parse function which returns an object with parsing results:

import {parse} from 'cashify';

parse('10 EUR to GBP'); //=> {amount: 10, from: 'EUR', to: 'GBP'}

Note: If you want to use full parsing, you need to pass a string in a specific format:

10 usd to pln
12.5 GBP in EUR
3.1415 eur as chf

You can use to, in or as to separate the expression (case insensitive). Used currencies name case doesn't matter, as cashify will automatically convert them to upper case.

Integration with big.js

big.js is a small JavaScript library for arbitrary-precision decimal arithmetic. You can use it with cashify to make sure you won't run into floating point issues:

import {Cashify} from 'cashify';
import Big from 'big.js';

const rates = {
	EUR: 0.8235,
	USD: 1
};

const cashify = new Cashify({base: 'USD', rates});

const result = cashify.convert(1, {
	from: 'USD',
	to: 'EUR',
	BigJs: Big
});

console.log(result); //=> 0.8235 (without big.js you would get something like 0.8234999999999999)

Formatting with Intl.NumberFormat

You can use the built-in Intl.NumberFormat API to format conversion results as currency strings:

import {Cashify} from 'cashify';

const rates = {
	GBP: 0.92,
	EUR: 1.00,
	USD: 1.12
};

const cashify = new Cashify({base: 'EUR', rates});

const converted = cashify.convert(8635619, {from: 'EUR', to: 'GBP'}); // => 7944769.48

// Format the conversion result
new Intl.NumberFormat('en-GB', {style: 'currency', currency: 'GBP'}).format(converted); // => '£7,944,769.48'

API

Cashify({base, rates, BigJs})

Constructor.

base

Type: string

The base currency.

rates

Type: object

An object containing currency rates (for example from an API, such as Open Exchange Rates).

BigJs

Type: big.js constructor

See integration with big.js.

convert(amount, {from, to, base, rates}) with and without constructor

Returns conversion result (number).

amount

Type: number or string

Amount of money you want to convert. You can either use a number or a string. If you choose the second option, you can take advantage of parsing and not specify from and/or to argument(s).

from

Type: string

Currency from which you want to convert. You might not need to specify it if you are using parsing.

to

Type: string

Currency to which you want to convert. You might not need to specify it if you are using parsing.

base

Type: string

The base currency.

rates

Type: object

An object containing currency rates (for example from an API, such as Open Exchange Rates).

BigJs

Type: big.js constructor

See integration with big.js.

parse(expression)

Returns an object, which contains parsing results:

{
	amount: number;
	from: string | undefined;
	to: string | undefined;
}
expression

Type: string

Expression you want to parse, ex. 10 usd to pln or €1.23 eur

Migrating from money.js

With Cashify constructor:

- import fx from 'money';
+ import {Cashify} from 'cashify';

- fx.base = 'EUR';
- fx.rates = {
-	GBP: 0.92,
-	EUR: 1.00,
-	USD: 1.12
- };

+ const rates = {
+	 GBP: 0.92,
+	 EUR: 1.00,
+	 USD: 1.12
+ };

+ const cashify = new Cashify({base: 'EUR', rates});

- fx.convert(10, {from: 'GBP', to: 'EUR'});
+ cashify.convert(10, {from: 'GBP', to: 'EUR'});

With convert function:

- import fx from 'money';
+ import {convert} from 'cashify';

- fx.base = 'EUR';
- fx.rates = {
-	GBP: 0.92,
-	EUR: 1.00,
-	USD: 1.12
- };

+ const rates = {
+	 GBP: 0.92,
+	 EUR: 1.00,
+	 USD: 1.12
+ };

- fx.convert(10, {from: 'GBP', to: 'EUR'});
+ convert(10, {from: 'GBP', to: 'EUR', base: 'EUR', rates});

Floating point issues

When working with currencies, decimals only need to be precise up to the smallest cent value while avoiding common floating point errors when performing basic arithmetic.

Let's take a look at the following example:

import {Cashify} from 'cashify';

const rates = {
	GBP: 0.92,
	USD: 1.12
};

const cashify = new Cashify({base: 'EUR', rates});

// money.js would give: 9.200000000000001
cashify.convert(10, {from: 'EUR', to: 'GBP'}); //=> 9.2

Cashify uses a simple rounding trick (amount * 100 * rate / 100) that avoids floating point errors in many common currency conversions. This works well for most practical currency values, but it is not a complete solution for all possible floating point edge cases. For guaranteed arbitrary-precision arithmetic, use the big.js integration.

AI disclosure

This project contains code generated by Large Language Models (LLMs), under human supervision and proofreading.

License

MIT © Antoni Kępiński

Similar Projects

Discover other similar projects and AI models.

RepositoryPHP
florianv/swap

PHP currency conversion library for retrieving exchange rates from 30 providers, with caching and fallback. Maintained since 2014.

1.3k
Nov 26, 2026
RepositoryPython
fawazahmed0/exchange-api

Free Currency Exchange Rates API with 200+ Currencies & No Rate Limits

2.7k
Oct 1, 2026
RepositoryRuby
lineofflight/frankfurter

💱 Currency data API

2.2k
Dec 1, 2026
RepositoryTypeScript
dinerojs/dinero.js

Create, calculate, and format money in JavaScript and TypeScript

6.8k
Nov 25, 2026
RepositoryPHP
moneyphp/money

PHP implementation of Fowler's Money pattern.

4.9k
Nov 23, 2026
RepositoryPHP
brick/money

A money and currency library for PHP

1.9k
Oct 6, 2026
RepositoryGo
Rhymond/go-money

Go implementation of Fowler's Money pattern

1.9k
Apr 29, 2026
RepositorySwift
Flight-School/Money

A precise, type-safe representation of a monetary amount in a given currency

907
Aug 31, 2023
RepositoryPHP
akaunting/laravel-money

Currency formatting and conversion package for Laravel

790
Nov 29, 2026