Skip to content

Commit 82fd7e6

Browse files
committed
Use Array.includes and String.includes
1 parent f364659 commit 82fd7e6

10 files changed

Lines changed: 27 additions & 49 deletions

File tree

assets/javascripts/app/app.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class App extends Events {
119119
bootAll() {
120120
const docs = this.settings.getDocs();
121121
for (var doc of this.DOCS) {
122-
(docs.indexOf(doc.slug) >= 0 ? this.docs : this.disabledDocs).add(doc);
122+
(docs.includes(doc.slug) ? this.docs : this.disabledDocs).add(doc);
123123
}
124124
this.migrateDocs();
125125
this.docs.load(this.start.bind(this), this.onBootError.bind(this), {
@@ -267,7 +267,7 @@ class App extends Events {
267267
return;
268268
}
269269
const tips = this.settings.getTips();
270-
if (tips.indexOf(tip) === -1) {
270+
if (!tips.includes(tip)) {
271271
tips.push(tip);
272272
this.settings.setTips(tips);
273273
new app.views.Tip(tip);
@@ -358,11 +358,7 @@ Please check your browser extensions/addons. `);
358358

359359
isAppError(error, file) {
360360
// Ignore errors from external scripts.
361-
return (
362-
file &&
363-
file.indexOf("devdocs") !== -1 &&
364-
file.indexOf(".js") === file.length - 3
365-
);
361+
return file && file.includes("devdocs") && file.endsWith(".js");
366362
}
367363

368364
isSupportedBrowser() {
@@ -414,7 +410,7 @@ Please check your browser extensions/addons. `);
414410
isInvalidLocation() {
415411
return (
416412
this.config.env === "production" &&
417-
location.host.indexOf(app.config.production_host) !== 0
413+
!location.host.startsWith(app.config.production_host)
418414
);
419415
}
420416
}

assets/javascripts/app/searcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function scoreExactMatch() {
106106
}
107107

108108
function fuzzyMatch() {
109-
if (valueLength <= queryLength || value.indexOf(query) >= 0) {
109+
if (valueLength <= queryLength || value.includes(query)) {
110110
return;
111111
}
112112
if (!(match = fuzzyRegexp.exec(value))) {

assets/javascripts/app/settings.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ app.Settings = class Settings {
109109
$.arrayDelete(layout, "");
110110

111111
if (enable) {
112-
if (layout.indexOf(name) === -1) {
112+
if (!layout.includes(name)) {
113113
layout.push(name);
114114
}
115115
} else {
@@ -125,7 +125,7 @@ app.Settings = class Settings {
125125

126126
hasLayout(name) {
127127
const layout = (this.store.get("layout") || "").split(" ");
128-
return layout.indexOf(name) !== -1;
128+
return layout.includes(name);
129129
}
130130

131131
setSize(value) {
@@ -155,7 +155,7 @@ app.Settings = class Settings {
155155
}
156156
for (key in data) {
157157
value = data[key];
158-
if (Settings.PREFERENCE_KEYS.indexOf(key) !== -1) {
158+
if (Settings.PREFERENCE_KEYS.includes(key)) {
159159
this.set(key, value);
160160
}
161161
}

assets/javascripts/debug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ this.viewTree = function (view, level, visited) {
7575
if (visited == null) {
7676
visited = [];
7777
}
78-
if (visited.indexOf(view) >= 0) {
78+
if (visited.includes(view)) {
7979
return;
8080
}
8181
visited.push(view);

assets/javascripts/lib/events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Events {
22
on(event, callback) {
3-
if (event.indexOf(" ") >= 0) {
3+
if (event.includes(" ")) {
44
for (var name of event.split(" ")) {
55
this.on(name, callback);
66
}
@@ -14,7 +14,7 @@ class Events {
1414

1515
off(event, callback) {
1616
let callbacks, index;
17-
if (event.indexOf(" ") >= 0) {
17+
if (event.includes(" ")) {
1818
for (var name of event.split(" ")) {
1919
this.off(name, callback);
2020
}

assets/javascripts/lib/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ var onclick = function (event) {
284284
};
285285

286286
var isSameOrigin = (url) =>
287-
url.indexOf(`${location.protocol}//${location.hostname}`) === 0;
287+
url.startsWith(`${location.protocol}//${location.hostname}`);
288288

289289
var updateCanonicalLink = function () {
290290
if (!this.canonicalLink) {

assets/javascripts/lib/util.js

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ $.on = function (el, event, callback, useCapture) {
6161
if (useCapture == null) {
6262
useCapture = false;
6363
}
64-
if (event.indexOf(" ") >= 0) {
64+
if (event.includes(" ")) {
6565
for (var name of event.split(" ")) {
6666
$.on(el, name, callback);
6767
}
@@ -74,7 +74,7 @@ $.off = function (el, event, callback, useCapture) {
7474
if (useCapture == null) {
7575
useCapture = false;
7676
}
77-
if (event.indexOf(" ") >= 0) {
77+
if (event.includes(" ")) {
7878
for (var name of event.split(" ")) {
7979
$.off(el, name, callback);
8080
}
@@ -520,55 +520,37 @@ $.popup = function (value) {
520520

521521
let isMac = null;
522522
$.isMac = () =>
523-
isMac != null
524-
? isMac
525-
: (isMac =
526-
(navigator.userAgent != null
527-
? navigator.userAgent.indexOf("Mac")
528-
: undefined) >= 0);
523+
isMac != null ? isMac : (isMac = navigator.userAgent.includes("Mac"));
529524

530525
let isIE = null;
531526
$.isIE = () =>
532527
isIE != null
533528
? isIE
534529
: (isIE =
535-
(navigator.userAgent != null
536-
? navigator.userAgent.indexOf("MSIE")
537-
: undefined) >= 0 ||
538-
(navigator.userAgent != null
539-
? navigator.userAgent.indexOf("rv:11.0")
540-
: undefined) >= 0);
530+
navigator.userAgent.includes("MSIE") ||
531+
navigator.userAgent.includes("rv:11.0"));
541532

542533
let isChromeForAndroid = null;
543534
$.isChromeForAndroid = () =>
544535
isChromeForAndroid != null
545536
? isChromeForAndroid
546537
: (isChromeForAndroid =
547-
(navigator.userAgent != null
548-
? navigator.userAgent.indexOf("Android")
549-
: undefined) >= 0 &&
538+
navigator.userAgent.includes("Android") &&
550539
/Chrome\/([.0-9])+ Mobile/.test(navigator.userAgent));
551540

552541
let isAndroid = null;
553542
$.isAndroid = () =>
554543
isAndroid != null
555544
? isAndroid
556-
: (isAndroid =
557-
(navigator.userAgent != null
558-
? navigator.userAgent.indexOf("Android")
559-
: undefined) >= 0);
545+
: (isAndroid = navigator.userAgent.includes("Android"));
560546

561547
let isIOS = null;
562548
$.isIOS = () =>
563549
isIOS != null
564550
? isIOS
565551
: (isIOS =
566-
(navigator.userAgent != null
567-
? navigator.userAgent.indexOf("iPhone")
568-
: undefined) >= 0 ||
569-
(navigator.userAgent != null
570-
? navigator.userAgent.indexOf("iPad")
571-
: undefined) >= 0);
552+
navigator.userAgent.includes("iPhone") ||
553+
navigator.userAgent.includes("iPad"));
572554

573555
$.overlayScrollbarsEnabled = function () {
574556
if (!$.isMac()) {

assets/javascripts/views/layout/mobile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ app.views.Mobile = class Mobile extends app.View {
2424
.matches ||
2525
// Need to sniff the user agent because some Android and Windows Phone devices don't take
2626
// resolution (dpi) into account when reporting device width/height.
27-
(navigator.userAgent.indexOf("Android") !== -1 &&
28-
navigator.userAgent.indexOf("Mobile") !== -1) ||
29-
navigator.userAgent.indexOf("IEMobile") !== -1
27+
(navigator.userAgent.includes("Android") &&
28+
navigator.userAgent.includes("Mobile")) ||
29+
navigator.userAgent.includes("IEMobile")
3030
);
3131
} catch (error) {
3232
return false;

assets/javascripts/views/layout/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ app.views.Settings = class Settings extends app.View {
6565
(() => {
6666
const result = [];
6767
for (var doc of app.docs.all()) {
68-
if (docs.indexOf(doc.slug) === -1) {
68+
if (!docs.includes(doc.slug)) {
6969
result.push(doc);
7070
}
7171
}

assets/javascripts/views/list/list_focus.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ app.views.ListFocus = class ListFocus extends app.View {
5656
return this.findNext(cursor);
5757
} else if (next.tagName === "DIV") {
5858
// sub-list
59-
if (cursor.className.indexOf(" open") >= 0) {
59+
if (cursor.className.includes(" open")) {
6060
return this.findFirst(next) || this.findNext(next);
6161
} else {
6262
return this.findNext(next);
@@ -96,7 +96,7 @@ app.views.ListFocus = class ListFocus extends app.View {
9696
return this.findPrev(cursor);
9797
} else if (prev.tagName === "DIV") {
9898
// sub-list
99-
if (prev.previousSibling.className.indexOf("open") >= 0) {
99+
if (prev.previousSibling.className.includes("open")) {
100100
return this.findLast(prev) || this.findPrev(prev);
101101
} else {
102102
return this.findPrev(prev);

0 commit comments

Comments
 (0)