Skip to content

Commit

Permalink
Added new routes for new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lizardgai4 committed Jun 12, 2024
1 parent ad8059b commit f00bb25
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ export const endpoints = {
version_url: `${API_BASE}/version`,
name_single_url: `${API_BASE}/name/single/{n}/{s}/{dialect}`,
name_full_url: `${API_BASE}/name/full/{ending}/{n}/{s1}/{s2}/{s3}/{dialect}`,
name_alu_url: `${API_BASE}/name/alu/{n}/{s}/{nm}/{am}/{dialect}`
name_alu_url: `${API_BASE}/name/alu/{n}/{s}/{nm}/{am}/{dialect}`,
homonyms_url: `${API_BASE}/homonyms`,
oddballs_url: `${API_BASE}/oddballs`,
multi_ipa_url: `${API_BASE}/multi-ipa`,
dict_len_url: `${API_BASE}/total-words`,
reef_ipa_url: `${API_BASE}/reef/{i}`,
validity_url: `${API_BASE}/valid/{i}`
}
90 changes: 90 additions & 0 deletions src/toybox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { endpoints } from './constants'
import type { Word } from './types'

/**
* Returns all the words with multiple IPAs
* @param {RequestInit | undefined} init fetch options (optional)
* @returns {Promise<Word[][]>}
*/
async function multiIPA(init?: RequestInit): Promise<Word[][]> {
const url = endpoints.multi_ipa_url
const response = await fetch(url, init)
const data = (await response.json()) as Word[][]
return data
}

/**
* Returns all the words which fall outside of normal Na'vi phonotactics
* @param {RequestInit | undefined} init fetch options (optional)
* @returns {Promise<Word[][]>}
*/
async function oddballs(init?: RequestInit): Promise<Word[][]> {
const url = endpoints.oddballs_url
const response = await fetch(url, init)
const data = (await response.json()) as Word[][]
return data
}

/**
* Returns all the words with more than one dictionary entry
* @param {RequestInit | undefined} init fetch options (optional)
* @returns {Promise<Word[][]>}
*/
async function homonyms(init?: RequestInit): Promise<Word[][]> {
const url = endpoints.oddballs_url
const response = await fetch(url, init)
const data = (await response.json()) as Word[][]
return data
}

/**
* Returns whether or not the given string is valid Na'vi
* @param {RequestInit | undefined} init fetch options (optional)
* @param {string} words words to search
* @returns {Promise<Word[][]>}
*/
async function valid(words: string, init?: RequestInit): Promise<String> {
const url = endpoints.validity_url.replace('{i}', words)
const response = await fetch(url, init)
const data = (await response.json()) as String
return data
}

/**
* Returns a string saying how long the dict is
* @param {RequestInit | undefined} init fetch options (optional)
* @returns {Promise<Word[][]>}
*/
async function dictLen(init?: RequestInit): Promise<String> {
const url = endpoints.dict_len_url
const response = await fetch(url, init)
const data = (await response.json()) as String
return data
}

/**
* Returns whether or not the given string is valid Na'vi
* @param {RequestInit | undefined} init fetch options (optional)
* @param {string} words words to search
* @returns {Promise<Word[][]>}
*/
async function reefMe(words: string, init?: RequestInit): Promise<String[]> {
const url = endpoints.reef_ipa_url.replace('{i}', words)
const response = await fetch(url, init)
const data = (await response.json()) as String[]
return data
}

/**
* Returns whether or not the given string is valid Na'vi
* @param {RequestInit | undefined} init fetch options (optional)
* @returns {Promise<Word[][]>}
*/
async function phonemeFrequency(init?: RequestInit): Promise<Map<string,Map<string,Map<string,number>>>> {
const url = endpoints.reef_ipa_url
const response = await fetch(url, init)
const data = (await response.json()) as Promise<Map<string,Map<string,Map<string,number>>>>
return data
}

export { multiIPA, oddballs, homonyms, valid, dictLen, reefMe, phonemeFrequency }

0 comments on commit f00bb25

Please sign in to comment.