Skip to content

Commit 550d542

Browse files
authored
refactor: use Array.flat instead of array-flatten package (#126)
1 parent 2e7fb67 commit 550d542

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
=================
3+
4+
* Use `Array.flat` instead of `array-flatten` package
5+
16
2.0.0 / 2024-09-09
27
==================
38

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @private
1313
*/
1414

15-
const flatten = require('array-flatten').flatten
1615
const isPromise = require('is-promise')
1716
const Layer = require('./lib/layer')
1817
const methods = require('methods')
@@ -27,6 +26,7 @@ const setPrototypeOf = require('setprototypeof')
2726
*/
2827

2928
const slice = Array.prototype.slice
29+
const flatten = Array.prototype.flat
3030

3131
/**
3232
* Expose `Router`.
@@ -374,7 +374,7 @@ Router.prototype.use = function use (handler) {
374374
}
375375
}
376376

377-
const callbacks = flatten(slice.call(arguments, offset))
377+
const callbacks = flatten.call(slice.call(arguments, offset), Infinity)
378378

379379
if (callbacks.length === 0) {
380380
throw new TypeError('argument handler is required')

lib/route.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @private
1313
*/
1414

15-
const flatten = require('array-flatten').flatten
1615
const Layer = require('./layer')
1716
const methods = require('methods')
1817

@@ -22,6 +21,7 @@ const methods = require('methods')
2221
*/
2322

2423
const slice = Array.prototype.slice
24+
const flatten = Array.prototype.flat
2525

2626
/* istanbul ignore next */
2727
const defer = typeof setImmediate === 'function'
@@ -192,7 +192,7 @@ Route.prototype.dispatch = function dispatch (req, res, done) {
192192
*/
193193

194194
Route.prototype.all = function all (handler) {
195-
const callbacks = flatten(slice.call(arguments))
195+
const callbacks = flatten.call(slice.call(arguments), Infinity)
196196

197197
if (callbacks.length === 0) {
198198
throw new TypeError('argument handler is required')
@@ -217,7 +217,7 @@ Route.prototype.all = function all (handler) {
217217

218218
methods.forEach(function (method) {
219219
Route.prototype[method] = function (handler) {
220-
const callbacks = flatten(slice.call(arguments))
220+
const callbacks = flatten.call(slice.call(arguments), Infinity)
221221

222222
if (callbacks.length === 0) {
223223
throw new TypeError('argument handler is required')

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"license": "MIT",
1010
"repository": "pillarjs/router",
1111
"dependencies": {
12-
"array-flatten": "3.0.0",
1312
"is-promise": "4.0.0",
1413
"methods": "~1.1.2",
1514
"parseurl": "~1.3.3",

0 commit comments

Comments
 (0)