Skip to content

Commit

Permalink
Replace lodash.isEmpty (#2241)
Browse files Browse the repository at this point in the history
* Replace lodash.isEmpty
  • Loading branch information
soulgalore authored Jan 4, 2025
1 parent 47411e5 commit 81b5db5
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 24 deletions.
3 changes: 1 addition & 2 deletions lib/chrome/webdriver/builder.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 { logging } from 'selenium-webdriver';
import { ServiceBuilder, Options } from 'selenium-webdriver/chrome.js';
import { pac, manual } from 'selenium-webdriver/proxy.js';
import { setupChromiumOptions } from './setupChromiumOptions.js';
import { pick } from '../../support/util.js';
import { pick, isEmpty } from '../../support/util.js';

/**
* Configure a WebDriver builder based on the specified options.
Expand Down
2 changes: 1 addition & 1 deletion lib/core/webdriver/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Builder } from 'selenium-webdriver';
import isEmpty from 'lodash.isempty';
import { configureBuilder as configureBuilderChrome } from '../../chrome/webdriver/builder.js';
import { configureBuilder as configureBuilderEdge } from '../../edge/webdriver/builder.js';
import { configureBuilder as configureBuilderFirefox } from '../../firefox/webdriver/builder.js';
import { configureBuilder as configureBuilderSafari } from '../../safari/webdriver/builder.js';
import { isEmpty } from '../../support/util.js';

/**
* Create a new WebDriver instance based on the specified options.
Expand Down
3 changes: 1 addition & 2 deletions lib/edge/webdriver/builder.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Options, ServiceBuilder } from 'selenium-webdriver/edge.js';
import intel from 'intel';
import get from 'lodash.get';
import isEmpty from 'lodash.isempty';
import { logging } from 'selenium-webdriver';
import { setupChromiumOptions } from '../../chrome/webdriver/setupChromiumOptions.js';
const log = intel.getLogger('browsertime.edge');
const { pac, manual } = 'selenium-webdriver/proxy.js';
import { pick } from '../../support/util.js';
import { pick, isEmpty } from '../../support/util.js';

export async function configureBuilder(builder, baseDir, options) {
const edgeConfig = options.edge || {};
Expand Down
3 changes: 1 addition & 2 deletions lib/firefox/webdriver/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import {
} from 'selenium-webdriver/firefox.js';
import intel from 'intel';
import { pac, manual } from 'selenium-webdriver/proxy.js';
import isEmpty from 'lodash.isempty';
import get from 'lodash.get';
import { defaultFirefoxPreferences } from '../settings/firefoxPreferences.js';
import { disableSafeBrowsingPreferences } from '../settings/disableSafeBrowsingPreferences.js';
import { disableTrackingProtectionPreferences } from '../settings/disableTrackingProtectionPreferences.js';
import { toArray, pick } from '../../support/util.js';
import { toArray, pick, isEmpty } from '../../support/util.js';
import { Android, isAndroidConfigured } from '../../android/index.js';
const log = intel.getLogger('browsertime.firefox');

Expand Down
3 changes: 1 addition & 2 deletions lib/support/har/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { createRequire } from 'node:module';
import merge from 'lodash.merge';
import isEmpty from 'lodash.isempty';
import get from 'lodash.get';
import { pathToFolder } from '../pathToFolder.js';
import { localTime } from '../util.js';
import intel from 'intel';
const log = intel.getLogger('browsertime');
const require = createRequire(import.meta.url);
const version = require('../../../package.json').version;
import { pick } from '../../support/util.js';
import { pick, isEmpty } from '../../support/util.js';

function generateUniquePageId(baseId, existingIdMap) {
let newId = baseId;
Expand Down
2 changes: 1 addition & 1 deletion lib/support/pathToFolder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parse } from 'node:url';
import { createHash } from 'node:crypto';
import isEmpty from 'lodash.isempty';
import intel from 'intel';
import { isEmpty } from './util.js';
const log = intel.getLogger('browsertime');

function toSafeKey(key) {
Expand Down
3 changes: 1 addition & 2 deletions lib/support/storageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import {
createReadStream,
createWriteStream
} from 'node:fs';
import isEmpty from 'lodash.isempty';
import intel from 'intel';
import { localTime } from './util.js';
import { localTime, isEmpty } from './util.js';

const gunzip = promisify(_gunzip);
const writeFile = promisify(_writeFile);
Expand Down
24 changes: 24 additions & 0 deletions lib/support/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,30 @@ export function pick(obj, keys) {
return result;
}

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;
}

function groupBy(array, property) {
const grouped = {};
for (const item of array) {
Expand Down
11 changes: 0 additions & 11 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 @@ -21,7 +21,6 @@
"get-port": "7.1.0",
"intel": "1.2.0",
"lodash.get": "4.4.2",
"lodash.isempty": "4.4.0",
"lodash.merge": "4.6.2",
"lodash.set": "4.3.2",
"selenium-webdriver": "4.27.0",
Expand Down

0 comments on commit 81b5db5

Please sign in to comment.