cbr-rates-cli
Advanced tools
Comparing version 0.2.5 to 0.2.6
46
cli.js
#!/usr/bin/env node | ||
import chalk from 'chalk'; | ||
import cbrRates from 'cbr-rates'; | ||
import each from 'ea'; | ||
import indentString from 'indent-string'; | ||
import meow from 'meow'; | ||
const cli = meow(` | ||
Usage | ||
cbr-rates [date] | ||
Examples | ||
cbr-rates | ||
cbr-rates 2014.5.12 | ||
`); | ||
const dateString = cli.input[0]; | ||
let date; | ||
if (dateString) { | ||
const [year, month, day] = dateString.split('.'); | ||
date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day)); | ||
} | ||
cbrRates(date, (err, rates) => { | ||
if (err) return; | ||
const values = []; | ||
each(rates, ({value}) => { | ||
values.push(value); | ||
}); | ||
const length = integerLength(Math.max(...values)); | ||
each(rates, ({par, value}, id) => { | ||
const indent = length - integerLength(value); | ||
id = id.toUpperCase(); | ||
value = indentString(value.toFixed(2), ' ', indent); | ||
console.log(`${id} ${chalk.bold(value)} ${chalk.grey(par)}`); | ||
}); | ||
}); | ||
function integerLength(num) { | ||
return Math.floor(num).toFixed().toString().length; | ||
} | ||
'use strict'; | ||
require('./index.es5'); |
{ | ||
"name": "cbr-rates-cli", | ||
"description": "Get currency rates from Central Bank of Russia", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"keywords": [ | ||
@@ -15,3 +15,3 @@ "cbr", | ||
"dependencies": { | ||
"cbr-rates": "^0.2.0", | ||
"cbr-rates": "^0.3.2", | ||
"chalk": "^1.1.0", | ||
@@ -23,13 +23,15 @@ "ea": "^0.5.0", | ||
"devDependencies": { | ||
"ava": "^0.2.0", | ||
"babel": "^5.5.6" | ||
"ava": "^0.7.0", | ||
"babel-cli": "^6.3.15", | ||
"babel-preset-es2015": "^6.3.13", | ||
"execa": "^0.1.1" | ||
}, | ||
"bin": { | ||
"cbr-rates": "cli.es5.js" | ||
"cbr-rates": "cli.js" | ||
}, | ||
"scripts": { | ||
"test": "babel-node test.js", | ||
"transpile": "babel --stage 0 cli.js > cli.es5.js", | ||
"prepublish": "npm run transpile", | ||
"postpublish": "rm -rf *.es5.js" | ||
"pretest": "npm run prepublish", | ||
"test": "ava", | ||
"prepublish": "babel --presets es2015 index.js --out-file index.es5.js", | ||
"postpublish": "rm -rf index.es5.js && git push --follow-tags" | ||
}, | ||
@@ -36,0 +38,0 @@ "author": "Andrey Polischuk <andre.polischuk@gmail.com>", |
23
test.js
import test from 'ava'; | ||
import {exec} from 'child_process'; | ||
const babel = __dirname + '/node_modules/.bin/babel-node'; | ||
import execa from 'execa'; | ||
test('should return last rates', t => { | ||
t.plan(2); | ||
exec(`${babel} cli.js`, {cwd: __dirname}, (err, stdout) => { | ||
t.ifError(err); | ||
t.true(stdout.trim().indexOf('USD') > 0); | ||
}); | ||
test('should return last rates', async t => { | ||
const {stdout} = await execa('./cli.js'); | ||
t.true(stdout.trim().indexOf('USD') > 0); | ||
}); | ||
test('should return rates for specified date', t => { | ||
t.plan(2); | ||
exec(`${babel} cli.js 2015.5.15`, {cwd: __dirname}, (err, stdout) => { | ||
t.ifError(err); | ||
t.true(stdout.trim().indexOf('USD') > 0); | ||
}); | ||
test('should return rates for specified date', async t => { | ||
const {stdout} = await execa('./cli.js', ['2015.5.15']); | ||
t.true(stdout.trim().indexOf('USD') > 0); | ||
}); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
9
5767
4
93
+ Addedcbr-rates@0.3.5(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcookiejar@2.1.4(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedform-data@1.0.0-rc4(transitive)
+ Addedformidable@1.2.6(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedobject-inspect@1.13.4(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedqs@6.14.0(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedsuperagent@2.3.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedcbr-rates@0.2.1(transitive)
- Removedcomponent-emitter@1.2.1(transitive)
- Removedcookiejar@2.0.6(transitive)
- Removedextend@3.0.0(transitive)
- Removedform-data@1.0.0-rc3(transitive)
- Removedformidable@1.0.17(transitive)
- Removedisarray@0.0.1(transitive)
- Removedmime@1.3.4(transitive)
- Removedqs@2.3.3(transitive)
- Removedreadable-stream@1.0.27-1(transitive)
- Removedreduce-component@1.0.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedsuperagent@1.8.5(transitive)
Updatedcbr-rates@^0.3.2