Skip to content

Commit

Permalink
Add jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed Mar 14, 2024
1 parent d686463 commit ae8f597
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions response.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
/**
* Creates a new Response object by copying the body and headers from an existing Response object.
* Difference between cloning and copying of a `Response`:
* https://community.cloudflare.com/t/whats-the-point-of-response-clone/216456
*
* @param {Response} response - The Response object to copy.
* @returns {Response} A new Response object with the same body and headers as the input Response object.
*/
export function copyResponse(response) {
return new Response(response.body, response);
}

/**
* Determines the appropriate body value for a Response object based on the input value.
* If the input is already a string, it is returned as-is.
* If the input is undefined or null, an empty string is returned.
* If the input is a supported type for the Response body, it is returned as-is.
* Otherwise, the input is converted to a JSON string.
*
* @param {*} input - The input value to determine the Response body for.
* @returns {BodyInit} The appropriate body value for the Response object.
*/
export function getResponseBody(input) {
if (typeof input === "string") {
return input;
Expand Down

0 comments on commit ae8f597

Please sign in to comment.