Skip to content

Commit e009bc5

Browse files
committed
(refactor): use const everywhere instead of let
- none of these variables are ever re-assigned - I wrote this a while ago when ES6 was new and just used `let` for everything instead of `var` at the time. Now I use `const` instead 😂... and `let` where needed
1 parent db32f93 commit e009bc5

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

index.es6

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
export default function trimCanvas (canvas) {
2-
let context = canvas.getContext('2d')
2+
const context = canvas.getContext('2d')
33

4-
let imgWidth = canvas.width
5-
let imgHeight = canvas.height
4+
const imgWidth = canvas.width
5+
const imgHeight = canvas.height
66

7-
let imgData = context.getImageData(0, 0, imgWidth, imgHeight).data
7+
const imgData = context.getImageData(0, 0, imgWidth, imgHeight).data
88

99
// get the corners of the relevant content (everything that's not white)
10-
let cropTop = scanY(true, imgWidth, imgHeight, imgData)
11-
let cropBottom = scanY(false, imgWidth, imgHeight, imgData)
12-
let cropLeft = scanX(true, imgWidth, imgHeight, imgData)
13-
let cropRight = scanX(false, imgWidth, imgHeight, imgData)
10+
const cropTop = scanY(true, imgWidth, imgHeight, imgData)
11+
const cropBottom = scanY(false, imgWidth, imgHeight, imgData)
12+
const cropLeft = scanX(true, imgWidth, imgHeight, imgData)
13+
const cropRight = scanX(false, imgWidth, imgHeight, imgData)
1414

1515
// + 1 is needed because this is a difference, there are n + 1 pixels in
1616
// between the two numbers inclusive
17-
let cropXDiff = (cropRight - cropLeft) + 1
18-
let cropYDiff = (cropBottom - cropTop) + 1
17+
const cropXDiff = (cropRight - cropLeft) + 1
18+
const cropYDiff = (cropBottom - cropTop) + 1
1919

2020
// get the relevant data from the calculated coordinates
21-
let trimmedData = context.getImageData(cropLeft, cropTop, cropXDiff,
21+
const trimmedData = context.getImageData(cropLeft, cropTop, cropXDiff,
2222
cropYDiff)
2323

2424
// set the trimmed width and height
@@ -48,8 +48,8 @@ function getAlpha (x, y, imgWidth, imgData) {
4848

4949
// finds the first y coord in imgData that is not white
5050
function scanY (fromTop, imgWidth, imgHeight, imgData) {
51-
let offset = fromTop ? 1 : -1
52-
let firstCol = fromTop ? 0 : imgHeight - 1
51+
const offset = fromTop ? 1 : -1
52+
const firstCol = fromTop ? 0 : imgHeight - 1
5353

5454
// loop through each row
5555
for (var y = firstCol; fromTop ? (y < imgHeight) : (y > -1); y += offset) {
@@ -68,8 +68,8 @@ function scanY (fromTop, imgWidth, imgHeight, imgData) {
6868

6969
// finds the first x coord in imgData that is not white
7070
function scanX (fromLeft, imgWidth, imgHeight, imgData) {
71-
let offset = fromLeft ? 1 : -1
72-
let firstRow = fromLeft ? 0 : imgWidth - 1
71+
const offset = fromLeft ? 1 : -1
72+
const firstRow = fromLeft ? 0 : imgWidth - 1
7373

7474
// loop through each column
7575
for (var x = firstRow; fromLeft ? (x < imgWidth) : (x > -1); x += offset) {

0 commit comments

Comments
 (0)