Skip to content

Latest commit

 

History

29 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@kikobeats/content-type

Last version Coverage Status NPM Status

A fast way to get the content type from the input string.

This is a lightweight version of jshttp/content-type for scenarios where you only want to get the content type value without parameters.

It's 90% faster; see benchmark to know more.

Install

$ npm install @kikobeats/content-type --save

Usage

Let's say the input string is 'text/html; charset=utf-8;'.

Use the library to return the content type stripping parameters:

const contentType = require('@kikobeats/content-type')
contentType(res.headers['content-type'])
// => text/html

API

getContentType(input, [options])

input

Required
Type: string

The input for getting the content type.

options

strict

Type: boolean
Default: false

When strict is enabled, it will return null when the input doesn not follow conten-type header spec.

License

@kikobeats/content-type © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @kikobeats

About

Fast Content-Type parsing for HTTP requests and responses — MIME type helpers aligned with RFC 7231.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages