Use utils-merge module for merging objects

parent 49c9bb46
2.x
===
* Use `utils-merge` module for merging objects
* deps: body-parser@~1.9.0
- include the charset in "unsupported charset" error message
- include the encoding in "unsupported content encoding" error message
......
......@@ -16,6 +16,7 @@ var EventEmitter = require('events').EventEmitter
, path = require('path')
, basename = path.basename
, fs = require('fs');
var merge = require('utils-merge');
// node patches
......@@ -64,8 +65,8 @@ exports.utils = utils;
function createServer() {
function app(req, res, next){ app.handle(req, res, next); }
utils.merge(app, proto);
utils.merge(app, EventEmitter.prototype);
merge(app, proto);
merge(app, EventEmitter.prototype);
app.route = '/';
app.stack = [];
......
......@@ -12,7 +12,7 @@
var bodyParser = require('body-parser');
var deprecate = require('depd')('connect');
var utils = require('../utils');
var merge = require('utils-merge');
/**
* JSON:
......@@ -25,7 +25,7 @@ var utils = require('../utils');
*/
module.exports = function json(options) {
var opts = utils.merge({
var opts = merge({
limit: '1mb',
type: ['application/json', 'application/*+json']
}, options);
......
......@@ -10,7 +10,7 @@
*/
var morgan = require('morgan');
var utils = require('../utils');
var merge = require('utils-merge');
/**
* Undeprecate default format.
......@@ -48,4 +48,4 @@ module.exports = function logger(options) {
return morgan(format, opts);
};
utils.merge(module.exports, morgan);
merge(module.exports, morgan);
......@@ -10,7 +10,7 @@
*/
var expressSession = require('express-session');
var utils = require('../utils');
var merge = require('utils-merge');
/**
* Session:
......@@ -25,7 +25,7 @@ var utils = require('../utils');
*/
module.exports = exports = function session(options) {
var opts = utils.merge({
var opts = merge({
resave: true,
saveUninitialized: true
}, options);
......
......@@ -14,6 +14,7 @@ var utils = require('../utils')
, parseurl = require('parseurl')
, Cache = require('../cache')
, fresh = require('fresh');
var merge = require('utils-merge');
/**
* Static cache:
......@@ -157,7 +158,7 @@ module.exports = deprecate.function(module.exports,
function respondFromCache(req, res, cacheEntry) {
var status = cacheEntry[0]
, headers = utils.merge({}, cacheEntry[1])
, headers = merge({}, cacheEntry[1])
, content = cacheEntry.slice(2);
headers.age = (new Date - new Date(headers.date)) / 1000 || 0;
......
......@@ -11,7 +11,7 @@
var bodyParser = require('body-parser');
var deprecate = require('depd')('connect');
var utils = require('../utils');
var merge = require('utils-merge');
/**
* Urlencoded:
......@@ -24,7 +24,7 @@ var utils = require('../utils');
*/
module.exports = function urlencoded(options) {
var opts = utils.merge({
var opts = merge({
extended: true,
limit: '1mb'
}, options);
......
......@@ -12,6 +12,7 @@
var cookie = require('cookie');
var deprecate = require('depd')('connect');
var http = require('http');
var merge = require('utils-merge');
var onHeaders = require('on-headers');
var utils = require('./utils')
, res = http.ServerResponse.prototype
......@@ -71,7 +72,7 @@ if (!res._hasConnectPatch) {
*/
res.cookie = function(name, val, options){
options = utils.merge({}, options);
options = merge({}, options);
if ('maxAge' in options) {
options.expires = new Date(Date.now() + options.maxAge);
options.maxAge /= 1000;
......
......@@ -21,6 +21,7 @@ var http = require('http')
, typeis = require('type-is')
, nodeVersion = process.versions.node.split('.');
var typer = require('media-typer');
var merge = require('utils-merge');
/**
* pause is broken in node < 0.10
......@@ -111,14 +112,8 @@ exports.md5 = deprecate.function(exports.md5,
* @api private
*/
exports.merge = function(a, b){
if (a && b) {
for (var key in b) {
a[key] = b[key];
}
}
return a;
};
exports.merge = deprecate.function(merge,
'utils.merge: use utils-merge npm module instead');
/**
* Escape the given string of `html`.
......
......@@ -44,6 +44,7 @@
"serve-index": "~1.5.0",
"serve-static": "~1.7.0",
"type-is": "~1.5.2",
"utils-merge": "1.0.0",
"vhost": "~3.0.0",
"pause": "0.0.1"
},
......
var connect = require('../');
var utils = require('../lib/utils');
var merge = require('utils-merge');
describe('patch', function(){
describe('res', function(){
......@@ -58,7 +58,7 @@ describe('patch', function(){
var app = connect();
var options = { maxAge: 1000 };
var optionsCopy = utils.merge({}, options);
var optionsCopy = merge({}, options);
app.use(function(req, res){
res.cookie('name', 'tobi', options)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment