Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coin-rates

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coin-rates - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

2

CHANGELOG.md
# Changelog
* v1.1.1:
* Updated, removed dependencies
* v1.1.0:

@@ -4,0 +6,0 @@ * Replace getValueAtPath with function to parse response body - improves flexibility of response parsing.

25

lib/cache.js

@@ -1,2 +0,1 @@

const _ = require('underscore');
let map = new Map();

@@ -6,7 +5,7 @@

get: function(key, options) {
options = _.defaults(options || {}, {
maxAge: 5 * 60 * 1000,
});
let data = null;
try {
return Promise.resolve().then(() => {
options = Object.assign({}, {
maxAge: 5 * 60 * 1000,
}, options || {});
let data = null;
const value = map.get(key);

@@ -25,9 +24,7 @@ if (value) {

}
} catch (error) {
return Promise.reject(error);
}
return Promise.resolve(data);
return data;
});
},
set: function(key, data) {
try {
return Promise.resolve().then(() => {
const timestamp = Date.now();

@@ -37,7 +34,5 @@ const item = { data, timestamp };

map.set(key, value);
} catch (error) {
return Promise.reject(error);
}
return Promise.resolve(data);
return data;
});
},
};

@@ -1,2 +0,2 @@

const _ = require('underscore');
const assert = require('assert');
const async = require('async');

@@ -9,5 +9,7 @@ const formatText = require('./formatText');

