From 9a7e688f48cddb097e3d89fd257d19fae69943dc Mon Sep 17 00:00:00 2001 From: "Thibaut(Teebo)" Date: Wed, 9 Oct 2024 14:57:46 +0000 Subject: [PATCH] refactor for const over let --- src/filters/HSV.ts | 7 +++---- src/filters/Noise.ts | 7 +++---- src/filters/RGBA.ts | 10 ++++------ src/filters/Solarize.ts | 7 ++++--- src/filters/Threshold.ts | 7 +++---- src/shapes/Line.ts | 17 +++++++---------- src/shapes/Text.ts | 1 - 7 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/filters/HSV.ts b/src/filters/HSV.ts index b111b277f..855f66445 100644 --- a/src/filters/HSV.ts +++ b/src/filters/HSV.ts @@ -15,12 +15,11 @@ import { getNumberValidator } from '../Validators'; */ export const HSV: Filter = function (imageData) { - let data = imageData.data, + const data = imageData.data, nPixels = data.length, v = Math.pow(2, this.value()), s = Math.pow(2, this.saturation()), - h = Math.abs(this.hue() + 360) % 360, - i; + h = Math.abs(this.hue() + 360) % 360; // Basis for the technique used: // http://beesbuzz.biz/code/hsv_color_transforms.php @@ -49,7 +48,7 @@ export const HSV: Filter = function (imageData) { let r, g, b, a; - for (i = 0; i < nPixels; i += 4) { + for (let i = 0; i < nPixels; i += 4) { r = data[i + 0]; g = data[i + 1]; b = data[i + 2]; diff --git a/src/filters/Noise.ts b/src/filters/Noise.ts index 6c80d4e7c..39fd3ea12 100644 --- a/src/filters/Noise.ts +++ b/src/filters/Noise.ts @@ -15,13 +15,12 @@ import { getNumberValidator } from '../Validators'; * node.noise(0.8); */ export const Noise: Filter = function (imageData) { - let amount = this.noise() * 255, + const amount = this.noise() * 255, data = imageData.data, nPixels = data.length, - half = amount / 2, - i; + half = amount / 2; - for (i = 0; i < nPixels; i += 4) { + for (let i = 0; i < nPixels; i += 4) { data[i + 0] += half - 2 * half * Math.random(); data[i + 1] += half - 2 * half * Math.random(); data[i + 2] += half - 2 * half * Math.random(); diff --git a/src/filters/RGBA.ts b/src/filters/RGBA.ts index 86e2ff24d..dcd140c07 100644 --- a/src/filters/RGBA.ts +++ b/src/filters/RGBA.ts @@ -18,17 +18,15 @@ import { RGBComponent } from '../Validators'; */ export const RGBA: Filter = function (imageData) { - let data = imageData.data, + const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), - alpha = this.alpha(), - i, - ia; + alpha = this.alpha(); - for (i = 0; i < nPixels; i += 4) { - ia = 1 - alpha; + for (let i = 0; i < nPixels; i += 4) { + const ia = 1 - alpha; data[i] = red * alpha + data[i] * ia; // r data[i + 1] = green * alpha + data[i + 1] * ia; // g diff --git a/src/filters/Solarize.ts b/src/filters/Solarize.ts index 266ff1ba2..c576b6f71 100644 --- a/src/filters/Solarize.ts +++ b/src/filters/Solarize.ts @@ -14,11 +14,12 @@ import { Filter } from '../Node'; */ export const Solarize: Filter = function (imageData) { - let data = imageData.data, + const data = imageData.data, w = imageData.width, h = imageData.height, - w4 = w * 4, - y = h; + w4 = w * 4; + + let y = h; do { const offsetY = (y - 1) * w4; diff --git a/src/filters/Threshold.ts b/src/filters/Threshold.ts index 5f95b03cc..1cdb8bb02 100644 --- a/src/filters/Threshold.ts +++ b/src/filters/Threshold.ts @@ -17,12 +17,11 @@ import { getNumberValidator } from '../Validators'; */ export const Threshold: Filter = function (imageData) { - let level = this.threshold() * 255, + const level = this.threshold() * 255, data = imageData.data, - len = data.length, - i; + len = data.length; - for (i = 0; i < len; i += 1) { + for (let i = 0; i < len; i += 1) { data[i] = data[i] < level ? 0 : 255; } }; diff --git a/src/shapes/Line.ts b/src/shapes/Line.ts index 551a6d1a9..664fc3d50 100644 --- a/src/shapes/Line.ts +++ b/src/shapes/Line.ts @@ -1,11 +1,10 @@ -import { Util } from '../Util'; import { Factory } from '../Factory'; -import { Shape, ShapeConfig } from '../Shape'; -import { getNumberValidator, getNumberArrayValidator } from '../Validators'; import { _registerNode } from '../Global'; +import { Shape, ShapeConfig } from '../Shape'; +import { getNumberArrayValidator, getNumberValidator } from '../Validators'; -import { GetSet } from '../types'; import { Context } from '../Context'; +import { GetSet } from '../types'; function getControlPoints(x0, y0, x1, y1, x2, y2, t) { const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), @@ -21,13 +20,11 @@ function getControlPoints(x0, y0, x1, y1, x2, y2, t) { } function expandPoints(p, tension) { - let len = p.length, - allPoints: Array = [], - n, - cp; + const len = p.length, + allPoints: Array = []; - for (n = 2; n < len - 2; n += 2) { - cp = getControlPoints( + for (let n = 2; n < len - 2; n += 2) { + const cp = getControlPoints( p[n - 2], p[n - 1], p[n], diff --git a/src/shapes/Text.ts b/src/shapes/Text.ts index 9069c405f..b6430dd84 100644 --- a/src/shapes/Text.ts +++ b/src/shapes/Text.ts @@ -69,7 +69,6 @@ const AUTO = 'auto', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', - LTR = 'ltr', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top',