8000 GitHub - miron77/cashify: 💸 Lightweight currency conversion library, successor of money.js
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

miron77/cashify

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

💸 Lightweight currency conversion library, successor of money.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%
0