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

voc-cli

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

voc-cli - npm Package Compare versions

Comparing version 1.0.0 to 1.0.2

11

index.js

@@ -21,3 +21,3 @@ #!/usr/bin/env node

.usage('<words...>')
.option('-v, --version', "output the version number", version)
.version(pkg.version)
.option('-a, --audio <cli>', "the command line to play .mp3 audio. set defaults to 'afplay'", setAudioCli)

@@ -28,7 +28,2 @@ .option('-d, --dir <path>', "set the download directory. set defaults to '~/vocabulary'", setAudioDirectory)

function version() {
console.log(pkg.version);
}
function resetConfig() {

@@ -88,3 +83,5 @@ config = DEFAULT;

} catch (e) {
// audio is not found
if (e.code !== 'ENOENT') {
throw e;
}
}

@@ -91,0 +88,0 @@ }

{
"name": "voc-cli",
"version": "1.0.0",
"version": "1.0.2",
"description": "download and play English vocabularies' audio by command line",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,3 +11,3 @@ # voc

- [Yahoo](http://tw.dictionary.search.yahoo.com)
- ~~Google~~ (API has been changed)
- _Google_ (API has been changed)

@@ -17,3 +17,3 @@ ## Installation

```
$ npm install voc-cli -g
$ npm install -g voc-cli
```

@@ -29,3 +29,3 @@

-h, --help output usage information
-v, --version output the version number
-V, --version output the version number
-a, --audio <cli> the command line to play .mp3 audio. set defaults to 'afplay'

@@ -32,0 +32,0 @@ -d, --dir <path> set the download directory. set defaults to '~/vocabulary'

var fs = require('fs');
var urlParse = require('url').parse;
var http = require('http');
var https = require('https');
var path = require('path');

@@ -30,6 +32,21 @@ var Promise = require('promise');

return new Promise(function (resolve, reject) {
var file = fs.createWriteStream(dest);
var info = urlParse(url);
var httpClient = info.protocol === 'https:' ? https : http;
var options = {
host: info.host,
path: info.path,
headers: {
'user-agent': 'voc'
}
};
http.get(url, function(response) {
response.pipe(file);
httpClient.get(options, function(res) {
// check status code
if (res.statusCode !== 200) {
var msg = url + ', status code ' + res.statusCode + '(' + res.statusMessage + ')';
reject(new Error(msg));
return;
}
var file = fs.createWriteStream(dest);
file.on('finish', function() {

@@ -39,8 +56,14 @@ // close() is async, call resolve after close completes.

});
file.on('error', function (err) {
// Delete the file async. (But we don't check the result)
fs.unlink(dest);
reject(err);
});
res.pipe(file);
})
.on('error', function(err) {
// Delete the file async. (But we don't check the result)
fs.unlink(dest);
reject(err);
});
})
.end();
});

@@ -78,3 +101,5 @@ }

if (url === null) {
throw new Error(word + ' is not found');
var err = new Error(word + ' is not found');
err.code = 'ENOENT';
throw err;
}

@@ -81,0 +106,0 @@

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