quick-res
Version:
A set of small utilities that makes Response. q.json(), q.text(), q.html(), .... can make your code shorter and more readable while also providing good support for Tree-Shaking.
25 lines (24 loc) • 720 B
TypeScript
interface CreateResponse<T = unknown> {
(data: T | null, /** Status code. Defaults to 200. */ status?: number, headers?: HeadersInit): Response;
(data: T | null, init?: ResponseInit): Response;
}
type JSONResp = CreateResponse<unknown>;
/**
* Responds stream or whatever you want.
*/
export declare const resp: CreateResponse<BodyInit>;
/**
* Responds as text/plain.
*/
export declare const text: CreateResponse<string>;
/**
* Responds as application/json.
* The data is converted into a JSON string using JSON.stringify.
*/
export declare const json: JSONResp;
/**
* Responds as text/html.
*/
export declare const html: CreateResponse<string>;
export declare const notFound: () => Response;
export {};