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

currency-converter-vl

v1.0.2

Published

Simplified Currency Conversion in Node js Without API Calls

Downloads

52

Readme

Known Vulnerabilities supported node versions license: MIT npm version npm

Typescript Support

I've updated tsconfig.json to { "compilerOptions": { "allowJs": true}} and imported class import * as CurrencyConverter from 'currency-converter-vl';

Getting started

Installation

This package can be installed using npm

npm install currency-converter-vl

or, yarn

yarn add currency-converter-vl

Usage

Import currency-converter-vl.

const CCV = require('currency-converter-vl')

Instant Setup: Node.js Currency Converter with Empty Constructor

let currencyConverter = new CCV()

Or, with a json object

let currencyConverter = new CCV({from:"USD", to:"INR", amount:100})

!!! Note: if you get incorrect conversion described in this issue then make sure you pass isDecimalComma: true to the constructor as following:

let currencyConverter = new CCV({from:"USD", to:"INR", amount:100, isDecimalComma:true})

Node.js Currency Converter: Promise-Based Convert Method with Rate Caching

currencyConverter.convert().then((response) => {
    console.log(response) //or do something else
})

convert can also take the amount as a parameter.

currencyConverter.convert(100).then((response) => {
    console.log(response) //or do something else
})

To find the rates use the rates method.

currencyConverter.rates().then((response) => {
    console.log(response) //or do something else
})

The Node js Currency Converter Library not only simplifies currency conversions by eliminating the need for API subscriptions but also supports efficient rate caching for currency pairs. To implement rate caching, instantiate an object of the CurrencyConverter class only once in your project. This should be done in a dedicated CurrencyConverter file, where you can set up the rates caching configuration. Subsequently, you can import this single instance of CurrencyConverter across the rest of your project. By centralizing the instantiation and configuration, you ensure that the cached rates are consistently utilized throughout your application, improving performance and reducing redundant requests.

Note: Moreover, the library supports method chaining, allowing for more readable and concise code when performing currency conversions. When caching is enabled, the process remains efficient as the rates are not deleted after the ratesCacheDuration expires. Instead, the rate remains in the cache until a new request for the same currency pair is made, at which point the old rate is overwritten with the updated value. This approach ensures that the conversion rates are always up-to-date while minimizing unnecessary API calls. The following is an example of how to set up and use the CurrencyConverter in a dedicated file, showcasing the implementation of rate caching and chaining for seamless currency conversions.

const CCV = require('currency-converter-vl')

let currencyConverter = new CCV()

let ratesCacheOptions = {
    isRatesCaching: true, // Set this boolean to true to implement rate caching
    ratesCacheDuration: 3600 // Set this to a positive number to set the number of seconds you want the rates to be cached. Defaults to 3600 seconds (1 hour)
}

currencyConverter = currencyConverter.setupRatesCache(ratesCacheOptions)

module.exports = currencyConverter

Effortless Currency Conversion with Chaining Support in Node js

currencyConverter.from("CAD").to("HRK").amount(125).convert().then((response) => {
    console.log(response) //or do something else
})

Disclaimer

This package uses web scraping to provide the api.

Issues

If any issues are found, they can be reported here.

License

This project is licensed under the MIT license.