Giter VIP home page Giter VIP logo

media-typer's Introduction

media-typer

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Simple RFC 6838 media type parser.

This module will parse a given media type into it's component parts, like type, subtype, and suffix. A formatter is also provided to put them back together and the two can be combined to normalize media types into a canonical form.

If you are looking to parse the string that represents a media type and it's parameters in HTTP (for example, the Content-Type header), use the content-type module.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install media-typer

API

var typer = require('media-typer')

typer.parse(string)

var obj = typer.parse('image/svg+xml')

Parse a media type string. This will return an object with the following properties (examples are shown for the string 'image/svg+xml; charset=utf-8'):

  • type: The type of the media type (always lower case). Example: 'image'

  • subtype: The subtype of the media type (always lower case). Example: 'svg'

  • suffix: The suffix of the media type (always lower case). Example: 'xml'

typer.format(obj)

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

Format an object into a media type string. This will return a string of the mime type for the given object. For the properties of the object, see the documentation for typer.parse(string).

License

MIT

media-typer's People

Contributors

dougwilson avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.