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);
console.log(media.subtype);
console.log(media.hasSuffix());
console.log(media);
}
var media = mediaType.fromString("application/vnd.company.app.entity-v2+xml; charset=utf8; BOM=true");
if (media.isValid()) {
console.log(media.type);
console.log(media.subtype);
console.log(media.subtypeFacets);
console.log(media.hasSuffix());
console.log(media.suffix);
console.log(media.parameters);
console.log(media.isVendor());
console.log(media.isPersonal());
console.log(media.isExperimental());
console.log(media);
}
Test
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.