export type GetApiTranslateSithArgs = {text: unknown}; export type GetApiTranslateSithOptions = {baseUrl?: string | undefined, XFuntranslationsApiSecret?: string | undefined, fetch?: typeof fetch | undefined}; /** * Translate from English to Sith Speak. * * GET /translate/sith */ export const getApiTranslateSith = async (args: GetApiTranslateSithArgs, options?: GetApiTranslateSithOptions) => { const {baseUrl = "https://api.funtranslations.com", fetch: fetchFn = fetch, XFuntranslationsApiSecret} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.text != null) query.append("text", String(args.text)) if (XFuntranslationsApiSecret !== undefined) headers.set("X-Funtranslations-Api-Secret", XFuntranslationsApiSecret) const url = `${baseUrl.replace(/\/+$/, '')}/translate/sith${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return (await res.json()) as unknown };