Comparing version 3.0.0 to 3.1.0
3.1.0 / 2015-08-06 | ||
================== | ||
* travis: add v2, v3, remove 0.11 | ||
* add custom types options | ||
* use type-is | ||
3.0.0 / 2015-07-25 | ||
@@ -3,0 +10,0 @@ ================== |
@@ -6,2 +6,3 @@ | ||
var typeis = require('type-is') | ||
var json = require('./json'); | ||
@@ -11,9 +12,5 @@ var form = require('./form'); | ||
var JSON_CONTENT_TYPES = [ | ||
'application/json', | ||
'application/json-patch+json', | ||
'application/vnd.api+json', | ||
'application/csp-report', | ||
'application/ld+json' | ||
]; | ||
var jsonTypes = ['json', 'application/*+json', 'application/csp-report']; | ||
var formTypes = ['urlencoded'] | ||
var textTypes = ['text'] | ||
@@ -35,18 +32,19 @@ /** | ||
req = req.req || req; | ||
opts = opts || {}; | ||
// parse Content-Type | ||
var type = req.headers['content-type'] || ''; | ||
type = type.split(';')[0]; | ||
// json | ||
if (~JSON_CONTENT_TYPES.indexOf(type)) return json(req, opts); | ||
var jsonType = opts.jsonTypes || jsonTypes; | ||
if (typeis(req, jsonType)) return json(req, opts); | ||
// form | ||
if ('application/x-www-form-urlencoded' == type) return form(req, opts); | ||
var formType = opts.formTypes || formTypes; | ||
if (typeis(req, formType)) return form(req, opts); | ||
// text | ||
if ('text/plain' == type) return text(req, opts); | ||
var textType = opts.textTypes || textTypes; | ||
if (typeis(req, textType)) return text(req, opts); | ||
// invalid | ||
return function(done){ | ||
var type = req.headers['content-type'] || ''; | ||
var message = type ? 'Unsupported content-type: ' + type : 'Missing content-type'; | ||
@@ -53,0 +51,0 @@ var err = new Error(message); |
{ | ||
"name": "co-body", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"repository": "cojs/co-body", | ||
@@ -17,3 +17,4 @@ "description": "request body parsing for co", | ||
"qs": "~4.0.0", | ||
"raw-body": "~2.1.2" | ||
"raw-body": "~2.1.2", | ||
"type-is": "~1.6.6" | ||
}, | ||
@@ -32,3 +33,6 @@ "devDependencies": { | ||
}, | ||
"files": ["index.js", "lib/"] | ||
"files": [ | ||
"index.js", | ||
"lib/" | ||
] | ||
} |
@@ -34,2 +34,5 @@ | ||
- `queryString` an object of options when parsing query strings and form data. See [qs](https://github.com/hapijs/qs) for more information. | ||
- `jsonTypes` is used to determine what media type **co-body** will parse as **json**, this option is passed directly to the [type-is](https://github.com/jshttp/type-is) library. | ||
- `formTypes` is used to determine what media type **co-body** will parse as **form**, this option is passed directly to the [type-is](https://github.com/jshttp/type-is) library. | ||
- `textTypes` is used to determine what media type **co-body** will parse as **text**, this option is passed directly to the [type-is](https://github.com/jshttp/type-is) library. | ||
@@ -55,2 +58,5 @@ more options available via [raw-body](https://github.com/stream-utils/raw-body#getrawbodystream-options-callback): | ||
var body = yield parse(req); | ||
// custom type | ||
var body = yield parse(req, { textTypes: ['text', 'html'] }); | ||
``` | ||
@@ -57,0 +63,0 @@ |
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
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
8486
84
3
161
+ Addedtype-is@~1.6.6
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedtype-is@1.6.18(transitive)