Skip to content

Commit

Permalink
reject object input. (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin authored Oct 3, 2023
1 parent da9d0ae commit a1a7912
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import {b64Encode} from "./base64.ts";

/**
* Possible input for `URLSearchParams`.
*/
export type QueryInit = Exclude<HeadersInit, Headers> | URLSearchParams;

/**
* `RequestInit` with added `query` property that can specify query string.
*/
export interface FetchInit extends Omit<RequestInit, "integrity" | "window">{
query?: QueryInit;
signal?: AbortSignal;
headers?: Headers;
body?: BodyInit;
query?: URLSearchParams;
}

/**
Expand Down Expand Up @@ -38,7 +36,7 @@ export interface ResponseType{
*/
export async function fetchExtend<T extends keyof ResponseType>(path:string, type:T, option?:FetchInit):Promise<ResponseType[T]>{
const {origin, pathname} = new URL(path, globalThis?.location?.href);
const query = new URLSearchParams(option?.query).toString();
const query = option?.query?.toString();

const response = await fetch(`${origin}${pathname}${query && "?"}${query}`, {
method: option?.method ?? "GET",
Expand All @@ -50,7 +48,7 @@ export async function fetchExtend<T extends keyof ResponseType>(path:string, typ
referrerPolicy: option?.referrerPolicy ?? "no-referrer",
referrer: option?.referrer,
signal: option?.signal,
headers: option?.headers && new Headers(option.headers),
headers: option?.headers,
body: option?.body
});

Expand Down

0 comments on commit a1a7912

Please sign in to comment.