wordnik-api
Version:
Community API for https://wordnik.com with types
226 lines (225 loc) • 12.1 kB
TypeScript
import { PartOfSpeech } from "./struct/PartOfSpeech";
import Word from "./entity/Word";
import AudioMetadata from "./entity/AudioMetadata";
import Example from "./entity/Example";
import Frequency from "./entity/Frequency";
import Syllable from "./entity/Syllable";
import Phrase from "./entity/Phrase";
import Pronunciation from "./entity/Pronunciation";
import { RelationshipType } from "./struct/RelationshipType";
import RelatedWord from "./entity/RelatedWord";
import RandomWord from "./entity/RandomWord";
import WordOfTheDay from "./entity/WordOfTheDay";
/**
* Defines the WordnikAPI class.
*/
export default class WordnikAPI {
private static readonly BASE_URL;
private static readonly WORDS_URL;
private readonly API_KEY;
/**
* Constructs a new WordnikAPI instance.
* @param API_KEY {string} The API key to use.
*/
constructor(API_KEY: string);
/**
* Make an API call to the Wordnik API.
*
* @param endpoint {string} The endpoint to call.
* @param params {object} The parameters to pass to the endpoint.
* @param base_url {string} The base URL to use (optional).
*
* @private
*/
private makeRequest;
/**
* Gets the API key.
*
* @returns {string} The API key.
*/
getAPIKey(): string;
/**
* Get definitions for a word.
*
* https://developer.wordnik.com/docs#!/word/getDefinitions
*
* @param word {string} The word to get definitions for.
* @param limit {number} The limit of definitions to get.
* @param partOfSpeech {PartOfSpeech} The part of speech to get definitions for.
* @param sourceDictionary {"all" | "ahd-5" | "century" | "wiktionary" | "webster" | "wordnet"} The source dictionary to get definitions for.
* @param useCanonical {boolean} Whether to use the canonical form of the word (e.g. "cats" -> "cat").
* @param includeTags {boolean} Whether to include tags in the response.
*
* @returns {Promise<Word[] | null>} The definitions for the word, or null if the word is not found.
*/
getDefinitions(word: string, limit?: number, partOfSpeech?: PartOfSpeech[] | PartOfSpeech | undefined, sourceDictionary?: "all" | "ahd-5" | "century" | "wiktionary" | "webster" | "wordnet", useCanonical?: boolean, includeTags?: boolean): Promise<Word[] | null>;
/**
* Get the audio metadata for a word.
*
* https://developer.wordnik.com/docs#!/word/getAudio
*
* @param word {string} The word to get audio metadata for.
* @param useCanonical {boolean} Whether to use the canonical form of the word (e.g. "cats" -> "cat").
* @param limit {number} The limit of audio metadata to get.
*
* @returns {Promise<AudioMetadata[] | null>} The audio metadata for the word, or null if the word is not found.
*/
getAudio(word: string, useCanonical?: boolean, limit?: number): Promise<AudioMetadata[] | null>;
/**
* Get the etymologies for a word.
*
* https://developer.wordnik.com/docs#!/word/getEtymologies
*
* @param word {string} The word to get etymologies for.
* @param useCanonical {boolean} Whether to use the canonical form of the word (e.g. "cats" -> "cat").
*
* @returns {Promise<string[] | null>} The etymologies for the word, or null if the word is not found.
*/
getEtymologies(word: string, useCanonical?: boolean): Promise<string[] | null>;
/**
* Get examples of a word's usage.
*
* https://developer.wordnik.com/docs#!/word/getExamples
*
* @param word {string} The word to get examples for.
* @param includeDuplicates {boolean} Whether to include duplicate examples.
* @param useCanonical {boolean} Whether to use the canonical form of the word (e.g. "cats" -> "cat").
* @param skip {number} The number of examples to skip.
* @param limit {number} The limit of examples to get (max 50).
*
* @returns {Promise<Example[] | null>} The examples for the word, or null if the word is not found.
*/
getExamples(word: string, includeDuplicates?: boolean, useCanonical?: boolean, skip?: number, limit?: number): Promise<Example[] | null>;
/**
* Get the frequency of a word.
*
* https://developer.wordnik.com/docs#!/word/getWordFrequency
*
* @param word {string} The word to get the frequency of.
* @param useCanonical {boolean} Whether to use the canonical form of the word (e.g. "cats" -> "cat").
* @param startYear {number} The start year to get the frequency of.
* @param endYear {number} The end year to get the frequency of.
*
* @returns {Promise<Frequency[] | null>} The frequency of the word, or null if the word is not found.
*/
getFrequency(word: string, useCanonical?: boolean, startYear?: number, endYear?: number): Promise<Frequency[] | null>;
/**
* Get the word's hyphenation.
*
* https://developer.wordnik.com/docs#!/word/getHyphenation
*
* @param word {string} The word to get the hyphenation of.
* @param useCanonical {boolean} Whether to use the canonical form of the word (e.g. "cats" -> "cat").
* @param sourceDictionary {string} The source dictionary to get the hyphenation of.
* @param limit {number} The limit of hyphenations to get.
*
* @returns {Promise<Syllable[] | null>} The word's hyphenation.
*/
getHyphenation(word: string, useCanonical?: boolean, sourceDictionary?: "all" | "ahd-5" | "century" | "wiktionary" | "webster" | "wordnet", limit?: number): Promise<Syllable[] | null>;
/**
* Get word phrases
*
* https://developer.wordnik.com/docs#!/word/getPhrases
*
* @param word {string} The word to get the phrases of.
* @param useCanonical {boolean} Whether to use the canonical form of the word (e.g. "cats" -> "cat").
* @param limit {number} The limit of phrases to get.
*
* @returns {Promise<Phrase[] | null>} The word's phrases.
*/
getPhrases(word: string, useCanonical?: boolean, limit?: number): Promise<Phrase[] | null>;
/**
* Get the word's Pronunciation.
*
* https://developer.wordnik.com/docs#!/word/getTextPronunciations
*
* @param word {string} The word to get the pronunciation of.
* @param useCanonical {boolean} Whether to use the canonical form of the word (e.g. "cats" -> "cat").
* @param sourceDictionary {string} The source dictionary to get the pronunciation of.
* @param typeFormat {string} The type of pronunciation to get.
* @param limit {number} The limit of pronunciations to get.
*
* @returns {Promise<Pronunciation[] | null>} The word's Pronunciation.
*/
getPronunciation(word: string, useCanonical?: boolean, sourceDictionary?: "ahd-5" | "century" | "wiktionary" | "webster" | "wordnet" | undefined, typeFormat?: "ahd-5" | "arpabet" | "gcide-diacritical" | "IPA" | undefined, limit?: number): Promise<Pronunciation[] | null>;
/**
* Get related words.
*
* https://developer.wordnik.com/docs#!/word/getRelatedWords
*
* @param word {string} The word to get related words for.
* @param useCanonical {boolean} Whether to use the canonical form of the word (e.g. "cats" -> "cat").
* @param relationshipTypes {RelationshipType | undefined} The relationship types to get.
* @param limitPerRelationshipType {number} The limit of related words to get per relationship type.
* @returns {Promise<RelatedWord[] | null>} The related words or null if an error occurred.
*/
getRelatedWords(word: string, useCanonical?: boolean, relationshipTypes?: RelationshipType | undefined, limitPerRelationshipType?: number | undefined): Promise<RelatedWord[] | null>;
/**
* Get the scrabble score of a word.
* You may want to lowercase the word before passing it in.
*
* https://developer.wordnik.com/docs#!/word/getScrabbleScore
*
* @param word {string} The word to get the scrabble score of.
*
* @returns {Promise<number | null>} The scrabble score of the word, or null if the word is not found.
*/
getScrabbleScore(word: string): Promise<number | null>;
/**
* Get the top example of a word.
*
* https://developer.wordnik.com/docs#!/word/getTopExample
*
* @param word {string} The word to get the top example of.
* @param useCanonical {boolean} Whether to use the canonical form of the word (e.g. "cats" -> "cat").
*
* @returns {Promise<Example | null>} The top example of the word, or null if the word is not found.
*/
getTopExample(word: string, useCanonical?: boolean): Promise<Example | null>;
/**
* Get a random word.
*
* https://developer.wordnik.com/docs#!/words/getRandomWord
*
* @param hasDictionaryDef {"true" | "false"} Only return words with dictionary definitions
* @param includePartOfSpeech {PartOfSpeech | undefined} Only return words with the specified part of speech.
* @param excludePartOfSpeech {PartOfSpeech | undefined} Only return words without the specified part of speech.
* @param minCorpusCount {number | undefined} Minimum corpus frequency for terms
* @param maxCorpusCount {number | undefined} Maximum corpus frequency for terms
* @param minDictionaryCount {number | undefined} Minimum dictionary count
* @param maxDictionaryCount {number | undefined} Maximum dictionary count
* @param minLength {number | undefined} Minimum word length
* @param maxLength {number | undefined} Maximum word length
*/
getRandomWord(hasDictionaryDef?: "true" | "false", includePartOfSpeech?: PartOfSpeech | undefined, excludePartOfSpeech?: PartOfSpeech | undefined, minCorpusCount?: number | undefined, maxCorpusCount?: number | undefined, minDictionaryCount?: number | undefined, maxDictionaryCount?: number | undefined, minLength?: number | undefined, maxLength?: number | undefined): Promise<RandomWord | null>;
/**
* Get random words.
*
* https://developer.wordnik.com/docs#!/words/getRandomWords
*
* @param hasDictionaryDef {"true" | "false"} Only return words with dictionary definitions
* @param includePartOfSpeech {PartOfSpeech[] | undefined} Only return words with the specified part of speech.
* @param excludePartOfSpeech {PartOfSpeech[] | undefined} Only return words without the specified part of speech.
* @param minCorpusCount {number | undefined} Minimum corpus frequency for terms
* @param maxCorpusCount {number | undefined} Maximum corpus frequency for terms
* @param minDictionaryCount {number | undefined} Minimum dictionary count
* @param maxDictionaryCount {number | undefined} Maximum dictionary count
* @param minLength {number | undefined} Minimum word length
* @param maxLength {number | undefined} Maximum word length
* @param sortBy {"alpha" | "count" | undefined} Sort by
* @param sortOrder {"asc" | "desc" | undefined} Sort order
* @param limit {number | undefined} Limit
*
* @returns {Promise<RandomWord[]>} Random words, or an empty array if no words were found.
*/
getRandomWords(hasDictionaryDef?: "true" | "false", includePartOfSpeech?: PartOfSpeech[] | undefined, excludePartOfSpeech?: PartOfSpeech[] | undefined, minCorpusCount?: number | undefined, maxCorpusCount?: number | undefined, minDictionaryCount?: number | undefined, maxDictionaryCount?: number | undefined, minLength?: number | undefined, maxLength?: number | undefined, sortBy?: "alpha" | "count" | undefined, sortOrder?: "asc" | "desc" | undefined, limit?: number): Promise<RandomWord[]>;
/**
* Get the word of the day.
*
* https://developer.wordnik.com/docs#!/words/getWordOfTheDay
*
* @param date {Date | string | undefined} the Date to get the word of the day for, a string in the format yyyy-MM-dd, or undefined to get the word of the day for today.
* @returns {Promise<WordOfTheDay | null>}
*/
getWordOfTheDay(date?: string | Date | undefined): Promise<WordOfTheDay | null>;
}