Bare Docs
ReferenceBareModules

bare-mime

Reference for bare-mime: MIME-type parsing for Bare—type, subtype, and parameters.

bare-mime parses MIME types for Bare into their type, subtype, and parameters, implementing the MIME type record and parser defined by the MIME Sniffing Standard. It's pure JavaScript.

npm i bare-mime

Usage

const MIME = require('bare-mime')

const mime = MIME.parse('text/plain;charset=utf-8')
console.log(mime.type)                      // 'text'
console.log(mime.subtype)                   // 'plain'
console.log(mime.parameters.get('charset')) // 'utf-8'

API

const mime = new MIME(type, subtype[, parameters])

Construct a MIME type. parameters is optional and defaults to an empty Map. Exposes mime.type, mime.subtype, and mime.parameters (a map of parameter names to values).

const mime = MIME.parse(input)

Parse a MIME-type string into a MIME. Returns null on failure. The type and subtype are lowercased, and leading/trailing HTTP whitespace is stripped from the input. If the same parameter name appears more than once, the first occurrence is used and subsequent duplicates are ignored.

See also

Last updated on

Was this helpful?

On this page