Disallow var keyword

This commit is contained in:
Simon Ser 2024-09-28 22:07:39 +02:00
parent 312c755c11
commit 07ae5f7167
2 changed files with 9 additions and 8 deletions

View file

@ -20,6 +20,7 @@ export default [
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
}],
"no-var": "error",
},
},
];

View file

@ -12,13 +12,13 @@ export function encode(data) {
return btoa(data);
}
var encoder = new TextEncoder();
var bytes = encoder.encode(data);
let encoder = new TextEncoder();
let bytes = encoder.encode(data);
var trailing = bytes.length % 3;
var out = "";
for (var i = 0; i < bytes.length - trailing; i += 3) {
var u24 = (bytes[i] << 16) + (bytes[i + 1] << 8) + bytes[i + 2];
let trailing = bytes.length % 3;
let out = "";
for (let i = 0; i < bytes.length - trailing; i += 3) {
let u24 = (bytes[i] << 16) + (bytes[i + 1] << 8) + bytes[i + 2];
out += alphabet[(u24 >> 18) & 0x3F];
out += alphabet[(u24 >> 12) & 0x3F];
out += alphabet[(u24 >> 6) & 0x3F];
@ -26,12 +26,12 @@ export function encode(data) {
}
if (trailing == 1) {
var u8 = bytes[bytes.length - 1];
let u8 = bytes[bytes.length - 1];
out += alphabet[u8 >> 2];
out += alphabet[(u8 << 4) & 0x3F];
out += "==";
} else if (trailing == 2) {
var u16 = (bytes[bytes.length - 2] << 8) + bytes[bytes.length - 1];
let u16 = (bytes[bytes.length - 2] << 8) + bytes[bytes.length - 1];
out += alphabet[u16 >> 10];
out += alphabet[(u16 >> 4) & 0x3F];
out += alphabet[(u16 << 2) & 0x3F];