NdYAG / mw-dict

Node.js wrapper of Merriam Webster Dictionary & Thesaurus Developer API
MIT License
10 stars 1 forks source link
dictionary english merriam-webster

mw-dict

Node.js Wrapper for Merriam Webster Dictionary Developer API

Preview:

'screen shot'

Note: Please get your API Key from Merriam-Webster's Developer Center

install

npm install mw-dict

usage

import { CollegiateDictionary, LearnersDictionary, CollegiateThesaurus } from 'mw-dict'

const dict = new CollegiateDictionary(API_KEY)
// const dict = new LearnersDictionary(API_KEY)
// const thesaurus = new CollegiateThesaurus(API_KEY)

dict
  .lookup(QUERY_WORD)
  .then(result => {})
  .catch(error => {})

result interface

// result: Definition[]
// Definition
{
  word: String,
  functional_label: String,
  pronunciation: String[],
  definition: Sense[],
  popularity: String
}
// Sense
{
  number: String,
  meanings: String[],
  synonyms: String[],
  antonyms: String[],
  illustrations: String[],
  senses: Sense[]
}

Error handler

import { WordNotFoundError } from 'mw-dict'

dict
  .lookup(QUERY_WORD)
  .catch(error => {
    if (error instanceof WordNotFoundError) {
      // error.suggestion
    }
  })