Make everything prefer-const clean
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 30 Oct 2020 10:45:43 +0000 (11:45 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 30 Oct 2020 11:26:18 +0000 (12:26 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js
wcfsetup/install/files/js/WoltLabSuite/Core/Core.js
wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Article/Search.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Suggestion.js
wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/Search.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Suggestion.ts

index db9825c9b5e11b348334c5c9fa46393fd8fdb402..34fedc4e7cb02f8996ecba8680c7d6195bac1941 100644 (file)
@@ -18,14 +18,13 @@ define(["require", "exports"], function (require, exports) {
      */
     function hsvToRgb(h, s, v) {
         const rgb = { r: 0, g: 0, b: 0 };
-        let h2, f, p, q, t;
-        h2 = Math.floor(h / 60);
-        f = h / 60 - h2;
+        const h2 = Math.floor(h / 60);
+        const f = h / 60 - h2;
         s /= 100;
         v /= 100;
-        p = v * (1 - s);
-        q = v * (1 - s * f);
-        t = v * (1 - s * (1 - f));
+        const p = v * (1 - s);
+        const q = v * (1 - s * f);
+        const t = v * (1 - s * (1 - f));
         if (s == 0) {
             rgb.r = rgb.g = rgb.b = v;
         }
@@ -77,14 +76,13 @@ define(["require", "exports"], function (require, exports) {
      * @see  https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV
      */
     function rgbToHsv(r, g, b) {
-        let h, s, v;
-        let max, min, diff;
+        let h, s;
         r /= 255;
         g /= 255;
         b /= 255;
-        max = Math.max(Math.max(r, g), b);
-        min = Math.min(Math.min(r, g), b);
-        diff = max - min;
+        const max = Math.max(Math.max(r, g), b);
+        const min = Math.min(Math.min(r, g), b);
+        const diff = max - min;
         h = 0;
         if (max !== min) {
             switch (max) {
@@ -108,7 +106,7 @@ define(["require", "exports"], function (require, exports) {
         else {
             s = diff / max;
         }
-        v = max;
+        const v = max;
         return {
             h: Math.round(h),
             s: Math.round(s * 100),
index 6de797b09ebd953304bedf404aad30b6ccf68302..d1c1f5f0e0f1ee8a27a9de5e2af5d69aacfa053e 100644 (file)
@@ -163,7 +163,7 @@ define(["require", "exports"], function (require, exports) {
      * Recursively serializes an object into an encoded URI parameter string.
      */
     function serialize(obj, prefix) {
-        let parameters = [];
+        const parameters = [];
         for (const key in obj) {
             if (obj.hasOwnProperty(key)) {
                 const parameterKey = prefix ? prefix + "[" + key + "]" : key;
index db7b0ed5501719821ef312d2b7bba12dc9db7642..b6798a91a5be06502e8810fd95b5714653066460 100644 (file)
@@ -256,7 +256,7 @@ define(["require", "exports", "tslib", "../StringUtil"], function (require, expo
                 if (attribute.name.indexOf(prefix) === 0) {
                     let name = attribute.name.replace(new RegExp("^" + prefix), "");
                     if (camelCaseName) {
-                        let tmp = name.split("-");
+                        const tmp = name.split("-");
                         name = "";
                         for (let j = 0, innerLength = tmp.length; j < innerLength; j++) {
                             if (name.length) {
@@ -284,7 +284,7 @@ define(["require", "exports", "tslib", "../StringUtil"], function (require, expo
             if (element.parentNode === null) {
                 throw new Error("The element has no parent.");
             }
-            let parent = element.parentNode;
+            const parent = element.parentNode;
             while (element.childNodes.length) {
                 parent.insertBefore(element.childNodes[0], element);
             }
index 95fd2b1ac4acc31ef26b17494c7ac0d0947df47d..ddf4e549632a7c105f602fdda0912e68cc92dfe8 100644 (file)
@@ -42,7 +42,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Dom/Util", "../../La
             Dialog_1.default.close(this);
         }
         _ajaxSuccess(data) {
-            let html = data.returnValues
+            const html = data.returnValues
                 .map((article) => {
                 return `<li>
           <div class="containerHeadline pointer" data-article-id="${article.articleID}">
@@ -53,7 +53,12 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Dom/Util", "../../La
             })
                 .join("");
             this.resultList.innerHTML = html;
-            Util_1.default[html ? "show" : "hide"](this.resultList);
+            if (html) {
+                Util_1.default.show(this.resultList);
+            }
+            else {
+                Util_1.default.hide(this.resultList);
+            }
             if (html) {
                 this.resultList.querySelectorAll(".containerHeadline").forEach((item) => {
                     item.addEventListener("click", this.click.bind(this));
index 49097db596cf4686afd585bdefd75e1428e064fc..70f8a6a418b788fcea0ff3c6b2dba9814695b8c7 100644 (file)
@@ -70,7 +70,8 @@ define(["require", "exports", "tslib", "../Ajax", "../Core", "./Dropdown/Simple"
                 return true;
             }
             let active;
-            let i = 0, length = this.dropdownMenu.childElementCount;
+            let i = 0;
+            const length = this.dropdownMenu.childElementCount;
             while (i < length) {
                 active = this.dropdownMenu.children[i];
                 if (active.classList.contains("active")) {
index 087fd6ca286965ad10430afc84c9eaa9bc857a95..2bc772f4de623c8e29ce1f292a97a7377ba881c7 100644 (file)
  */
 export function hsvToRgb(h: number, s: number, v: number): RGB {
   const rgb: RGB = { r: 0, g: 0, b: 0 };
-  let h2: number, f: number, p: number, q: number, t: number;
 
-  h2 = Math.floor(h / 60);
-  f = h / 60 - h2;
+  const h2 = Math.floor(h / 60);
+  const f = h / 60 - h2;
 
   s /= 100;
   v /= 100;
 
-  p = v * (1 - s);
-  q = v * (1 - s * f);
-  t = v * (1 - s * (1 - f));
+  const p = v * (1 - s);
+  const q = v * (1 - s * f);
+  const t = v * (1 - s * (1 - f));
 
   if (s == 0) {
     rgb.r = rgb.g = rgb.b = v;
@@ -83,16 +82,15 @@ export function hsvToRgb(h: number, s: number, v: number): RGB {
  * @see  https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV
  */
 export function rgbToHsv(r: number, g: number, b: number): HSV {
-  let h: number, s: number, v: number;
-  let max: number, min: number, diff: number;
+  let h: number, s: number;
 
   r /= 255;
   g /= 255;
   b /= 255;
 
-  max = Math.max(Math.max(r, g), b);
-  min = Math.min(Math.min(r, g), b);
-  diff = max - min;
+  const max = Math.max(Math.max(r, g), b);
+  const min = Math.min(Math.min(r, g), b);
+  const diff = max - min;
 
   h = 0;
   if (max !== min) {
@@ -121,7 +119,7 @@ export function rgbToHsv(r: number, g: number, b: number): HSV {
     s = diff / max;
   }
 
-  v = max;
+  const v = max;
 
   return {
     h: Math.round(h),
index 11bf0457efe1c656a0c4aaf72b92adda8f3bd77f..1a0de00ffa921432e66d63679ca3e9616787c267 100644 (file)
@@ -174,7 +174,7 @@ export function getUuid(): string {
  * Recursively serializes an object into an encoded URI parameter string.
  */
 export function serialize(obj: object, prefix?: string): string {
-  let parameters: string[] = [];
+  const parameters: string[] = [];
 
   for (const key in obj) {
     if (obj.hasOwnProperty(key)) {
index 6af47fae37bcbfefec77726bdb0b69553e7b89eb..36305ba2a9cefc0c97466db30492584c82e718d4 100644 (file)
@@ -306,7 +306,7 @@ const DomUtil = {
       if (attribute.name.indexOf(prefix) === 0) {
         let name = attribute.name.replace(new RegExp("^" + prefix), "");
         if (camelCaseName) {
-          let tmp = name.split("-");
+          const tmp = name.split("-");
           name = "";
           for (let j = 0, innerLength = tmp.length; j < innerLength; j++) {
             if (name.length) {
@@ -338,7 +338,7 @@ const DomUtil = {
       throw new Error("The element has no parent.");
     }
 
-    let parent = element.parentNode;
+    const parent = element.parentNode;
     while (element.childNodes.length) {
       parent.insertBefore(element.childNodes[0], element);
     }
index 99ba488e3ea16ec3c06b9b9eb8ddcb272a93def2..d296c696fe03f3b663d62c2bcc827f7bad9aa3f2 100644 (file)
@@ -60,7 +60,7 @@ class UiArticleSearch implements AjaxCallbackObject, DialogCallbackObject {
   }
 
   _ajaxSuccess(data: AjaxResponse): void {
-    let html = data.returnValues
+    const html = data.returnValues
       .map((article) => {
         return `<li>
           <div class="containerHeadline pointer" data-article-id="${article.articleID}">
@@ -73,7 +73,11 @@ class UiArticleSearch implements AjaxCallbackObject, DialogCallbackObject {
 
     this.resultList!.innerHTML = html;
 
-    DomUtil[html ? "show" : "hide"](this.resultList!);
+    if (html) {
+      DomUtil.show(this.resultList!);
+    } else {
+      DomUtil.hide(this.resultList!);
+    }
 
     if (html) {
       this.resultList!.querySelectorAll(".containerHeadline").forEach((item) => {
index 28887bdae2a72b5f29fed3c1c71532e0a730bc64..14987c699d7be12e8b82fd93ae54a22709bc73bd 100644 (file)
@@ -98,8 +98,8 @@ class UiSuggestion implements AjaxCallbackObject {
     }
 
     let active!: HTMLElement;
-    let i = 0,
-      length = this.dropdownMenu!.childElementCount;
+    let i = 0;
+    const length = this.dropdownMenu!.childElementCount;
     while (i < length) {
       active = this.dropdownMenu!.children[i] as HTMLElement;
       if (active.classList.contains("active")) {