Skip to content

Commit

Permalink
Replace lodash.flatten with a small function
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Sep 12, 2023
1 parent 39977a5 commit 609b4d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"html-escaper": "^2.0.2",
"is-plain-object": "^5.0.0",
"lodash.debounce": "^4.0.8",
"lodash.flatten": "^4.4.0",
"lodash.invokemap": "^4.6.0",
"lodash.pullall": "^4.2.0",
"lodash.uniqby": "^4.7.0",
Expand Down
32 changes: 31 additions & 1 deletion src/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const path = require('path');
const pullAll = require('lodash.pullall');
const invokeMap = require('lodash.invokemap');
const uniqBy = require('lodash.uniqby');
const flatten = require('lodash.flatten');

const gzipSize = require('gzip-size');
const {parseChunked} = require('@discoveryjs/json-ext');
Expand Down Expand Up @@ -239,3 +238,34 @@ function getChunkToInitialByEntrypoint(bundleStats) {
});
return chunkToEntrypointInititalMap;
};

/**
* arr-flatten <https://github.com/jonschlinkert/arr-flatten>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*
* Modified by Sukka <https://skk.moe>
*
* Replace recursively flatten with one-level deep flatten to match lodash.flatten
*
* TODO: replace with Array.prototype.flat once Node.js 10 support is dropped
*/
function flatten(arr) {
if (!arr) return [];
const len = arr.length;
if (!len) return [];

let cur;

const res = [];
for (let i = 0; i < len; i++) {
cur = arr[i];
if (Array.isArray(cur)) {
res.push(...cur);
} else {
res.push(cur);
}
}
return res;
}

0 comments on commit 609b4d5

Please sign in to comment.