Skip to content

Commit

Permalink
fixes #175 by allowing full options inclusion in status and fixing ty…
Browse files Browse the repository at this point in the history
…pes in createResponse
  • Loading branch information
kwhitley committed Jun 20, 2023
1 parent 64ec625 commit 061aeab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/createResponse.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
export interface ResponseFormatter {
(body?: any, options?: object): Response
(body?: any, options?: ResponseInit): Response
}

export interface BodyTransformer {
(body: any): string
}

type ResponseFormatterOptions = {
headers?: object
} & ResponseInit

export const createResponse =
(
format = 'text/plain; charset=utf-8',
transform?: BodyTransformer
): ResponseFormatter =>
(body, options: ResponseFormatterOptions = {}) => {
const { headers = {}, ...rest } = options
(body, options?: ResponseInit) => {
const { headers = {}, ...rest } = options || {}

if (body?.constructor.name === 'Response') return body

Expand Down
3 changes: 2 additions & 1 deletion src/status.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const status = (status: number) => new Response(null, { status })
export const status = (status: number, options?: ResponseInit): Response =>
new Response(null, { ...options, status })

0 comments on commit 061aeab

Please sign in to comment.