Comparing version 1.0.0 to 1.0.1
@@ -14,5 +14,2 @@ /*! | ||
const bytes = require('bytes'); | ||
const contentType = require('content-type'); | ||
const createError = require('http-errors'); | ||
const debug = require('debug')('bory:json'); | ||
@@ -23,2 +20,12 @@ const read = require('../read'); | ||
/** | ||
* Helper dependencies. | ||
* @private | ||
*/ | ||
const getCharset = require('../helpers/getCharset'); | ||
const invalidCharset = require('../helpers/invalidCharset'); | ||
const getLimit = require('../helpers/getLimit'); | ||
const typeChecker = require('../helpers/typeChecker'); | ||
/** | ||
* Module exports. | ||
@@ -54,3 +61,3 @@ */ | ||
const limit = typeof opts.limit !== 'number' ? bytes.parse(opts.limit || '100kb') : opts.limit; | ||
const limit = getLimit(opts); | ||
const inflate = opts.inflate !== false; | ||
@@ -113,7 +120,3 @@ const reviver = opts.reviver; | ||
if (charset.substr(0, 4) !== 'utf-') { | ||
debug('invalid charset'); | ||
next(createError(415, `unsupported charset "${charset.toUpperCase()}"`, { | ||
charset, | ||
})); | ||
return; | ||
return next(invalidCharset(charset)); | ||
} | ||
@@ -143,27 +146,1 @@ | ||
} | ||
/** | ||
* Get the charset of a request. | ||
* | ||
* @param {object} req | ||
* @api private | ||
*/ | ||
function getCharset(req) { | ||
try { | ||
return contentType.parse(req).parameters.charset.toLowerCase(); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} | ||
/** | ||
* Get the simple type checker. | ||
* | ||
* @param {string} type | ||
* @return {function} | ||
*/ | ||
function typeChecker(type) { | ||
return req => Boolean(typeis(req, type)); | ||
} |
@@ -13,3 +13,2 @@ /*! | ||
const bytes = require('bytes'); | ||
const debug = require('debug')('bory:raw'); | ||
@@ -20,2 +19,10 @@ const read = require('../read'); | ||
/** | ||
* Helper dependencies. | ||
* @private | ||
*/ | ||
const getLimit = require('../helpers/getLimit'); | ||
const typeChecker = require('../helpers/typeChecker'); | ||
/** | ||
* Module exports. | ||
@@ -37,3 +44,3 @@ */ | ||
const inflate = opts.inflate !== false; | ||
const limit = typeof opts.limit !== 'number' ? bytes.parse(opts.limit || '100kb') : opts.limit; | ||
const limit = getLimit(opts); | ||
const type = opts.type || 'application/octet-stream'; | ||
@@ -84,12 +91,1 @@ const verify = opts.verify || false; | ||
} | ||
/** | ||
* Get the simple type checker. | ||
* | ||
* @param {string} type | ||
* @return {function} | ||
*/ | ||
function typeChecker(type) { | ||
return req => Boolean(typeis(req, type)); | ||
} |
@@ -13,4 +13,2 @@ /*! | ||
const bytes = require('bytes'); | ||
const contentType = require('content-type'); | ||
const debug = require('debug')('bory:text'); | ||
@@ -21,2 +19,11 @@ const read = require('../read'); | ||
/** | ||
* Helper dependencies. | ||
* @private | ||
*/ | ||
const getCharset = require('../helpers/getCharset'); | ||
const getLimit = require('../helpers/getLimit'); | ||
const typeChecker = require('../helpers/typeChecker'); | ||
/** | ||
* Module exports. | ||
@@ -39,3 +46,3 @@ */ | ||
const inflate = opts.inflate !== false; | ||
const limit = typeof opts.limit !== 'number' ? bytes.parse(opts.limit || '100kb') : opts.limit; | ||
const limit = getLimit(opts); | ||
const type = opts.type || 'text/plain'; | ||
@@ -89,27 +96,1 @@ const verify = opts.verify || false; | ||
} | ||
/** | ||
* Get the charset of a request. | ||
* | ||
* @param {object} req | ||
* @api private | ||
*/ | ||
function getCharset(req) { | ||
try { | ||
return contentType.parse(req).parameters.charset.toLowerCase(); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} | ||
/** | ||
* Get the simple type checker. | ||
* | ||
* @param {string} type | ||
* @return {function} | ||
*/ | ||
function typeChecker(type) { | ||
return req => Boolean(typeis(req, type)); | ||
} |
@@ -14,4 +14,2 @@ /*! | ||
const bytes = require('bytes'); | ||
const contentType = require('content-type'); | ||
const createError = require('http-errors'); | ||
@@ -26,2 +24,12 @@ const debug = require('debug')('bory:urlencoded'); | ||
/** | ||
* Helper dependencies. | ||
* @private | ||
*/ | ||
const getCharset = require('../helpers/getCharset'); | ||
const invalidCharset = require('../helpers/invalidCharset'); | ||
const getLimit = require('../helpers/getLimit'); | ||
const typeChecker = require('../helpers/typeChecker'); | ||
/** | ||
* Module exports. | ||
@@ -56,3 +64,3 @@ */ | ||
const inflate = opts.inflate !== false; | ||
const limit = typeof opts.limit !== 'number' ? bytes.parse(opts.limit || '100kb') : opts.limit; | ||
const limit = getLimit(opts); | ||
const type = opts.type || 'application/x-www-form-urlencoded'; | ||
@@ -100,7 +108,3 @@ const verify = opts.verify || false; | ||
if (charset !== 'utf-8') { | ||
debug('invalid charset'); | ||
next(createError(415, `unsupported charset "${charset.toUpperCase()}"`, { | ||
charset, | ||
})); | ||
return; | ||
return next(invalidCharset(charset)); | ||
} | ||
@@ -158,17 +162,2 @@ | ||
/** | ||
* Get the charset of a request. | ||
* | ||
* @param {object} req | ||
* @api private | ||
*/ | ||
function getCharset(req) { | ||
try { | ||
return contentType.parse(req).parameters.charset.toLowerCase(); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} | ||
/** | ||
* Count the number of parameters, stopping once limit reached | ||
@@ -258,12 +247,1 @@ * | ||
} | ||
/** | ||
* Get the simple type checker. | ||
* | ||
* @param {string} type | ||
* @return {function} | ||
*/ | ||
function typeChecker(type) { | ||
return req => Boolean(typeis(req, type)); | ||
} |
{ | ||
"name": "bory", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Node.js body and query parsing middleware", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# bory | ||
Node.js **bo**dy and que**ry** parsing middleware. *Node >= v4.0.0* | ||
@@ -10,4 +10,5 @@ | ||
[![devDependency Status](https://david-dm.org/danielrohers/bory/dev-status.svg)](https://david-dm.org/danielrohers/bory#info=devDependencies) | ||
[![npm](https://img.shields.io/npm/dt/bory.svg)](https://www.npmjs.com/package/bory) | ||
[![npm version](https://badge.fury.io/js/bory.svg)](https://badge.fury.io/js/bory) | ||
[![npm download](https://img.shields.io/npm/dt/bory.svg)](https://www.npmjs.com/package/bory) | ||
[![npm version](https://img.shields.io/npm/v/bory.svg)](https://badge.fury.io/js/bory) | ||
[![Code Climate](https://codeclimate.com/github/danielrohers/bory/badges/gpa.svg)](https://codeclimate.com/github/danielrohers/bory) | ||
@@ -14,0 +15,0 @@ Parse incoming request bodies in a middleware before your handlers, available |
42970
15
1029
459