oxford-dictionary-api-client
Version:
A Node.js and browser wrapper for Oxford Dictionary API
2 lines (1 loc) • 2.94 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=e=>Array.isArray(e)?e.join(","):String(e),i=(e={})=>{const t=Object.entries(e).filter(([,r])=>r!==void 0).map(([r,s])=>[r,p(s)]);return new URLSearchParams(t).toString()},c=(e,t)=>t?`${e}?${t}`:e,u=e=>{const t=e.findIndex(s=>!s);return(t===-1?e:e.slice(0,t)).join("/")};class ${#t;#r;constructor(t,r){this.#t=r,this.#r=t}async request(t){try{const r={"Content-Type":"application/json"},s={...this.#t,...r},o=`${this.#r}${t}`,n=await fetch(o,{headers:s});if(!n.ok)throw await n.json();return n.json()}catch(r){throw console.error(r),r}}async entries(t,r,s={}){const o=i(s),n=`/entries/${t}/${r}`,a=c(n,o);return this.request(a)}async translations(t,r,s,o={}){const n=i(o),a=`/translations/${t}/${r}/${s}`,l=c(a,n);return this.request(l)}async words(t,r,s={}){const o=i({...s,q:r}),n=`/words/${t}`,a=c(n,o);return this.request(a)}async lemmas(t,r,s={}){const o=i(s),n=`/lemmas/${t}/${r}`,a=c(n,o);return this.request(a)}async inflections(t,r,s={}){const o=i(s),n=`/inflections/${t}/${r}`,a=c(n,o);return this.request(a)}async thesaurus(t,r,s={}){const o=i(s),n=`/thesaurus/${t}/${r}`,a=c(n,o);return this.request(a)}async sentences(t,r,s={}){const o=i(s),n=`/sentences/${t}/${r}`,a=c(n,o);return this.request(a)}utility={dictionaryNames:({targetLang:t,sourceLang:r})=>{const s=i({targetLang:t,sourceLang:r}),n=c("/languages",s);return this.request(n)},filters:t=>{const r=u(["/filters",t]);return this.request(r)},fields:t=>{const r=u(["/fields",t]);return this.request(r)},lexicalCategories:(t,r)=>{const s=u(["/lexicalCategories",t,r]);return this.request(s)},registers:(t,r)=>{const s=u(["/registers",t,r]);return this.request(s)},domains:(t,r)=>{const s=u(["/domains",t,r]);return this.request(s)},grammaticalFeatures:(t,r)=>{const s=u(["/grammaticalFeatures",t,r]);return this.request(s)}};search={entries:(t,r,s={})=>{const o=i({...s,q:r}),n=`/search/${t}`,a=c(n,o);return this.request(a)},thesaurus:(t,r,s={})=>{const o=i({...s,q:r}),n=`/search/thesaurus/${t}`,a=c(n,o);return this.request(a)},translations:(t,r,s,o={})=>{const n=i({...o,q:s}),a=`/search/translations/${t}/${r}`,l=c(a,n);return this.request(l)}}}var h=(e=>(e.Headword="headword",e.Inflection="inflection",e.Phrase="phrase",e))(h||{}),d=(e=>(e.Ipa="ipa",e.DictionarySpecific="dictionarySpecific",e.OupToneCode="oupToneCode",e))(d||{}),q=(e=>(e.Pre="pre",e.Post="post",e))(q||{}),g=(e=>(e.CloseMatch="close match",e.Related="related",e.SeeAlso="see also",e.VariantSpelling="variant spelling",e.Abbreviation="abbreviation",e))(g||{}),y=(e=>(e.GrammaticalNote="grammaticalNote",e.UsageNote="usageNote",e.EditorialNote="editorialNote",e.EncyclopedicNote="encyclopedicNote",e.EtymologyNote="etymologyNote",e.TechnicalNote="technicalNote",e))(y||{});exports.CollocationType=q;exports.CrossReferenceType=g;exports.EntryType=h;exports.NoteType=y;exports.OxfordDictionary=$;exports.ToneType=d;