#! /usr/bin/env node

const optimist = require('optimist').argv
const http = require('http')

if (!optimist.from && !optimist.f) {
  console.log('From param should be defined')
  process.exit()
}

var from = optimist.from ? optimist.from : optimist.f

from = from.toUpperCase()

if (!optimist.to && !optimist.t) {
  console.log('To param should be defined')
  process.exit()
}

var to = optimist.to ? optimist.to : optimist.t
to = to.toUpperCase()

let type = 'simple'

if (optimist.ouput || optimist.o) {
  if (optimist.ouput === 'full' || optimist.o === 'full') type = 'full'
};

let amount
process.argv.forEach(function (value) {
  if (!isNaN(parseFloat(value)) && isFinite(value)) {
    amount = value
  }
})

if (!amount) {
  console.log('Amount param should be defined')
  process.exit()
}

var code = from + '_' + to

http.get('http://free.currencyconverterapi.com/api/v3/convert?q=' + code + '&compact=ultra', (res) => {
  res.on('data', (data) => {
    data = JSON.parse(data)
    if (!data[code]) {
      console.log('Currency no supported or bad spell')
    } else {
    // raw response
      if (type === 'full') {
        console.log('Amount: ' + amount + ' ' + from)
        console.log('From: ' + from)
        console.log('To: ' + to)
        console.log('Current Rate: ' + data[code] + ' ' + to)
        console.log('Total: ' + amount * data[code] + ' ' + to)
      } else {
        console.log(amount * data[code] + ' ' + to)
      }
    }
  })
})

@@ -13,16 +13,29 @@
 env node
+%0A'use strict'
 %0A%0Aconst 
@@ -624,24 +624,18 @@
 ach(
-function 
 (value)
+ =%3E
  %7B%0A 
@@ -812,23 +812,23 @@
 e = 
+%60$%7B
 from
- + '_' + to
+%7D_$%7Bto%7D%60
 %0A%0Aht
@@ -1151,17 +1151,17 @@
 log(
-'
+%60
 Amount: 
 ' + 
@@ -1160,31 +1160,26 @@
 nt: 
-' + 
+$%7B
 amount
- + ' ' + 
+%7D $%7B
 from
+%7D%60
 )%0A  
@@ -1200,23 +1200,23 @@
 log(
-'
+%60
 From: 
-' + 
+$%7B
 from
+%7D%60
 )%0A  
@@ -1237,19 +1237,19 @@
 log(
-'
+%60
 To: 
-' + to
+$%7Bto%7D%60
 )%0A  
@@ -1262,25 +1262,25 @@
 console.log(
-'
+%60
 Current Rate
@@ -1281,20 +1281,18 @@
 t Rate: 
-' + 
+$%7B
 data%5Bcod
@@ -1289,35 +1289,32 @@
 $%7Bdata%5Bcode%5D
- + ' ' + to
+%7D $%7Bto%7D%60
 )%0A        co
@@ -1327,20 +1327,18 @@
 log(
-'
+%60
 Total: 
-' + 
+$%7B
 amou
@@ -1348,35 +1348,32 @@
 * data%5Bcode%5D
- + ' ' + to
+%7D $%7Bto%7D%60
 )%0A      %7D el
@@ -1397,16 +1397,19 @@
 ole.log(
+%60$%7B
 amount *
@@ -1423,19 +1423,16 @@
 ode%5D
- + ' ' + to
+%7D $%7Bto%7D%60
 )%0A  

Set strings contactenations with ec6