Skip to content

Commit

Permalink
Simplify and inline check function
Browse files Browse the repository at this point in the history
  • Loading branch information
fehnomenal committed Feb 16, 2022
1 parent b76aca6 commit b401334
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions packages/kit/src/runtime/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,16 @@ export function decode_params(params) {
return params;
}

/** @param {any} obj **/
function is_readable_node_stream(obj) {
// Copied from nodejs sources
return !!(
(
obj &&
typeof obj.pipe === 'function' &&
typeof obj.on === 'function' &&
(!obj._writableState || obj._readableState?.readable !== false) && // Duplex
(!obj._writableState || obj._readableState)
) // Writable has .pipe.
);
}

/** @param {any} body */
export function is_pojo(body) {
if (typeof body !== 'object') return false;

if (body) {
if (body instanceof Uint8Array) return false;

if (is_readable_node_stream(body)) return false;
// body could be a node Readable, but we don't want to import
// node built-ins, so we use duck typing
if (body._readableState && typeof body.pipe === 'function') return false;

// similarly, it could be a web ReadableStream
if (typeof ReadableStream !== 'undefined' && body instanceof ReadableStream) return false;
Expand Down

0 comments on commit b401334

Please sign in to comment.