Lightweight currency conversion library, successor of money.js
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
- Simple API
- 0 dependencies
- Actively maintained
- Well tested
- Easy migration from money.js
- Written in TypeScript
$ npm install cashify
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
Constructor
Type: string
Base currency
Type: object
Object containing currency rates (for example from an API, such as Open Exchange Rates)
Returns conversion result (number
)
Type: number
Amount of money you want to convert
Type: string
Currency from which you want to convert
Type: string
Currency to which you want to convert
Returns conversion result (number
)
Type: number
Amount of money you want to convert
Type: string
Currency from which you want to convert
Type: string
Currency to which you want to convert
Type: string
Base currency
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});
MIT © Antoni Kepinski