Skip to content

Commit

Permalink
Replace lodash.isEmpty (#4391)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore authored Jan 7, 2025
1 parent f720e6e commit 25c5f38
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/core/resultsStorage/pathToFolder.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { parse } from 'node:url';
import { createHash } from 'node:crypto';

import isEmpty from 'lodash.isempty';
import { getLogger } from '@sitespeed.io/log';

import { isEmpty } from '../../support/util.js';
const log = getLogger('sitespeedio.file');

function toSafeKey(key) {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/assets/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isEmpty from 'lodash.isempty';
import { SitespeedioPlugin } from '@sitespeed.io/plugin';
import { AssetsAggregator } from './aggregator.js';
import { isEmpty } from '../../support/util.js';
const DEFAULT_METRICS_LARGEST_ASSETS = ['image.0.transferSize'];

export default class AssetsPlugin extends SitespeedioPlugin {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/browsertime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { getLogger } from '@sitespeed.io/log';
const log = getLogger('plugin.browsertime');

import dayjs from 'dayjs';
import isEmpty from 'lodash.isempty';
import get from 'lodash.get';
import { Stats } from 'fast-stats';
import coach from 'coach-core';
Expand All @@ -21,6 +20,7 @@ import { SitespeedioPlugin } from '@sitespeed.io/plugin';

import { summarizeStats } from '../../support/statsHelpers.js';
import { analyzeUrl } from './analyzer.js';
import { isEmpty } from '../../support/util.js';

import { BrowsertimeAggregator } from './browsertimeAggregator.js';
import { metricsPageSummary as DEFAULT_METRICS_PAGE_SUMMARY } from './default/metricsPageSummary.js';
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/domains/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { parse } from 'node:url';

import { Stats } from 'fast-stats';
import { getLogger } from '@sitespeed.io/log';
import isEmpty from 'lodash.isempty';
import reduce from 'lodash.reduce';

import { summarizeStats } from '../../support/statsHelpers.js';
import { isEmpty } from '../../support/util.js';

const log = getLogger('sitespeedio.plugin.domains');

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/domains/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isEmpty from 'lodash.isempty';
import { SitespeedioPlugin } from '@sitespeed.io/plugin';
import { DomainsAggregator } from './aggregator.js';
import { isEmpty } from '../../support/util.js';

export default class DomainsPlugin extends SitespeedioPlugin {
constructor(options, context, queue) {
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/graphite/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import isEmpty from 'lodash.isempty';
import merge from 'lodash.merge';
import get from 'lodash.get';
import dayjs from 'dayjs';
import { getLogger } from '@sitespeed.io/log';
import { SitespeedioPlugin } from '@sitespeed.io/plugin';

import { isEmpty } from '../../support/util.js';

import { send } from './send-annotation.js';
import { GraphiteDataGenerator as DataGenerator } from './data-generator.js';
import { isStatsD } from './helpers/is-statsd.js';
Expand Down
3 changes: 1 addition & 2 deletions lib/plugins/html/htmlBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getLogger } from '@sitespeed.io/log';
import { markdown } from 'markdown';
import merge from 'lodash.merge';
import get from 'lodash.get';
import isEmpty from 'lodash.isempty';

const log = getLogger('sitespeedio.plugin.html');
const require = createRequire(import.meta.url);
Expand All @@ -27,7 +26,7 @@ import detailedSetup from './setup/detailed.js';
import { getFilmstrip } from '../browsertime/filmstrip.js';
import getScripts from './getScripts.js';
import friendlyNames from '../../support/friendlynames.js';
import { toArray } from '../../support/util.js';
import { toArray, isEmpty } from '../../support/util.js';
import { getOS, osName } from '../../support/osUtil.js';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
Expand Down
3 changes: 1 addition & 2 deletions lib/plugins/influxdb/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import isEmpty from 'lodash.isempty';
import { getLogger } from '@sitespeed.io/log';
import dayjs from 'dayjs';

Expand All @@ -8,7 +7,7 @@ import { InfluxDB2Sender as SenderV2 } from './senderV2.js';
import { sendV1 } from './send-annotation.js';
import { sendV2 } from './send-annotationV2.js';
import { InfluxDBDataGenerator as DataGenerator } from './data-generator.js';
import { throwIfMissing } from '../../support/util.js';
import { throwIfMissing, isEmpty } from '../../support/util.js';

const log = getLogger('sitespeedio.plugin.influxdb');
export default class InfluxDBPlugin extends SitespeedioPlugin {
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/messagelogger/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint no-console:0 */

import { getLogger } from '@sitespeed.io/log';
import isEmpty from 'lodash.isempty';
import { SitespeedioPlugin } from '@sitespeed.io/plugin';

import { isEmpty } from '../../support/util.js';

const log = getLogger('sitespeedio.plugin.messagelogger');

function shortenData(key, value) {
Expand Down
3 changes: 1 addition & 2 deletions lib/support/metricsFilter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import isEmpty from 'lodash.isempty';
import get from 'lodash.get';
import set from 'lodash.set';
import merge from 'lodash.merge';
import reduce from 'lodash.reduce';

import { toArray } from './util.js';
import { toArray, isEmpty } from './util.js';

function normalizePath(path) {
if (path.endsWith('.*')) return path.slice(0, -2);
Expand Down
24 changes: 24 additions & 0 deletions lib/support/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,27 @@ export function throwIfMissing(options, keys, namespace) {
);
}
}

export function isEmpty(value) {
if (value === null) return true;

if (value === undefined) return true;

if (typeof value === 'boolean') return false;

if (typeof value === 'number') return false;

if (typeof value === 'string') return value.length === 0;

if (typeof value === 'function') return false;

if (Array.isArray(value)) return value.length === 0;

if (value instanceof Map || value instanceof Set) return value.size === 0;

if (typeof value === 'object') {
return Object.keys(value).length === 0;
}

return false;
}
6 changes: 0 additions & 6 deletions npm-shrinkwrap.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 @@ -100,7 +100,6 @@
"jstransformer-markdown-it": "3.0.0",
"junit-report-builder": "3.2.1",
"lodash.get": "4.4.2",
"lodash.isempty": "4.4.0",
"lodash.merge": "4.6.2",
"lodash.reduce": "4.6.0",
"lodash.set": "4.3.2",
Expand Down

0 comments on commit 25c5f38

Please sign in to comment.