Skip to content

Instantly share code, notes, and snippets.

@carbide-public
Created May 3, 2026 05:00
Show Gist options
  • Select an option

  • Save carbide-public/7559696f1d61dd11235e1283aaf47ea3 to your computer and use it in GitHub Desktop.

Select an option

Save carbide-public/7559696f1d61dd11235e1283aaf47ea3 to your computer and use it in GitHub Desktop.
untitled
let word = "gehen"
let endpoint = 'https://en.wiktionary.org/api/rest_v1/page/definition'
let filter = new RegExp('< *\\/? *[a-z]+ *( [a-z]+="[^<>"]+" *)* *\\/? *>', 'ig')
let url = `${endpoint}/${word}`
let resObj = await fetch(url, {orgin:'test'})
let res = await resObj.json()
function cleanString(str) {
return str.replaceAll(filter, '').replaceAll('&nbsp;', ' ')
}
let output = ''
for (let meaning of res.en) {
output += meaning.partOfSpeech
for (let definition of meaning.definitions) {
if (definition.definition) {
let filteredDefinition = cleanString(definition.definition)
output += `\n- ${filteredDefinition}`
if (definition.examples) {
for (let example of definition.examples) {
let filteredExample = cleanString(example)
output += `\n "${filteredExample}"`
}
}
}
}
output += '\n\n'
}
output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment