UNPKG

wordreference-definition-api

Version:

Scrap word definitions from http://www.wordreference.com

72 lines (56 loc) 2.19 kB
# wordreference-definition-api # Example with cache ``` const { wrDefinition } = require('wordreference-definition-api') let def = wrDefinition() console.time('scream') def.define('scream').then(data => { console.log(data) console.timeEnd('scream') console.time('screamCache') def.define('scream').then(() => { console.timeEnd('screamCache') }) }) /* OUTPUTS: [{ class: "v.", defs: [ { def: "to make a loud, sharp cry: ", examples: [ "[no object]screamed with fright.", ] }, ] }] scream: 2500.78ms got from cache screamCache: 27.009ms */ ``` # Simple documentation ``` //defaults let definition = wrDefinition({cache: { dir: path.join(__dirname, 'cache'), //you can choose which directory you want to save the cache keyEncoding: 'utf8', //the key of the cache valueEncoding: 'json', //store the cache as json use: true //wheter you want to use cache or not }, logs: false, //shows logs on the console URL: 'https://www.wordreference.com/definition/' //just in case they change the routes, I hope they don't change the html }) //wrDefinition returns Definition class, those are the methods definition.define(word) //return Promise, if it don't find any word, resolve empty array definition.clearCache(word) //remove one word from the cache definition.clearCache() //clean the entire cache ``` # Questions: #### What is it ? This is a js api that grabs/scrap definitions of a given word from [wordreference](https://www.wordreference.com) #### Is it ready for production ? I'm using this on my personal software, but I don't guarantee that you are going to get definition for all words, if the word exists on their website #### Can I use it in a browser ? This is not intended to be used on the browser, an alternative would be to use the old version 2 of this API, please test the 2 version of this software before using it # Cache This api contains a built-in cache created with [leveldb](https://npmjs.com/package/level), you can choose to not use this cache by passing extra arguments, see the docs.