npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cxllm/currency

v1.0.1

Published

A currency converter api that uses exchangerate.host

Downloads

3

Readme

@cxllm/currency

This is a package that uses the exchangerate.host API for easy currency conversion within node.js. It contains methods for finding the rate and a conversion of a specific value between two different currencies.

Installation

For installing this, please run: npm install @cxllm/currency

Or, if you prefer the yarn package manager yarn install @cxllm/currency

Methods + Examples

In the examples below I will be using British Pounds (GBP) and Canadian Dollars (CAD), however they are interchangeable with other 3-character currency codes, e.g. USD (United States Dollar), TRY (Turkish Lira), AUD (Australian Dollar) etc. You can also use this library with TypeScript's import instead of require, however I just used require for the purpose of this example

Convert Method

This is the method used for converting between 2 currencies with a specific value. The arguments are as follows:

convert(
    amount: number, // the amount to convert
    from: string, // the currency to convert from
    to: string // the currency to convert to
)

This returns a promise with an object containing values with these types:

from: string; // the currency converted from
to: string; // the currency converted to
amount: number; // the amount converted
rate: number; // the exchange rate
conversion: number; // the conversion of the amount
updated: Date; // the time it was last updated (a JavaScript Date object)

Example

const converter = require("@cxllm/currency");
convertor.convert(12.8, "GBP", "CAD").then(console.log);
// { from: 'GBP', to: 'CAD', amount: 12.8, rate: 1.709844, conversion: 21.886, updated: 2022-01-30T00:00:00.000Z

Rate Method

This is the method for finding the exchange rate between two currencies The syntax is as follows:

rate(
    from: string, // the currency to convert from
    to: string // the currency to convert to
);

This returns a promise with an object containing values with these types:

from: string; //the currency converted from
to: string; // the currency converted to
rate: number; // the exchange rate
updated: Date; // the time it was last updated (a JavaScript Date object)

Example

const converter = require("@cxllm/currency");
convertor.rate("GBP", "CAD").then(console.log);
// { from: 'GBP', to: 'CAD', rate: 1.709844, updated: 2022-01-30T00:00:00.000Z }

Currencies Method

This is the method for listing all currencies supported, and their names. The syntax is as follows:

currencies();

This returns a promise with an array:

Array<{
    name: string, // The currency name
    code: string // The 3 letter code
}>

Example

const converter = require("@cxllm/currency");
convertor.currencies().then(console.log);
// [ { name: 'United Arab Emirates Dirham', code: 'AED' }, { name: 'Afghan Afghani', code: 'AFN' }, ... etc ]

## Support

If you require any further support, please contact me through the twitter and discord links listed [here](https://github.com/cxllm/)