#!/usr/bin/env node

const meow = require('meow')
const speedTest = require('speedtest-net')
const updateNotifier = require('update-notifier')

// silly usage for tests
const cli = new meow([
  'Usage'
])

// check for updates
updateNotifier({ pkg: cli.pkg }).notify()

let st = speedTest({ maxTime: 15000 })

st.on('data', data => {
  let download = data.speeds.download
  let upload = data.speeds.upload

  console.log('Download speed: ' + download + 'kB/s')
  console.log('Upload speed: ' + upload + 'kB/s')

  console.log({data})
})

st.on('downloadprogress', progress => {
  console.log('Download progress -> ' + progress + '%')
})

st.on('uploadprogress', progress => {
  console.log('Upload progress -> ' + progress + '%')
})

st.on('error', err => {
  console.error(err)
})

@@ -252,16 +252,18 @@
 i.pkg %7D)
+  
 .notify(
@@ -299,10 +299,10 @@
 me: 
-15
+20
 000 
@@ -342,24 +342,25 @@
  download = 
+(
 data.speeds.
@@ -367,16 +367,34 @@
 download
+ * 100).toFixed(2)
 %0A  let u
@@ -401,16 +401,17 @@
 pload = 
+(
 data.spe
@@ -420,17 +420,99 @@
 s.upload
-%0A
+ * 100).toFixed(2)%0A  let ping = data.server.ping%0A%0A  console.log('%5CnFinal results:')
 %0A  conso
@@ -547,24 +547,25 @@
 download + '
+ 
 kB/s')%0A  con
@@ -606,17 +606,63 @@
  + '
+ 
 kB/s')%0A
-%0A
  
+ console.log('Latency: ' + ping + ' ms')%0A%0A  //
  con
@@ -693,24 +693,29 @@
 on('download
+speed
 progress', p
@@ -709,32 +709,29 @@
 dprogress', 
-progress
+speed
  =%3E %7B%0A  cons
@@ -751,45 +751,53 @@
 load
- progress -%3E ' + progress + '%25
+: ' + (speed * 100).toFixed(2) + ' kB/s
 ')%0A%7D)%0A
-%0A
 st.o
@@ -805,16 +805,21 @@
 ('upload
+speed
 progress
@@ -821,24 +821,21 @@
 gress', 
-progress
+speed
  =%3E %7B%0A  
@@ -857,38 +857,47 @@
 load
- progress -%3E ' + progress + '%25
+: ' + (speed * 100).toFixed(2) + ' kB/s
 ')%0A%7D

fix errors with speed