Socket
Socket
Sign inDemoInstall

mw-dictionary

Package Overview
Dependencies
25
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

47

dictionary.js

@@ -22,15 +22,36 @@ // Endpoints

//remove erroneous results (doodle != Yankee Doodle)
var entries = result.entry_list.entry;
for (var i=0; i<entries.length; i++){
if (entries[i].ew == word) {
if (result.entry_list.entry != undefined) {
var entries = result.entry_list.entry;
for (var i=0; i<entries.length; i++){
//construct a more digestable object
results.push({
partOfSpeech: entries[i].fl,
definition: entries[i].def[0].dt
});
//remove erroneous results (doodle != Yankee Doodle)
if (entries[i].ew == word) {
//construct a more digestable object
var definition = entries[i].def[0].dt;
var partOfSpeech = entries[i].fl;
switch (typeof definition) {
case "object":
for (var i=0; i<definition.length; i++){
var definitionStr = "";
if (definition[i]["_"].length > 1) definitionStr += " "+definition[i]["_"];
}
definition = definitionStr;
break;
case "string":
default:
break;
}
results.push({
partOfSpeech: partOfSpeech,
definition: definition
});
}
}
callback(null, results);
}
callback(null, results);
else if (result.entry_list.suggestion != undefined) {
callback('suggestions', result.entry_list.suggestion);
}
}

@@ -47,3 +68,7 @@ else callback(error);

if (error === null) callback(null, result);
else callback('XML Parsing error.');
else if (response.statusCode != 200) console.log(response.statusCode);
else {
console.log(error);
callback('XML Parsing error.');
}
});

@@ -50,0 +75,0 @@ }

//To run:
// $ node example.js [your-merriam-webster-api-key]
// $ node example.js [your-merriam-webster-api-key] [word]

@@ -12,3 +12,3 @@ var Dictionary = require('./dictionary'),

//sample method
dict.define('doodle', function(error, result){
dict.define(process.argv[3], function(error, result){
if (error == null) {

@@ -19,5 +19,18 @@ for(var i=0; i<result.length; i++){

console.log('Definitions: '+result[i].definition);
console.log(result[i].definition)
}
}
else if (error === "suggestions"){
console.log(process.argv[3] + ' not found in dictionary. Possible suggestions:');
for (var i=0; i<result.length; i++){
console.log(result[i]);
}
}
else console.log(error);
});
//test words
// charlatan
// patutukis
// doodle

@@ -5,3 +5,3 @@ {

"description": "Simple wrapper for the Merriam-Webster dictionary API found at dictionaryapi.com",
"version": "0.0.3",
"version": "0.0.4",
"keywords": [

@@ -8,0 +8,0 @@ "dictionary",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc