Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
A free currency converter for NodeJS - uses the European Central Bank's daily feed for accuracy
A free currency converter for NodeJS - uses the European Central Bank's daily feed for accuracy
The best way of installing this is through NPM:
npm install currencyjs
If you want to install a specific version:
npm install currencyjs@1.0.0
# Usage
The first thing you need to do is to include the library and create an instance.
var CurrencyJS = require('currencyjs');
var objCurrency = new CurrencyJS({
type: 'mysql', // Select database to use
host: 'host', // localhost or similar
user: 'username', // Optional
pass: 'password', // Optional
db: 'database',
port: 'port' // Optional
});
See the Supported Databases section for the databases you can use.
## Creating Data TablesOnce you've created your instance, you will need to create your data table. This is something you'll only probably do once, but it's written as a function to make it easier (and to run integration tests on it).
Depending upon your chosen database type (eg, Mongo), you may not actually need to run this. However, it's probably best to run it.
objCurrency.createTable(function(err, result) {
// err should be null
// result should be true
});
If you have some form of migration script of your own, you can use the actual query directly. You'll find this in /lib/db/DB_TYPE/store.js.
## Importing DataNow we've got our data table created, we can start importing some data. The feed is from the European Central Bank, which publishes it in XML format. Again there is a method that you can execute, imaginatively titled import().
objCurrency.import(function(err, importCount) {
// err should be null
// importCount should be a number, at least 0
});
This is probably best run as a cron job. The feed gets updates at about 2pm in Central European Time - UTC + 1 (UTC + 2 in the summer). Also, the feed is only updated on weekdays, so not much point in querying it on a Saturday or Sunday.
## Converting CurrenciesThis is what you actually want. Once you've set up your database and imported some data, you can actually get on with doing the conversions. Best done with a series of examples
Pass in just the currencies to get the currency rate
objCurrency.convert('USD', 'EUR', function(err, objConvert) {
// err should be null
// objConvert should be instance of Convert object
});
Pass in an object with value defined. THIS MUST BE A NUMBER
objCurrency.convert('GBP', 'AUD', {value: 10}, function(err, objConvert) {
// err should be null
// objConvert should be instance of Convert object
});
Pass in an object with date defined. THIS MUST BE A DATE OBJECT
objCurrency.convert('EUR', 'CAD', {value: 45.85, date: new Date('2013-07-23')}, function(err, objConvert) {
// err should be null
// objConvert should be instance of Convert object
});
## The Convert Model
When you make a conversion request, you are returned an instance of the Convert model. This is quite useful as, once you have it, you can make further conversions without having to query the database.
@returns Undefined
Converts the from value into the to value
You will need to do one of the below get methods to return the value.
@returns Undefined
Converts the to value into the from value
You will need to do one of the below get methods to return the value.
Gets the from value formatted as a string. By default, it would return 1234.5 as 1,234.50.
@returns Number
Returns the from value as a number.
@returns Number
Returns the converstion rate as a number. Multiply the from value by this and you will get the to value.
@returns Number
Returns the reverse converstion rate as a number. Multiply the to value by this and you will get the from value.
@returns String
Gets the to value formatted as a string. By default, it would return 1234.5 as 1,234.50.
@returns Number
Returns the to value as a number.
# Supported CurrenciesThis is a list of all the supported currencies and their 3 letter code:
CurrencyJS supports the following databases and from which version. Simply set up the CurrencyJS object with the string in italics below.
Please report any bugs on GitHub
# LicenceThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Copyright (C) 2013 Simon Emms
FAQs
A free currency converter for NodeJS - uses the European Central Bank's daily feed for accuracy
The npm package currencyjs receives a total of 108 weekly downloads. As such, currencyjs popularity was classified as not popular.
We found that currencyjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.