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() { bootAll() {
const docs = this.settings.getDocs(); const docs = this.settings.getDocs();
for (var doc of this.DOCS) { 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.migrateDocs();
this.docs.load(this.start.bind(this), this.onBootError.bind(this), { this.docs.load(this.start.bind(this), this.onBootError.bind(this), {
@ -267,7 +267,7 @@ class App extends Events {
return; return;
} }
const tips = this.settings.getTips(); const tips = this.settings.getTips();
if (tips.indexOf(tip) === -1) { if (!tips.includes(tip)) {
tips.push(tip); tips.push(tip);
this.settings.setTips(tips); this.settings.setTips(tips);
new app.views.Tip(tip); new app.views.Tip(tip);
@ -358,11 +358,7 @@ Please check your browser extensions/addons. `);
isAppError(error, file) { isAppError(error, file) {
// Ignore errors from external scripts. // Ignore errors from external scripts.
return ( return file && file.includes("devdocs") && file.endsWith(".js");
file &&
file.indexOf("devdocs") !== -1 &&
file.indexOf(".js") === file.length - 3
);
} }
isSupportedBrowser() { isSupportedBrowser() {
@ -414,7 +410,7 @@ Please check your browser extensions/addons. `);
isInvalidLocation() { isInvalidLocation() {
return ( return (
this.config.env === "production" && 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() { function fuzzyMatch() {
if (valueLength <= queryLength || value.indexOf(query) >= 0) { if (valueLength <= queryLength || value.includes(query)) {
return; return;
} }
if (!(match = fuzzyRegexp.exec(value))) { if (!(match = fuzzyRegexp.exec(value))) {

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

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

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

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

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

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

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

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

Loading…
Cancel
Save