content-check
v1.0.4
Published
Guess the content type of a request body.
Downloads
367
Maintainers
Readme
Utility for working with the content-type
header isomorphically.
Installation
npm install content-check
API
check(data: any): string|undefined
Attempt to guess the content type for some data. Returns undefined if it could not be guessed.
import * as fs from "fs";
import { check } from "content-check";
check("hello"); // "text/plain"
check("<body></body>"); // "text/html"
check({ a: 1 }); // "application/json"
check(new Buffer("hello")); // "application/octet-stream"
check(fs.createReadStream(__dirname + "/index.js")); // "application/javascript"
Contributions
- Use
npm test
to run tests.
Please feel free to create a PR!