content-type
Advanced tools
Comparing version 0.0.1 to 1.0.0
{ | ||
"name": "content-type", | ||
"version": "0.0.1", | ||
"description": "Javascript/ECMAScript library for parsing Content-Type and Media/MIME type strings", | ||
"main": "content-type.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/deoxxa/content-type.git" | ||
}, | ||
"description": "Create and parse HTTP Content-Type header", | ||
"version": "1.0.0", | ||
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
"license": "MIT", | ||
"keywords": [ | ||
"content-type", | ||
"parse", | ||
"http", | ||
"header" | ||
"req", | ||
"res", | ||
"rfc7231" | ||
], | ||
"author": "Austin Wright <https://github.com/Acubed>", | ||
"license": "Unlicense <http://unlicense.org/>", | ||
"bugs": { | ||
"url": "https://github.com/deoxxa/content-type/issues" | ||
"repository": "jshttp/content-type", | ||
"devDependencies": { | ||
"istanbul": "0.3.5", | ||
"mocha": "~1.21.5" | ||
}, | ||
"files": [ | ||
"LICENSE", | ||
"HISTORY.md", | ||
"README.md", | ||
"index.js" | ||
], | ||
"engines": { | ||
"node": ">= 0.6" | ||
}, | ||
"scripts": { | ||
"test": "mocha --reporter spec --check-leaks --bail test/", | ||
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/", | ||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/" | ||
} | ||
} |
103
README.md
@@ -1,61 +0,84 @@ | ||
# Content-Type parsing | ||
# content-type | ||
*note: forked from [here](https://github.com/Acubed/contenttype)* | ||
[![NPM Version][npm-image]][npm-url] | ||
[![NPM Downloads][downloads-image]][downloads-url] | ||
[![Node.js Version][node-version-image]][node-version-url] | ||
[![Build Status][travis-image]][travis-url] | ||
[![Test Coverage][coveralls-image]][coveralls-url] | ||
## new MediaType(type, [parameters]) | ||
Create and parse HTTP Content-Type header according to RFC 7231 | ||
The MediaType represents a parsed Media Type. For use in HTTP, the first (but only the first) `q` parameter will be parsed as a float. | ||
Other parameters are available through the `params` object. | ||
The first argument is the full media type, the second argument, if provided, is strictly a list of parameters. | ||
## Installation | ||
The `toString` method converts the object back into a Media type. | ||
```sh | ||
$ npm install content-type | ||
``` | ||
```javascript | ||
var p = new MediaType('text/html;level=1;q=0.5'); | ||
p.q === 0.5; | ||
p.params.level === "1" | ||
## API | ||
var q = new MediaType('application/json', {profile: 'http://example.com/schema.json'}); | ||
q.type === "application/json"; | ||
q.params.profile === "http://example.com/schema.json"; | ||
```js | ||
var contentType = require('content-type') | ||
``` | ||
q.q = 1; | ||
q.toString() === 'application/json;q=1;profile="http://example.com/schema.json"'; | ||
### contentType.parse(string) | ||
```js | ||
var obj = contentType.parse('image/svg+xml; charset=utf-8') | ||
``` | ||
## parseMedia(type) | ||
Returns a new instance of MediaType. | ||
Parse a content type string. This will return an object with the following | ||
properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`): | ||
## splitQuotedString(str, delimiter, quote) | ||
Splits a string by a delimiter character (default: semicolon), ignoring quoted sections (default: double quote). | ||
- `type`: The media type (the type and subtype, always lower case). | ||
Example: `'image/svg+xml'` | ||
- `parameters`: An object of the parameters in the media type (name of parameter | ||
always lower case). Example: `{charset: 'utf-8'}` | ||
## splitContentTypes(str) | ||
Splits an Accept (or similar) header into an Array of strings of content-types. | ||
### contentType.parse(req) | ||
```javascript | ||
splitContentType('application/json, text/html').map(parseMedia) | ||
```js | ||
var obj = contentType.parse(req) | ||
``` | ||
## select(reps, accept) | ||
Pick an ideal representation to send, given an Array of representations to choose from, and the client-preferred list as an Array. | ||
Parse the `content-type` header from the given `req`. Short-cut for | ||
`contentType.parse(req.headers['content-type'])`. | ||
See example.js for an example. | ||
### contentType.parse(res) | ||
## mediaCmp(a, b) | ||
```js | ||
var obj = contentType.parse(res) | ||
``` | ||
Accepts two MediaType instances and tests them for being a subset/superset. | ||
Parse the `content-type` header set on the given `res`. Short-cut for | ||
`contentType.parse(res.getHeader('content-type'))`. | ||
If a is a superset of b (b is smaller than a), return 1. | ||
If b is a superset of a, return -1. | ||
If they are the exact same, return 0. | ||
If they are disjoint, return null. | ||
### contentType.format(obj) | ||
The q-value, if any, is ignored. | ||
```js | ||
var str = contentType.format({type: 'image/svg+xml'}) | ||
``` | ||
```javascript | ||
mediaCmp(parseMedia('text/html'), parseMedia('text/html')) === 0 | ||
mediaCmp(parseMedia('*/*'), parseMedia('text/html')) === 1 | ||
mediaCmp(parseMedia('text/html;level=1'), parseMedia('text/html')) === -1 | ||
mediaCmp(parseMedia('application/json;profile="v1.json"'), parseMedia('application/json;profile="v2.json"')) === null | ||
``` | ||
Format an object into a content type string. This will return a string of the | ||
content type for the given object with the following properties (examples are | ||
shown that produce the string `'image/svg+xml; charset=utf-8'`): | ||
- `type`: The media type (will be lower-cased). Example: `'image/svg+xml'` | ||
- `parameters`: An object of the parameters in the media type (name of the | ||
parameter will be lower-cased). Example: `{charset: 'utf-8'}` | ||
## License | ||
[MIT](LICENSE) | ||
[npm-image]: https://img.shields.io/npm/v/content-type.svg | ||
[npm-url]: https://npmjs.org/package/content-type | ||
[node-version-image]: https://img.shields.io/node/v/content-type.svg | ||
[node-version-url]: http://nodejs.org/download/ | ||
[travis-image]: https://img.shields.io/travis/jshttp/content-type/master.svg | ||
[travis-url]: https://travis-ci.org/jshttp/content-type | ||
[coveralls-image]: https://img.shields.io/coveralls/jshttp/content-type/master.svg | ||
[coveralls-url]: https://coveralls.io/r/jshttp/content-type | ||
[downloads-image]: https://img.shields.io/npm/dm/content-type.svg | ||
[downloads-url]: https://npmjs.org/package/content-type |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
1
85
9088
2
171
1
1
2