Skip to content

Commit

Permalink
feat: create etymolgies endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ArkhamCookie authored and ArkhamCookie committed Mar 19, 2024
1 parent 14d1b26 commit 86b1a1d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/word/etymologies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Wordnik } from '../mod'

/**
* Etymologies
* @param {string} word
* @param {*} options
* @param {boolean} [useCanonical=false]
* @returns {json} response
*/
export async function etymologies(word, {
useCanonical
}) {
if (!word) throw new Error('word is required')
const wordnik = new Wordnik('word.json/' + word + '/etymologies')
let endpoint =
wordnik.base + wordnik.version + wordnik.target

if (useCanonical) {
if (!(typeof useCanonical === 'boolean')) {
throw new Error('"useCanonical" must be a boolean')
}
endpoint = endpoint + '&' + 'useCanonical=' + useCanonical
}

endpoint = endpoint + '&' + wordnik.key
const response = await fetch(endpoint)

return await response.json()
}

0 comments on commit 86b1a1d

Please sign in to comment.