History

Use Array.includes and String.includes

Simon Legner committed 2 years ago

Commit 82fd7e61 parent f36465910 files · +27 −49Browse files

Unified · Split

10 files
  1. assets/javascripts/app/app.js +4 −8
  2. assets/javascripts/app/searcher.js +1 −1
  3. assets/javascripts/app/settings.js +3 −3
  4. assets/javascripts/debug.js +1 −1
  5. assets/javascripts/lib/events.js +2 −2
  6. assets/javascripts/lib/page.js +1 −1
  7. assets/javascripts/lib/util.js +9 −27
  8. assets/javascripts/views/layout/mobile.js +3 −3
  9. assets/javascripts/views/layout/settings.js +1 −1
  10. assets/javascripts/views/list/list_focus.js +2 −2
assets/javascripts/app/app.js+4−8
@@ -119,7 +119,7 @@ class App extends Events { · 118 unmodified lines
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 { · 141 unmodified lines
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. `); · 84 unmodified lines
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. `); · 45 unmodified lines
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+1−1
@@ -106,7 +106,7 @@ function scoreExactMatch() { · 105 unmodified lines
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+3−3
@@ -109,7 +109,7 @@ app.Settings = class Settings { · 108 unmodified lines
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 { · 9 unmodified lines
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 { · 23 unmodified lines
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+1−1
@@ -75,7 +75,7 @@ this.viewTree = function (view, level, visited) { · 74 unmodified lines
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+2−2
@@ -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 { · 7 unmodified lines
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+1−1
@@ -284,7 +284,7 @@ var onclick = function (event) { · 283 unmodified lines
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+9−27
@@ -61,7 +61,7 @@ $.on = function (el, event, callback, useCapture) { · 60 unmodified lines
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) { · 6 unmodified lines
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) { · 439 unmodified lines
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+3−3
@@ -24,9 +24,9 @@ app.views.Mobile = class Mobile extends app.View { · 23 unmodified lines
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+1−1
@@ -65,7 +65,7 @@ app.views.Settings = class Settings extends app.View { · 64 unmodified lines
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+2−2
@@ -56,7 +56,7 @@ app.views.ListFocus = class ListFocus extends app.View { · 55 unmodified lines
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 { · 33 unmodified lines
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);