Skip to content
💸 Lightweight currency conversion library, successor of money.js
TypeScript
Branch: master
Clone or download
Latest commit 37c6bb0 Aug 9, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Initial commit Aug 7, 2019
src If `from` equals `to`, just return the amount of money Aug 9, 2019
.editorconfig Initial commit Aug 7, 2019
.gitignore Initial commit Aug 7, 2019
.travis.yml travis: publish coverage to coveralls Aug 7, 2019
license lowercase license & remove year Aug 7, 2019
package.json Fix travis Aug 9, 2019
readme.md Fix markdown link Aug 8, 2019
test.ts Change tests Aug 9, 2019
tsconfig.json Initial commit Aug 7, 2019

readme.md

Cashify 💸

Lightweight currency conversion library, successor of money.js

Build Status Coverage Status XO code style install size

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

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

Highlights

Install

$ npm install cashify

Usage

const {Cashify} = require('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.200000000000001

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

const {convert} = require('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.200000000000001

API

Cashify({base, rates})

Constructor

base

Type: string

Base currency

rates

Type: object

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

convert(amount, {from, to}) with constructor

Returns conversion result (number)

amount

Type: number

Amount of money you want to convert

from

Type: string

Currency from which you want to convert

to

Type: string

Currency to which you want to convert

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

Returns conversion result (number)

amount

Type: number

Amount of money you want to convert

from

Type: string

Currency from which you want to convert

to

Type: string

Currency to which you want to convert

base

Type: string

Base currency

rates

Type: object

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

Migrating from money.js

With Cashify constructor:

- const fx = require('money');
+ const {Cashify} = require('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:

- const fx = require('money');
+ const {convert} = require('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});

License

MIT © Antoni Kepinski

You can’t perform that action at this time.