const noop = function() {};
module.exports = function(options) {
try {
options = _.defaults(options || {}, {
return Promise.resolve().then(() => {
options = Object.assign({}, {
currencies: {

@@ -21,3 +23,3 @@ from: null,

if (error instanceof Error) return false;
if (!_.isUndefined(error.status)) {
if (typeof error.status !== 'undefined') {
if (error.status === 0) return false;

@@ -32,39 +34,22 @@ if (error.status >= 400 && error.status <= 499) return false;

provider: null,
}, options || {});
assert.ok(options.currencies, 'Missing required option: "currencies"');
assert.strictEqual(typeof options.currencies, 'object', 'Invalid option ("currencies"): Object expected');
assert.ok(options.currencies.from, 'Missing required option: "currencies.from"');
assert.ok(options.currencies.to, 'Missing required option: "currencies.to"');
assert.strictEqual(typeof options.currencies.from, 'string', 'Invalid option ("currencies.from"): String expected');
assert.strictEqual(typeof options.currencies.to, 'string', 'Invalid option ("currencies.to"): String expected');
assert.ok(options.provider, 'Missing required option: "provider"');
let provider = providers.find(provider => {
return provider.name === options.provider;
});
if (!options.currencies) {
throw new Error('Missing required option: "currencies"');
assert.ok(provider, `Unknown provider: "${options.provider}"`);
assert.ok(provider.url, 'Missing provider config: "url"');
assert.ok(typeof provider.convertSymbols === 'undefined' || typeof provider.convertSymbols === 'object', 'Invalid provider config ("convertSymbols"): Object expected');
if (typeof provider.parseResponseBody === 'undefined') {
provider.parseResponseBody = noop;
}
if (!_.isObject(options.currencies)) {
throw new Error('Invalid option ("currencies"): Object expected');
}
if (!_.isString(options.currencies.from)) {
throw new Error('Invalid option ("currencies.from"): String expected');
}
if (!_.isString(options.currencies.to)) {
throw new Error('Invalid option ("currencies.to"): String expected');
}
if (!options.provider) {
throw new Error('Missing required option: "provider"');
}
if (!_.isString(options.provider)) {
throw new Error('Invalid option ("provider"): String expected');
}
let provider = _.findWhere(providers, { name: options.provider });
if (!provider) {
throw new Error(`Unknown provider: "${options.provider}"`);
}
if (!provider.url) {
throw new Error('Missing provider config: "url"');
}
if (!_.isUndefined(provider.convertSymbols) && !_.isObject(provider.convertSymbols)) {
throw new Error('Invalid provider config ("convertSymbols"): Object expected');
}
if (_.isUndefined(provider.parseResponseBody)) {
provider.parseResponseBody = _.noop;
}
if (!_.isFunction(provider.parseResponseBody)) {
throw new Error('Invalid provider config ("parseResponseBody"): Function expected');
}
assert.strictEqual(typeof provider.parseResponseBody, 'function', 'Invalid provider config ("parseResponseBody"): Function expected');
let currencies = {};
_.each(options.currencies, function(symbol, key) {
Object.entries(options.currencies).forEach(function([key, symbol], index) {
if (provider.convertSymbols && provider.convertSymbols[symbol]) {

@@ -93,3 +78,3 @@ symbol = provider.convertSymbols[symbol];

result = provider.parseResponseBody(body, currencies) || null;
if (_.isNumber(result)) {
if (typeof result === 'number') {
result = result.toString();

@@ -117,5 +102,3 @@ }

});
} catch (error) {
return Promise.reject(error);
}
});
};

@@ -1,10 +0,8 @@

const _ = require('underscore');
module.exports = function(text, data) {
_.chain(data)
.pick('from', 'to', 'FROM', 'TO')
.each(function(value, key) {
text = text.replace(`{{${key}}}`, value);
});
const { from, to, FROM, TO } = data;
text = text.replace(`{{from}}`, from);
text = text.replace(`{{to}}`, to);
text = text.replace(`{{FROM}}`, FROM);
text = text.replace(`{{TO}}`, TO);
return text;
};

@@ -1,2 +0,1 @@

const _ = require('underscore');
const cache = require('./cache');

@@ -7,3 +6,4 @@ const fetch = require('./fetch');

options = options || {};
const key = JSON.stringify(_.pick(options, 'provider', 'currencies'));
const { provider, currencies } = options;
const key = JSON.stringify({ provider, currencies });
return cache.get(key, options.cache).then(fromCache => {

@@ -10,0 +10,0 @@ if (fromCache) return fromCache;

@@ -1,2 +0,2 @@

const _ = require('underscore');
const assert = require('assert');

@@ -22,5 +22,3 @@ module.exports = [

let data = JSON.parse(body);
if (!_.isEmpty(data.message)) {
throw new Error(data.message);
}
assert.ok(!data.message, data.message);
return data.last_price;

@@ -35,5 +33,3 @@ },

let data = JSON.parse(body);
if (!_.isEmpty(data.error_message)) {
throw new Error(data.error_message);
}
assert.ok(!data.error_message, data.error_message);
return data.ltp;

@@ -48,5 +44,3 @@ },

let data = JSON.parse(body);
if (!_.isEmpty(data.message)) {
throw new Error(data.message);
}
assert.ok(!data.message, data.message);
return data.last;

@@ -61,5 +55,3 @@ },

let data = JSON.parse(body);
if (!_.isEmpty(data.errors)) {
throw new Error(data.errors);
}
assert.ok(!data.errors, data.errors);
const { TO } = currencies;

@@ -75,5 +67,3 @@ return data.data && data.data.rates && data.data.rates[TO];

let data = JSON.parse(body);
if (!_.isEmpty(data.errorMessage)) {
throw new Error(data.errorMessage);
}
assert.ok(!data.errorMessage, data.errorMessage);
return data.data && data.data.last;

@@ -91,5 +81,3 @@ },

let data = JSON.parse(body);
if (!_.isEmpty(data.error)) {
throw new Error(data.error);
}
assert.deepStrictEqual(data.error, [], data.error);
const { FROM, TO } = currencies;

@@ -96,0 +84,0 @@ return data.result && data.result[`X${FROM}Z${TO}`] && data.result[`X${FROM}Z${TO}`]['c'] && data.result[`X${FROM}Z${TO}`]['c'][0];

{
"name": "coin-rates",
"version": "1.1.0",
"version": "1.1.1",
"description": "Fetch currency exchange rate for coin/fiat currency pairs",

@@ -19,12 +19,7 @@ "main": "index.js",

"author": {
"name": "Samotari",
"email": "crypto.samotari@gmail.com",
"url": "https://github.com/samotari"
"name": "Charles Hill",
"email": "chill@degreesofzero.com"
},
"contributors": [
{
"name": "Charles Hill",
"email": "chill@degreesofzero.com"
},
{
"name": "Carlos Garcia Ortiz",

@@ -40,9 +35,7 @@ "email": "yo@carlosgarciaortiz.com"

"dependencies": {
"async": "3.2.2",
"underscore": "1.13.1"
"async": "3.2.3"
},
"devDependencies": {
"chai": "4.3.4",
"mocha": "9.1.3"
"mocha": "9.2.2"
}
}
# coin-rates
![Build Status](https://github.com/samotari/coin-rates-node/actions/workflows/tests.yml/badge.svg)
Fetch currency exchange rate for a coin/fiat currency pair in nodejs.

@@ -4,0 +6,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc