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

content-type

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

content-type - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

HISTORY.md

41

package.json
{
"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/"
}
}

@@ -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
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