media-type
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -57,3 +57,3 @@ /** | ||
MediaType.prototype.toString = function() { | ||
MediaType.prototype.asString = function() { | ||
var str = ""; | ||
@@ -79,3 +79,2 @@ if (this.isValid()) { | ||
}; | ||
MediaType.prototype.inspect = MediaType.prototype.toString; | ||
@@ -82,0 +81,0 @@ var wrapQuotes = function(str) { |
{ | ||
"name": "media-type", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"main": "./lib/mediaType", | ||
@@ -11,3 +11,3 @@ "description": "Parse and validate RFC6838 media types, anything from 'text/plain' to 'application/vnd.company.app.entity-v2+xml;charset=utf8'", | ||
"engines": { | ||
"node": "*" | ||
"node": ">=0.10" | ||
}, | ||
@@ -31,4 +31,4 @@ "scripts": { | ||
"dependencies": { | ||
"binary-csv": "~0.1" | ||
"binary-csv": "^0.1.7" | ||
} | ||
} |
@@ -13,15 +13,16 @@ # media-type | ||
## Usage | ||
## Usage examples | ||
```javascript | ||
var mediaType = require("media-type"); | ||
var mediaType = require('media-type'); | ||
``` | ||
```javascript | ||
var media = mediaType.fromString("text/plain"); | ||
var media = mediaType.fromString('text/plain'); | ||
if (media.isValid()) { | ||
console.log(media.type); // "text" | ||
console.log(media.subtype); // "plain" | ||
console.log(media.type); // 'text' | ||
console.log(media.subtype); // 'plain' | ||
console.log(media.hasSuffix()); // false | ||
console.log(media); // "text/plain" | ||
console.log(media.asString()); // 'text/plain' | ||
console.log(media); // { type: 'text', subtype: 'plain', subtypeFacets: [ 'plain' ] ... } | ||
} | ||
@@ -31,17 +32,50 @@ ``` | ||
```javascript | ||
var media = mediaType.fromString("application/vnd.company.app.entity-v2+xml; charset=utf8; BOM=true"); | ||
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.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.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" | ||
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](https://travis-ci.org/lovell/media-type.png?branch=master)](https://travis-ci.org/lovell/media-type) | ||
@@ -55,3 +89,3 @@ | ||
Copyright 2013 Lovell Fuller | ||
Copyright 2013, 2014 Lovell Fuller | ||
@@ -58,0 +92,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); |
@@ -125,3 +125,3 @@ /** | ||
assert.ok(!type.isExperimental()); | ||
assert.strictEqual(type.toString(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml;k1=v1;k2=\"v2a;v2b\""); | ||
assert.strictEqual(type.asString(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml;k1=v1;k2=\"v2a;v2b\""); | ||
@@ -139,3 +139,3 @@ type = mediaType.fromString("application/sparql-results+xml"); | ||
assert.ok(!type.isExperimental()); | ||
assert.strictEqual(type.toString(), "application/sparql-results+xml"); | ||
assert.strictEqual(type.asString(), "application/sparql-results+xml"); | ||
@@ -153,3 +153,3 @@ type = mediaType.fromString("image/svg+xml; CHARSET = utf8"); | ||
assert.ok(!type.isExperimental()); | ||
assert.strictEqual(type.toString(), "image/svg+xml;charset=utf8"); | ||
assert.strictEqual(type.asString(), "image/svg+xml;charset=utf8"); | ||
@@ -166,3 +166,3 @@ type = mediaType.fromString("audio/amr-wb+"); | ||
assert.ok(!type.isExperimental()); | ||
assert.strictEqual(type.toString(), "audio/amr-wb+"); | ||
assert.strictEqual(type.asString(), "audio/amr-wb+"); | ||
@@ -179,3 +179,3 @@ type = mediaType.fromString("text/vnd.DMClientScript;charset=iso-8859-1"); | ||
assert.ok(!type.isExperimental()); | ||
assert.strictEqual(type.toString(), "text/vnd.DMClientScript;charset=iso-8859-1"); | ||
assert.strictEqual(type.asString(), "text/vnd.DMClientScript;charset=iso-8859-1"); | ||
@@ -192,3 +192,3 @@ type = mediaType.fromString("text/prs.lines.tag"); | ||
assert.ok(!type.isExperimental()); | ||
assert.strictEqual(type.toString(), "text/prs.lines.tag"); | ||
assert.strictEqual(type.asString(), "text/prs.lines.tag"); | ||
@@ -205,3 +205,3 @@ type = mediaType.fromString("text/x.test"); | ||
assert.ok(type.isExperimental()); | ||
assert.strictEqual(type.toString(), "text/x.test"); | ||
assert.strictEqual(type.asString(), "text/x.test"); | ||
@@ -218,3 +218,3 @@ type = mediaType.fromString("text/X-test"); | ||
assert.ok(type.isExperimental()); | ||
assert.strictEqual(type.toString(), "text/X-test"); | ||
assert.strictEqual(type.asString(), "text/X-test"); | ||
@@ -231,3 +231,3 @@ type = mediaType.fromString("text/x-test"); | ||
assert.ok(type.isExperimental()); | ||
assert.strictEqual(type.toString(), "text/x-test"); | ||
assert.strictEqual(type.asString(), "text/x-test"); | ||
@@ -246,3 +246,3 @@ // https://twitter.com/fcw/status/398604109525184512 | ||
assert.ok(!type.isExperimental()); | ||
assert.strictEqual(type.toString(), "application/LD+JSON-SQL*CSV.1"); | ||
assert.strictEqual(type.asString(), "application/LD+JSON-SQL*CSV.1"); | ||
@@ -261,3 +261,2 @@ // https://github.com/lovell/media-type/issues/1 | ||
assert.ok(!type.isExperimental()); | ||
assert.strictEqual(type.toString(), "image/svg+xml;charset=utf8;format=foo"); | ||
assert.strictEqual(type.asString(), "image/svg+xml;charset=utf8;format=foo"); |
Sorry, the diff of this file is not supported yet
27217
98
322
Updatedbinary-csv@^0.1.7