From ebae0bfa99a50c28913e181db55603d37f4a2c7a Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Sun, 29 Dec 2024 15:04:51 +0100 Subject: [PATCH] Replace lodash.chunk (#4372) --- lib/plugins/html/htmlBuilder.js | 9 ++++++++- lib/plugins/text/textBuilder.js | 9 ++++++++- npm-shrinkwrap.json | 6 ------ package.json | 1 - 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/plugins/html/htmlBuilder.js b/lib/plugins/html/htmlBuilder.js index 4da5680eef..ac985e214b 100644 --- a/lib/plugins/html/htmlBuilder.js +++ b/lib/plugins/html/htmlBuilder.js @@ -12,7 +12,6 @@ import { markdown } from 'markdown'; import merge from 'lodash.merge'; import get from 'lodash.get'; import isEmpty from 'lodash.isempty'; -import chunk from 'lodash.chunk'; const getOS = promisify(getos); const log = intel.getLogger('sitespeedio.plugin.html'); @@ -37,6 +36,14 @@ import { toArray } from '../../support/util.js'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'; +function chunk(array, size) { + const out = []; + for (let i = 0; i < array.length; i += size) { + out.push(array.slice(i, i + size)); + } + return out; +} + export class HTMLBuilder { constructor(context, options) { this.storageManager = context.storageManager; diff --git a/lib/plugins/text/textBuilder.js b/lib/plugins/text/textBuilder.js index 3c0f174937..591a02883e 100644 --- a/lib/plugins/text/textBuilder.js +++ b/lib/plugins/text/textBuilder.js @@ -1,6 +1,5 @@ import table from 'text-table'; import clic from 'cli-color'; -import chunk from 'lodash.chunk'; import { plural, short, cap } from '../../support/helpers/index.js'; import summaryBoxesSetup from '../html/setup/summaryBoxes.js'; @@ -11,6 +10,14 @@ const tableOptions = { }; const drab = blackBright; +function chunk(array, size) { + const out = []; + for (let i = 0; i < array.length; i += size) { + out.push(array.slice(i, i + size)); + } + return out; +} + function getMarker(label) { return { ok: '√', warning: '!', error: '✗', info: '' }[label] || ''; } diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 9e22580eb5..a3b5fc0552 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -31,7 +31,6 @@ "intel": "1.2.0", "jstransformer-markdown-it": "3.0.0", "junit-report-builder": "3.2.1", - "lodash.chunk": "4.2.0", "lodash.clonedeep": "4.5.0", "lodash.foreach": "4.5.0", "lodash.get": "4.4.2", @@ -7800,11 +7799,6 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, - "node_modules/lodash.chunk": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.chunk/-/lodash.chunk-4.2.0.tgz", - "integrity": "sha1-ZuXOH3btJ7QwPYxlEujRIW6BBrw=" - }, "node_modules/lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", diff --git a/package.json b/package.json index a9f30d8a10..8066f2af99 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,6 @@ "intel": "1.2.0", "jstransformer-markdown-it": "3.0.0", "junit-report-builder": "3.2.1", - "lodash.chunk": "4.2.0", "lodash.clonedeep": "4.5.0", "lodash.foreach": "4.5.0", "lodash.get": "4.4.2",