All Projects → lovell → media-type

lovell / media-type

Licence: Apache-2.0 license
JavaScript module to parse and validate RFC6838 media types, anything from 'text/plain' to 'application/vnd.company.app.entity-v2+xml;charset=utf8'

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to media-type

spring-batch-rest
REST API for Spring Batch using Spring Boot 2.2
Stars: ✭ 85 (+466.67%)
Mutual labels:  hateoas
ruby-magic
Simple interface to libmagic for Ruby Programming Language
Stars: ✭ 23 (+53.33%)
Mutual labels:  content-type
mimesniffer
A MIME type sniffer for Go.
Stars: ✭ 22 (+46.67%)
Mutual labels:  content-type
typebeat
Parsing of the Content-Type header in pure OCaml
Stars: ✭ 20 (+33.33%)
Mutual labels:  content-type
Htmx
</> htmx - high power tools for HTML
Stars: ✭ 5,256 (+34940%)
Mutual labels:  hateoas
Pomona
A fruitful way to REST
Stars: ✭ 23 (+53.33%)
Mutual labels:  hateoas
hal-api
Enhances your HATEOAS experience by automating common tasks.
Stars: ✭ 32 (+113.33%)
Mutual labels:  hateoas
react-ketting
Ketting bindings for React
Stars: ✭ 13 (-13.33%)
Mutual labels:  hateoas
Spring-Boot-Application-Template
Spring Boot Web App, Flyway, MySQL, H2DB, Bootstrap, Thymeleaf, JWT, Swagger, API Rate Limiting, Docker, RBAC, i18n
Stars: ✭ 90 (+500%)
Mutual labels:  hateoas
riskfirst.hateoas
Powerful HATEOAS functionality for .NET web api
Stars: ✭ 69 (+360%)
Mutual labels:  hateoas
express-hateoas-links
Extends express res.json to simplify building HATEOAS enabled REST API's
Stars: ✭ 26 (+73.33%)
Mutual labels:  hateoas
RestWithASP-NETUdemy
No description or website provided.
Stars: ✭ 40 (+166.67%)
Mutual labels:  hateoas
akka-http-hal
HAL (Hypermedia Application Language) specification support for akka-http
Stars: ✭ 18 (+20%)
Mutual labels:  hateoas

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, wildcards and semicolon delimited parameters.

Install

npm install media-type

Usage examples

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.asString());  // 'text/plain'
  console.log(media);             // { type: 'text', subtype: 'plain', subtypeFacets: [ '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.asString());       // 'application/vnd.company.app.entity-v2+xml;bom=true;charset=utf8'
  console.log(media);                  // { type: 'application', subtype: 'vnd.company.app.entity-v2',
                                       //   subtypeFacets: [ 'vnd', 'company', 'app', 'entity-v2' ],
                                       //   suffix: 'xml', parameters: { charset: 'utf8', bom: 'true' } }
}

API

fromString(str)

Factory method to construct an Object from a String representation of a media type.

isValid()

Is this media type valid?

asString()

Return media type as a normalised String.

hasSuffix()

Does the media type have a suffix, e.g. the xml of image/svg+xml?

isVendor()

Does the media type have a vendor prefix, e.g. text/vnd.DMClientScript?

isPersonal()

Does the media type have a personal prefix, e.g. text/prs.lines.tag?

isExperimental()

Does the media type have an experimental prefix, e.g. text/x-test?

Test Build Status

Run the unit tests with:

npm test

Licence

Copyright 2013, 2014, 2015 Lovell Fuller and contributors

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].