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

thesaurus-com

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thesaurus-com - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

.eslintrc.json

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 @@

@@ -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);
});
});
});
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