Detect if the type of an argument is supported by the request body of browser fetch api and node-fetch.

npm install known-fetch-body@0.1.1


Detect fetch API body type

Detect the type of a variable is the known request body type of browser fetch API and node-fetch. Currently known types are string, FormData, Blob, URLSearchParams, Buffer, stream.Readable.


npm install known-fetch-body

Quick Start

import isKnownReqBodyType from "known-fetch-body";
import {createReadStream} from "stream";

isKnownReqBodyType("string");   // true
isKnownReqBodyType(new FormData()); // true
isKnownReqBodyType(new URLSearchParams());  // true
isKnownReqBodyType(new Buffer());   // true
isKnownReqBodyType(createReadStream("filePath"));    // true
isKnownReqBodyType({}); // false