cbr-rates-cli
Advanced tools
Comparing version 0.3.0 to 1.0.0
@@ -25,25 +25,33 @@ 'use strict'; | ||
var cli = (0, _meow2.default)('\n Usage\n cbr-rates [id] [date]\n\n Examples\n cbr-rates\n cbr-rates usd\n cbr-rates 2014.5.12\n'); | ||
var cli = (0, _meow2.default)('\n Usage\n cbr-rates [...id] [date]\n\n Examples\n cbr-rates\n cbr-rates usd eur\n cbr-rates 2014.5.12\n'); | ||
var currencyId = cli.input[0]; | ||
var dateString = cli.input[1]; | ||
var _cli$input$slice = cli.input.slice(-1); | ||
if (/\./.test(currencyId)) { | ||
var _ref = [dateString, currencyId]; | ||
currencyId = _ref[0]; | ||
dateString = _ref[1]; | ||
var _cli$input$slice2 = _slicedToArray(_cli$input$slice, 1); | ||
var last = _cli$input$slice2[0]; | ||
var ids = cli.input.map(function (id) { | ||
return id.toLowerCase(); | ||
}); | ||
var date = undefined; | ||
if (/\./g.test(last)) { | ||
ids = ids.slice(0, -1); | ||
date = parseDateString(last); | ||
} | ||
var date = parseDateString(dateString); | ||
(0, _cbrRates2.default)(date).then(function (rates) { | ||
var _Math; | ||
var values = Object.keys(rates).map(function (id) { | ||
var values = Object.keys(rates).filter(function (id) { | ||
return isIdExist(id, ids); | ||
}).map(function (id) { | ||
return rates[id].value; | ||
}); | ||
var length = integerLength((_Math = Math).max.apply(_Math, _toConsumableArray(values))); | ||
Object.keys(rates).forEach(function (id) { | ||
if (currencyId && currencyId !== id) return; | ||
if (!isIdExist(id, ids)) return; | ||
var _rates$id = rates[id]; | ||
@@ -54,5 +62,4 @@ var par = _rates$id.par; | ||
var indent = length - integerLength(value); | ||
id = id.toUpperCase(); | ||
value = (0, _indentString2.default)(value.toFixed(2), ' ', indent); | ||
console.log(id + ' ' + _chalk2.default.bold(value) + ' ' + _chalk2.default.grey(par)); | ||
console.log(id.toUpperCase() + ' ' + _chalk2.default.bold(value) + ' ' + _chalk2.default.grey(par)); | ||
}); | ||
@@ -62,12 +69,10 @@ }); | ||
function parseDateString(str) { | ||
if (!str) return; | ||
var _str$split = str.split('.'); | ||
var _dateString$split = dateString.split('.'); | ||
var _str$split2 = _slicedToArray(_str$split, 3); | ||
var _dateString$split2 = _slicedToArray(_dateString$split, 3); | ||
var year = _str$split2[0]; | ||
var month = _str$split2[1]; | ||
var day = _str$split2[2]; | ||
var year = _dateString$split2[0]; | ||
var month = _dateString$split2[1]; | ||
var day = _dateString$split2[2]; | ||
return new Date(parseInt(year), parseInt(month) - 1, parseInt(day)); | ||
@@ -79,1 +84,5 @@ } | ||
} | ||
function isIdExist(id, ids) { | ||
return !ids.length || ids.indexOf(id) > -1; | ||
} |
{ | ||
"name": "cbr-rates-cli", | ||
"description": "Get currency rates from Central Bank of Russia", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "cbr", |
@@ -21,7 +21,7 @@ # cbr-rates-cli [![Build Status][travis-image]][travis-url] | ||
Usage | ||
cbr-rates [id] [date] | ||
cbr-rates [...id] [date] | ||
Examples | ||
cbr-rates | ||
cbr-rates usd | ||
cbr-rates usd eur | ||
cbr-rates 2014.5.12 | ||
@@ -28,0 +28,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4559
61
1