From 0eab275b44c336c67c565ebe161b90aa6817100d Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 1 Aug 2019 19:13:31 -0700 Subject: [PATCH] Remove deprecated flatten dependency For: https://github.com/brave/brave-browser/issues/5490 --- index.js | 15 ++++++++++++--- package.json | 1 - 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2fd62662..be17c614 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,6 @@ const BlockStream = require('block-stream2') const calcPieceLength = require('piece-length') const corePath = require('path') const FileReadStream = require('filestream/read') -const flatten = require('flatten') const fs = require('fs') const isFile = require('is-file') const junk = require('junk') @@ -13,6 +12,16 @@ const parallel = require('run-parallel') const sha1 = require('simple-sha1') const stream = require('readable-stream') +// TODO: When Node 10 support is dropped, replace this Array.prototype.flat +function flat (arr1) { + return arr1.reduce( + (acc, val) => Array.isArray(val) + ? acc.concat(flat(val)) + : acc.concat(val), + [] + ) +} + const announceList = [ ['udp://tracker.leechers-paradise.org:6969'], ['udp://tracker.coppersurfer.tk:6969'], @@ -192,7 +201,7 @@ function _parseInput (input, opts, cb) { cb(null, file) }), (err, files) => { if (err) return cb(err) - files = flatten(files) + files = flat(files) cb(null, files, isSingleFileTorrent) }) } @@ -202,7 +211,7 @@ function getFiles (path, keepRoot, cb) { traversePath(path, getFileInfo, (err, files) => { if (err) return cb(err) - if (Array.isArray(files)) files = flatten(files) + if (Array.isArray(files)) files = flat(files) else files = [files] path = corePath.normalize(path) diff --git a/package.json b/package.json index 8458862b..9f267d5f 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "bencode": "^2.0.0", "block-stream2": "^2.0.0", "filestream": "^5.0.0", - "flatten": "^1.0.2", "is-file": "^1.0.0", "junk": "^3.1.0", "minimist": "^1.1.0",