Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

media-type

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

media-type

Parse and validate RFC6838 media types, anything from 'text/plain' to 'application/vnd.company.app.entity-v2+xml;charset=utf8'

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18K
increased by10.54%
Maintainers
1
Weekly downloads
 
Created
Source

media-type

Node.js module to parse and validate RFC6838 media types.

Useful for parsing Content-Type HTTP response headers from HATEOAS constrained services.

Aware of vendor subtype trees, +suffixes and semicolon delimited parameters.

Install

npm install media-type

Usage

var mediaType = require("media-type");
var media = mediaType.fromString("text/plain");
if (media.isValid()) {
  console.log(media.type);        // "text"
  console.log(media.subtype);     // "plain"
  console.log(media.hasSuffix()); // false
  console.log(media);             // "text/plain"
}
var media = mediaType.fromString("application/vnd.company.app.entity-v2+xml; charset=utf8; BOM=true");
if (media.isValid()) {
  console.log(media.type);             // "application"
  console.log(media.subtype);          // "vnd.company.app.entity-v2"
  console.log(media.subtypeFacets);    // ["vnd", "company", "app", "entity-v2"]
  console.log(media.hasSuffix());      // true
  console.log(media.suffix);           // "xml"
  console.log(media.parameters);       // {charset: "utf8", bom: "true"}
  console.log(media.isVendor());       // true
  console.log(media.isPersonal());     // false
  console.log(media.isExperimental()); // false
  console.log(media);                  // "application/vnd.company.app.entity-v2+xml;bom=true;charset=utf8"
}

Test Build Status

Run the unit tests with:

npm test

Licence

Copyright 2013 Lovell Fuller

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Keywords

FAQs

Package last updated on 13 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc