export type GetApiApiIdnitsArgs = {url: string, verbose?: number | undefined, hidetext?: string | undefined, year?: number | undefined, submitcheck?: string | undefined}; export type GetApiApiIdnitsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get idnits output * * GET /api/idnits */ export const getApiApiIdnits = async (args: GetApiApiIdnitsArgs, options?: GetApiApiIdnitsOptions) => { const {baseUrl = "https://author-tools.ietf.org", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/plain") if (args.url != null) query.append("url", String(args.url)) if (args.verbose != null) query.append("verbose", String(args.verbose)) if (args.hidetext != null) query.append("hidetext", String(args.hidetext)) if (args.year != null) query.append("year", String(args.year)) if (args.submitcheck != null) query.append("submitcheck", String(args.submitcheck)) const url = `${baseUrl.replace(/\/+$/, '')}/api/idnits${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 res.text() };