Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace indexOf with equivalent includes and startsWith #3845

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vega-event-selector/src/event-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function find(s, i, endChar, pushChar, popChar) {
for (; i < n; ++i) {
c = s[i];
if (!count && c === endChar) return i;
else if (popChar && popChar.indexOf(c) >= 0) --count;
else if (pushChar && pushChar.indexOf(c) >= 0) ++count;
else if (popChar && popChar.includes(c)) --count;
else if (pushChar && pushChar.includes(c)) ++count;
}
return i;
}
Expand Down
14 changes: 7 additions & 7 deletions packages/vega-expression/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@ function isDecimalDigit(ch) {
}

function isHexDigit(ch) {
return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;
return '0123456789abcdefABCDEF'.includes(ch);
}

function isOctalDigit(ch) {
return '01234567'.indexOf(ch) >= 0;
return '01234567'.includes(ch);
}

// 7.2 White Space

function isWhiteSpace(ch) {
return (ch === 0x20) || (ch === 0x09) || (ch === 0x0B) || (ch === 0x0C) || (ch === 0xA0) ||
(ch >= 0x1680 && [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(ch) >= 0);
(ch >= 0x1680 && [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].includes(ch));
}

// 7.3 Line Terminators
Expand Down Expand Up @@ -426,7 +426,7 @@ function scanPunctuator() {
// Other 2-character punctuators: ++ -- << >> && ||
ch2 = ch3.substr(0, 2);

if ((ch1 === ch2[1] && ('+-<>&|'.indexOf(ch1) >= 0)) || ch2 === '=>') {
if ((ch1 === ch2[1] && ('+-<>&|'.includes(ch1))) || ch2 === '=>') {
index += 2;
return {
type: TokenPunctuator,
Expand All @@ -442,7 +442,7 @@ function scanPunctuator() {

// 1-character punctuators: < > = ! + - * % & | ^ /

if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {
if ('<>=!+-*%&|^/'.includes(ch1)) {
++index;
return {
type: TokenPunctuator,
Expand Down Expand Up @@ -643,7 +643,7 @@ function scanStringLiteral() {

// 3 digits are only allowed when string starts
// with 0, 1, 2, 3
if ('0123'.indexOf(ch) >= 0 &&
if ('0123'.includes(ch) &&
index < length &&
isOctalDigit(source[index])) {
code = code * 8 + '01234567'.indexOf(source[index++]);
Expand Down Expand Up @@ -683,7 +683,7 @@ function scanStringLiteral() {
function testRegExp(pattern, flags) {
let tmp = pattern;

if (flags.indexOf('u') >= 0) {
if (flags.includes('u')) {
// Replace each astral symbol and every Unicode code point
// escape sequence with a single ASCII symbol to avoid throwing on
// regular expressions that are only valid in combination with the
Expand Down
2 changes: 1 addition & 1 deletion packages/vega-parser/src/parsers/marks/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {MarkRole, ScopeRole} from './roles';

export default function(spec) {
const role = spec.role || '';
return (!role.indexOf('axis') || !role.indexOf('legend') || !role.indexOf('title'))
return (role.startsWith('axis') || role.startsWith('legend') || role.startsWith('title'))
? role
: spec.type === GroupMark ? ScopeRole : (role || MarkRole);
}
4 changes: 2 additions & 2 deletions packages/vega-selections/src/selectionResolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ var ops = {
if (!base.length) return value;

var i = 0, n = value.length;
for (; i<n; ++i) if (base.indexOf(value[i]) < 0) base.push(value[i]);
for (; i<n; ++i) if (!base.includes(value[i])) base.push(value[i]);
return base;
},

E_intersect: function(base, value) {
return !base.length ? value :
base.filter(v => value.indexOf(v) >= 0);
base.filter(v => value.includes(v));
},

R_union: function(base, value) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vega-selections/src/selectionTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function testPoint(datum, entry) {
if (f.type === TYPE_ENUM) {
// Enumerated fields can either specify individual values (single/multi selections)
// or an array of values (interval selections).
if(isArray(values[i]) ? values[i].indexOf(dval) < 0 : dval !== values[i]) {
if(isArray(values[i]) ? !values[i].includes(dval) : dval !== values[i]) {
return false;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/vega-view/src/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ inherits(View, Dataflow, {

addResizeListener(handler) {
const l = this._resizeListeners;
if (l.indexOf(handler) < 0) {
if (!l.includes(handler)) {
// add handler if it isn't already registered
// note: error trapping handled elsewhere, so
// no need to wrap handlers here
Expand Down
2 changes: 1 addition & 1 deletion packages/vega-view/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function getState(options) {
function dataTest(name, data) {
return data.modified
&& isArray(data.input.value)
&& name.indexOf('_:vega:_');
&& !name.startsWith('_:vega:_');
}

function signalTest(name, op) {
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default function(commandLineArgs) {

const outputs = [{
input: './index.js',
external: dependencies.filter(dep => esmDeps.indexOf(dep) < 0),
external: dependencies.filter(dep => !esmDeps.includes(dep)),
onwarn,
output: {
file: pkg.main,
Expand Down