thesaurus-com
Advanced tools
Comparing version 1.0.3 to 1.1.0
74
index.js
@@ -1,64 +0,32 @@ | ||
#!/usr/bin/env node | ||
/*global $:true */ | ||
var request = require('request'); | ||
var cheerio = require('cheerio'); | ||
const request = require('sync-request'); | ||
const cheerio = require('cheerio'); | ||
function help_me() { | ||
var path = require('path'); | ||
console.log([ | ||
'usage: ' + path.basename(process.argv[1]) + ' [-j|-h] <query>', | ||
'', | ||
'options:', | ||
'', | ||
' -j|--json return JSON', | ||
' -h|--help show this help', | ||
'' | ||
].join('\n')); | ||
process.exit(1); | ||
} | ||
function search(query) { | ||
const url = 'http://www.thesaurus.com/browse/' + encodeURIComponent(query); | ||
const req = request('GET', url); | ||
var args = process.argv.slice(2); | ||
var output_json = 0; | ||
if (req.statusCode !== 200) { | ||
return {synonyms: [], antonyms: []}; | ||
} | ||
switch (args[0]) { | ||
case '-j': | ||
case '--json': | ||
output_json = 1; | ||
args.shift(); | ||
break; | ||
case '-h': | ||
case '--help': | ||
help_me(); | ||
} | ||
$ = cheerio.load(req.getBody(), { ignoreWhitespace: true }); | ||
if (args.length == 0) { | ||
help_me(); | ||
} | ||
var url = 'http://www.thesaurus.com/browse/' + encodeURIComponent(args.join(' ')); | ||
request(url, function(err, resp, body){ | ||
$ = cheerio.load(body, { ignoreWhitespace: true }); | ||
var synonyms = $('div.relevancy-list ul li a span.text'); | ||
var synonyms = synonyms.map(function(_i, _element){ | ||
let synonyms = $('div.relevancy-list ul li a span.text'); | ||
synonyms = synonyms.map(function() { | ||
return $(this).text(); | ||
}).get().sort(); | ||
var antonyms = $('div.list-holder ul li a span.text'); | ||
var antonyms = antonyms.map(function(_i, _element){ | ||
let antonyms = $('div.list-holder ul li a span.text'); | ||
antonyms = antonyms.map(function() { | ||
return $(this).text(); | ||
}).get().sort(); | ||
if (output_json) { | ||
console.log(JSON.stringify({ | ||
synonyms: synonyms, | ||
antonyms: antonyms | ||
})); | ||
} else { | ||
console.log('Synonyms: ' + synonyms.join(', ')); | ||
if (antonyms.length > 0) { | ||
console.log('Antonyms: ' + antonyms.join(', ')); | ||
} | ||
} | ||
}); | ||
return { | ||
synonyms: synonyms, | ||
antonyms: antonyms | ||
}; | ||
} | ||
exports.search = search; |
{ | ||
"name": "thesaurus-com", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Lookup synonyms and antonyms from thesaurus.com.", | ||
"main": "index.js", | ||
"bin": { | ||
"tcom": "./index.js" | ||
"tcom": "./tcom.js" | ||
}, | ||
"dependencies": { | ||
"cheerio": "^0.22.0", | ||
"request": "^2.75.0" | ||
"sync-request": "^3.0.1" | ||
}, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"eslint": "^3.8.1", | ||
"mocha": "^3.1.2" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "eslint *.js && mocha test.js" | ||
}, | ||
@@ -17,0 +20,0 @@ "repository": { |
@@ -0,1 +1,2 @@ | ||
[![Build Status](https://travis-ci.org/mhinz/node-thesaurus-com.svg?branch=master)](https://travis-ci.org/mhinz/node-thesaurus-com) | ||
[![npm](https://img.shields.io/npm/v/thesaurus-com.svg)](https://www.npmjs.com/package/thesaurus-com) | ||
@@ -2,0 +3,0 @@ |
42
test.js
@@ -1,7 +0,39 @@ | ||
var assert = require('assert'); | ||
var assert = require('thesaurus'); | ||
const assert = require('assert'); | ||
const tcom = require('./index.js'); | ||
describe('tcom', function() { | ||
describe('never', function() { | ||
const output_for_never = { | ||
synonyms: ["at no time", "don\'t hold your breath"], | ||
antonyms: ["always", "forever"] | ||
}; | ||
describe('tcom.search()', function() { | ||
describe('with argument "never"', function() { | ||
it('should return synonyms and antonyms', function() { | ||
assert.equal( | ||
const matches = tcom.search("never"); | ||
assert.deepEqual(output_for_never.synonyms, matches.synonyms.slice(0,2)); | ||
assert.deepEqual(output_for_never.antonyms, matches.antonyms.slice(0,2)); | ||
}); | ||
}); | ||
describe('with argument "foo"', function() { | ||
it('should return only synonyms', function() { | ||
const matches = tcom.search("foo"); | ||
assert.notEqual(0, matches.synonyms.length); | ||
assert.equal(0, matches.antonyms.length); | ||
}); | ||
}); | ||
describe('with argument "fooo"', function() { | ||
it('should return nothing', function() { | ||
const matches = tcom.search("fooo"); | ||
assert.deepEqual({ synonyms: [], antonyms: [] }, matches); | ||
}); | ||
}); | ||
describe('with argument ""', function() { | ||
it('should return nothing', function() { | ||
const matches = tcom.search(""); | ||
assert.deepEqual({ synonyms: [], antonyms: [] }, matches); | ||
}); | ||
}); | ||
}); |
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 tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
6641
9
129
0
27
2
+ Addedsync-request@^3.0.1
+ Addedasap@2.0.6(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcaseless@0.11.0(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-basic@2.5.1(transitive)
+ Addedhttp-response-object@1.1.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpromise@7.3.1(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedsync-request@3.0.1(transitive)
+ Addedthen-request@2.2.0(transitive)
+ Addedtypedarray@0.0.6(transitive)
- Removedrequest@^2.75.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.10.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)