Skip to content

Commit

Permalink
Core: Remove inArray with native array.includes()
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Jan 23, 2023
1 parent 4ef04c1 commit f68708f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
12 changes: 0 additions & 12 deletions src/core/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@ export function diff (a, b) {
return a.filter((a) => b.indexOf(a) === -1);
}

/**
* Determines whether an element exists in a given array or not.
*
* @method inArray
* @param {any} elem
* @param {Array} array
* @return {boolean}
*/
export function inArray (elem, array) {
return array.indexOf(elem) !== -1;
}

/**
* Recursively clone an object into a plain array or object, taking only the
* own enumerable properties.
Expand Down
4 changes: 2 additions & 2 deletions src/dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// -------

import config from './core/config';
import { inArray, toString, is } from './core/utilities';
import { toString, is } from './core/utilities';

export default (function () {
function quote (str) {
Expand Down Expand Up @@ -222,7 +222,7 @@ export default (function () {
const nonEnumerableProperties = ['message', 'name'];
for (const i in nonEnumerableProperties) {
const key = nonEnumerableProperties[i];
if (key in map && !inArray(key, keys)) {
if (key in map && !keys.includes(key)) {
keys.push(key);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { inArray } from './core/utilities';

const LISTENERS = Object.create(null);
const SUPPORTED_EVENTS = [
'error',
Expand Down Expand Up @@ -50,7 +48,7 @@ export function emit (eventName, data) {
export function on (eventName, callback) {
if (typeof eventName !== 'string') {
throw new TypeError('eventName must be a string when registering a listener');
} else if (!inArray(eventName, SUPPORTED_EVENTS)) {
} else if (!SUPPORTED_EVENTS.includes(eventName)) {
const events = SUPPORTED_EVENTS.join(', ');
throw new Error(`"${eventName}" is not a valid event; must be one of: ${events}.`);
} else if (typeof callback !== 'function') {
Expand All @@ -62,7 +60,7 @@ export function on (eventName, callback) {
}

// Don't register the same callback more than once
if (!inArray(callback, LISTENERS[eventName])) {
if (!LISTENERS[eventName].includes(callback)) {
LISTENERS[eventName].push(callback);
}
}
5 changes: 2 additions & 3 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
extend,
generateHash,
hasOwn,
inArray,
performance
} from './core/utilities';
import { runLoggingCallbacks } from './core/logging';
Expand Down Expand Up @@ -805,7 +804,7 @@ Test.prototype = {
return (
// undefined or empty array
!selectedId || !selectedId.length ||
inArray(testModule.moduleId, selectedId) || (
selectedId.includes(testModule.moduleId) || (
testModule.parentModule && moduleChainIdMatch(testModule.parentModule, selectedId)
)
);
Expand All @@ -815,7 +814,7 @@ Test.prototype = {
return false;
}

if (config.testId && config.testId.length && !inArray(this.testId, config.testId)) {
if (config.testId && config.testId.length && !config.testId.includes(this.testId)) {
return false;
}

Expand Down

0 comments on commit f68708f

Please sign in to comment.