export type GetApiBadgeWikiOwnerRepoSvgArgs = {owner: string, repo: string, style?: string | undefined}; export type GetApiBadgeWikiOwnerRepoSvgOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Distribution Badge * * GET /badge/wiki/{owner}/{repo}.svg */ export const getApiBadgeWikiOwnerRepoSvg = async (args: GetApiBadgeWikiOwnerRepoSvgArgs, options: GetApiBadgeWikiOwnerRepoSvgOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/plain") if (args.style != null) query.append("style", String(args.style)) const url = `${baseUrl.replace(/\/+$/, '')}/badge/wiki/${encodeURIComponent(String(args.owner))}/${encodeURIComponent(String(args.repo))}.svg${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() };