Media-typer

media-typer

RFC 6838 media type parser.

media-typer helps in parsing and formatting media type.

Get it: npm install media-typer

Sample usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const typer = require('media-typer');

typer.parse('image/svg+xml; charset=utf-8');

/*
{ type: 'image',
  subtype: 'svg',
  suffix: 'xml',
  parameters: { charset: 'utf-8' } 
}
*/

typer.format({type: 'image', subtype: 'svg', suffix: 'xml'})

// ^ 'image/svg+xml'
1
2
3
4
typer.parse(req);

/* ^ Parse the `content-type` header from the given req.
 Short-cut for typer.parse(req.headers['content-type'])*/

GIF FTW!

media-typer

Suggest a module

Comments