export type GetApiBarcodeEncodeArgs = {number: unknown, barcodeformat?: unknown | undefined, outputformat?: unknown | undefined, widthfactor?: number | undefined, totalheight?: number | undefined}; export type GetApiBarcodeEncodeOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get a Bar Code image for the given barcode number * * GET /barcode/encode */ export const getApiBarcodeEncode = async (args: GetApiBarcodeEncodeArgs, options?: GetApiBarcodeEncodeOptions) => { const {baseUrl = "http://api.fungenerators.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.number != null) query.append("number", String(args.number)) if (args.barcodeformat != null) query.append("barcodeformat", String(args.barcodeformat)) if (args.outputformat != null) query.append("outputformat", String(args.outputformat)) if (args.widthfactor != null) query.append("widthfactor", String(args.widthfactor)) if (args.totalheight != null) query.append("totalheight", String(args.totalheight)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/barcode/encode${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 };