Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove array-flatten dependency, no longer necessary #5219

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var compileETag = require('./utils').compileETag;
var compileQueryParser = require('./utils').compileQueryParser;
var compileTrust = require('./utils').compileTrust;
var deprecate = require('depd')('express');
var flatten = require('array-flatten');
var merge = require('utils-merge');
var resolve = require('path').resolve;
var setPrototypeOf = require('setprototypeof')
Expand Down Expand Up @@ -211,7 +210,7 @@ app.use = function use(fn) {
}
}

var fns = flatten(slice.call(arguments, offset));
var fns = slice.call(arguments, offset).flat(Infinity)

if (fns.length === 0) {
throw new TypeError('app.use() requires a middleware function')
Expand Down
3 changes: 1 addition & 2 deletions lib/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var methods = require('methods');
var mixin = require('utils-merge');
var debug = require('debug')('express:router');
var deprecate = require('depd')('express');
var flatten = require('array-flatten');
var parseUrl = require('parseurl');
var setPrototypeOf = require('setprototypeof')

Expand Down Expand Up @@ -456,7 +455,7 @@ proto.use = function use(fn) {
}
}

var callbacks = flatten(slice.call(arguments, offset));
var callbacks = slice.call(arguments, offset).flat(Infinity);

if (callbacks.length === 0) {
throw new TypeError('Router.use() requires a middleware function')
Expand Down
5 changes: 2 additions & 3 deletions lib/router/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

var debug = require('debug')('express:router:route');
var flatten = require('array-flatten');
var Layer = require('./layer');
var methods = require('methods');

Expand Down Expand Up @@ -182,7 +181,7 @@ Route.prototype.dispatch = function dispatch(req, res, done) {
*/

Route.prototype.all = function all() {
var handles = flatten(slice.call(arguments));
var handles = slice.call(arguments).flat(Infinity);

for (var i = 0; i < handles.length; i++) {
var handle = handles[i];
Expand All @@ -205,7 +204,7 @@ Route.prototype.all = function all() {

methods.forEach(function(method){
Route.prototype[method] = function(){
var handles = flatten(slice.call(arguments));
var handles = slice.call(arguments).flat(Infinity);

for (var i = 0; i < handles.length; i++) {
var handle = handles[i];
Expand Down
12 changes: 0 additions & 12 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var Buffer = require('safe-buffer').Buffer
var contentDisposition = require('content-disposition');
var contentType = require('content-type');
var deprecate = require('depd')('express');
var flatten = require('array-flatten');
var mime = require('send').mime;
var etag = require('etag');
var proxyaddr = require('proxy-addr');
Expand Down Expand Up @@ -59,17 +58,6 @@ exports.isAbsolute = function(path){
if ('\\\\' === path.substring(0, 2)) return true; // Microsoft Azure absolute path
};

/**
* Flatten the given `arr`.
*
* @param {Array} arr
* @return {Array}
* @api private
*/

exports.flatten = deprecate.function(flatten,
'utils.flatten: use array-flatten npm module instead');

/**
* Normalize the given `type`, for example "html" becomes "text/html".
*
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
],
"dependencies": {
"accepts": "~1.3.8",
"array-flatten": "1.1.1",
"body-parser": "1.20.2",
"content-disposition": "0.5.4",
"content-type": "~1.0.4",
Expand Down
15 changes: 0 additions & 15 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,3 @@ describe('utils.isAbsolute()', function(){
assert(!utils.isAbsolute('foo/bar'));
})
})

describe('utils.flatten(arr)', function(){
it('should flatten an array', function(){
var arr = ['one', ['two', ['three', 'four'], 'five']];
var flat = utils.flatten(arr)

assert.strictEqual(flat.length, 5)
assert.strictEqual(flat[0], 'one')
assert.strictEqual(flat[1], 'two')
assert.strictEqual(flat[2], 'three')
assert.strictEqual(flat[3], 'four')
assert.strictEqual(flat[4], 'five')
assert.ok(flat.every(function (v) { return typeof v === 'string' }))
})
})