Skip to content

Commit

Permalink
feat: export createStandardResponse helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed May 30, 2024
1 parent 254c57e commit 23a7b4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion scripts/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ await Deno.remove('deno.lock')

const files =
(await Array.fromAsync(expandGlob('**/*.ts', { root: Deno.cwd(), includeDirs: false, exclude: ['**/_*', '**/.*'] })))
.map((x) => relative(Deno.cwd(), x.path)).join(' ') // simplify when https://github.com/dsherret/dax/issues/251 is supported
.map((x) => relative(Deno.cwd(), x.path)).join(' ')

await $.raw`deno cache --reload --lock=deno.lock ${files}`

/**
* TODO:
* - simplify when https://github.com/dsherret/dax/issues/251 is implemented
*/
15 changes: 14 additions & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,24 @@ export async function createRouter(
}
}

function createStandardResponse(status: StatusCode, init?: ResponseInit): Response {
/**
* Creates a standard response with the given status code.
* @param status The status code.
* @param init The response init.
* @returns The response.
*
* @example
* ```ts
* const response = createStandardResponse(STATUS_CODE.NotFound)
* ```
*/
export function createStandardResponse(status: StatusCode, init?: ResponseInit): Response {
const statusText = STATUS_TEXT[status]
return new Response(statusText, { status, statusText, ...init })
}

export { STATUS_CODE } from '@std/http'

/**
* TODO:
* - use URLPatternList once it's available (https://github.com/whatwg/urlpattern/pull/166)
Expand Down

0 comments on commit 23a7b4a

Please sign in to comment.