parse-mime

A centralized parsing module that can be extended to handle any mime type

Usage no npm install needed!

<script type="module">
  import parseMime from 'https://cdn.skypack.dev/parse-mime';
</script>

README

parse-mime

A centralized parsing module that can be extended to handle any mime type

Installation

With packin: packin add jkroso/parse-mime

then in your app:

var parse = require('parse-mime')

API

parse(mime, data)

Takes a mimetype string and some data and returns the parsed value. If it doesn't know how to parse the given mimetype it will just return the data unchanged

parse('application/json', '[1,2,3]') // => [1,2,3]

parse.define(mime, fn)

Define a parser for a new mimetype

parse.define('application/edn', JSON.parse)
parse('application/edn', '[1,2,3]') // => [1,2,3]

If the mimetype has already been defined then it will throw an error