Use Array.includes and String.includes

pull/1441/head
Simon Legner 1 year ago
parent f364659d97
commit 82fd7e6547

@ -119,7 +119,7 @@ class App extends Events {
bootAll() {
const docs = this.settings.getDocs();
for (var doc of this.DOCS) {
(docs.indexOf(doc.slug) >= 0 ? this.docs : this.disabledDocs).add(doc);
(docs.includes(doc.slug) ? this.docs : this.disabledDocs).add(doc);
}
this.migrateDocs();
this.docs.load(this.start.bind(this), this.onBootError.bind(this), {
@ -267,7 +267,7 @@ class App extends Events {
return;
}
const tips = this.settings.getTips();
if (tips.indexOf(tip) === -1) {
if (!tips.includes(tip)) {
tips.push(tip);
this.settings.setTips(tips);
new app.views.Tip(tip);
@ -358,11 +358,7 @@ Please check your browser extensions/addons. `);
isAppError(error, file) {
// Ignore errors from external scripts.
return (
file &&
file.indexOf("devdocs") !== -1 &&
file.indexOf(".js") === file.length - 3
);
return file && file.includes("devdocs") && file.endsWith(".js");
}
isSupportedBrowser() {
@ -414,7 +410,7 @@ Please check your browser extensions/addons. `);
isInvalidLocation() {
return (
this.config.env === "production" &&
location.host.indexOf(app.config.production_host) !== 0
!location.host.startsWith(app.config.production_host)
);
}
}

@ -106,7 +106,7 @@ function scoreExactMatch() {
}
function fuzzyMatch() {
if (valueLength <= queryLength || value.indexOf(query) >= 0) {
if (valueLength <= queryLength || value.includes(query)) {
return;
}
if (!(match = fuzzyRegexp.exec(value))) {

@ -109,7 +109,7 @@ app.Settings = class Settings {
$.arrayDelete(layout, "");
if (enable) {
if (layout.indexOf(name) === -1) {
if (!layout.includes(name)) {
layout.push(name);
}
} else {
@ -125,7 +125,7 @@ app.Settings = class Settings {
hasLayout(name) {
const layout = (this.store.get("layout") || "").split(" ");
return layout.indexOf(name) !== -1;
return layout.includes(name);
}
setSize(value) {
@ -155,7 +155,7 @@ app.Settings = class Settings {
}
for (key in data) {
value = data[key];
if (Settings.PREFERENCE_KEYS.indexOf(key) !== -1) {
if (Settings.PREFERENCE_KEYS.includes(key)) {
this.set(key, value);
}
}

@ -75,7 +75,7 @@ this.viewTree = function (view, level, visited) {
if (visited == null) {
visited = [];
}
if (visited.indexOf(view) >= 0) {
if (visited.includes(view)) {
return;
}
visited.push(view);

@ -1,6 +1,6 @@
class Events {
on(event, callback) {
if (event.indexOf(" ") >= 0) {
if (event.includes(" ")) {
for (var name of event.split(" ")) {
this.on(name, callback);
}
@ -14,7 +14,7 @@ class Events {
off(event, callback) {
let callbacks, index;
if (event.indexOf(" ") >= 0) {
if (event.includes(" ")) {
for (var name of event.split(" ")) {
this.off(name, callback);
}

@ -284,7 +284,7 @@ var onclick = function (event) {
};
var isSameOrigin = (url) =>
url.indexOf(`${location.protocol}//${location.hostname}`) === 0;
url.startsWith(`${location.protocol}//${location.hostname}`);
var updateCanonicalLink = function () {
if (!this.canonicalLink) {

@ -61,7 +61,7 @@ $.on = function (el, event, callback, useCapture) {
if (useCapture == null) {
useCapture = false;
}
if (event.indexOf(" ") >= 0) {
if (event.includes(" ")) {
for (var name of event.split(" ")) {
$.on(el, name, callback);
}
@ -74,7 +74,7 @@ $.off = function (el, event, callback, useCapture) {
if (useCapture == null) {
useCapture = false;
}
if (event.indexOf(" ") >= 0) {
if (event.includes(" ")) {
for (var name of event.split(" ")) {
$.off(el, name, callback);
}
@ -520,55 +520,37 @@ $.popup = function (value) {
let isMac = null;
$.isMac = () =>
isMac != null
? isMac
: (isMac =
(navigator.userAgent != null
? navigator.userAgent.indexOf("Mac")
: undefined) >= 0);
isMac != null ? isMac : (isMac = navigator.userAgent.includes("Mac"));
let isIE = null;
$.isIE = () =>
isIE != null
? isIE
: (isIE =
(navigator.userAgent != null
? navigator.userAgent.indexOf("MSIE")
: undefined) >= 0 ||
(navigator.userAgent != null
? navigator.userAgent.indexOf("rv:11.0")
: undefined) >= 0);
navigator.userAgent.includes("MSIE") ||
navigator.userAgent.includes("rv:11.0"));
let isChromeForAndroid = null;
$.isChromeForAndroid = () =>
isChromeForAndroid != null
? isChromeForAndroid
: (isChromeForAndroid =
(navigator.userAgent != null
? navigator.userAgent.indexOf("Android")
: undefined) >= 0 &&
navigator.userAgent.includes("Android") &&
/Chrome\/([.0-9])+ Mobile/.test(navigator.userAgent));
let isAndroid = null;
$.isAndroid = () =>
isAndroid != null
? isAndroid
: (isAndroid =
(navigator.userAgent != null
? navigator.userAgent.indexOf("Android")
: undefined) >= 0);
: (isAndroid = navigator.userAgent.includes("Android"));
let isIOS = null;
$.isIOS = () =>
isIOS != null
? isIOS
: (isIOS =
(navigator.userAgent != null
? navigator.userAgent.indexOf("iPhone")
: undefined) >= 0 ||
(navigator.userAgent != null
? navigator.userAgent.indexOf("iPad")
: undefined) >= 0);
navigator.userAgent.includes("iPhone") ||
navigator.userAgent.includes("iPad"));
$.overlayScrollbarsEnabled = function () {
if (!$.isMac()) {

@ -24,9 +24,9 @@ app.views.Mobile = class Mobile extends app.View {
.matches ||
// Need to sniff the user agent because some Android and Windows Phone devices don't take
// resolution (dpi) into account when reporting device width/height.
(navigator.userAgent.indexOf("Android") !== -1 &&
navigator.userAgent.indexOf("Mobile") !== -1) ||
navigator.userAgent.indexOf("IEMobile") !== -1
(navigator.userAgent.includes("Android") &&
navigator.userAgent.includes("Mobile")) ||
navigator.userAgent.includes("IEMobile")
);
} catch (error) {
return false;

@ -65,7 +65,7 @@ app.views.Settings = class Settings extends app.View {
(() => {
const result = [];
for (var doc of app.docs.all()) {
if (docs.indexOf(doc.slug) === -1) {
if (!docs.includes(doc.slug)) {
result.push(doc);
}
}

@ -56,7 +56,7 @@ app.views.ListFocus = class ListFocus extends app.View {
return this.findNext(cursor);
} else if (next.tagName === "DIV") {
// sub-list
if (cursor.className.indexOf(" open") >= 0) {
if (cursor.className.includes(" open")) {
return this.findFirst(next) || this.findNext(next);
} else {
return this.findNext(next);
@ -96,7 +96,7 @@ app.views.ListFocus = class ListFocus extends app.View {
return this.findPrev(cursor);
} else if (prev.tagName === "DIV") {
// sub-list
if (prev.previousSibling.className.indexOf("open") >= 0) {
if (prev.previousSibling.className.includes("open")) {
return this.findLast(prev) || this.findPrev(prev);
} else {
return this.findPrev(prev);

Loading…
Cancel
Save