Use const variables when applicable

This commit is contained in:
2019-11-17 18:25:14 +09:00
parent 454e8572e3
commit 878f1913e3
39 changed files with 405 additions and 403 deletions

View File

@ -1,5 +1,5 @@
export function* findAll(className: string): IterableIterator<HTMLElement> {
let elements = document.getElementsByClassName(className)
const elements = document.getElementsByClassName(className)
for(let i = 0; i < elements.length; ++i) {
yield elements[i] as HTMLElement
@ -7,7 +7,7 @@ export function* findAll(className: string): IterableIterator<HTMLElement> {
}
export function* findAllInside(className: string, root: HTMLElement): IterableIterator<HTMLElement> {
let elements = root.getElementsByClassName(className)
const elements = root.getElementsByClassName(className)
for(let i = 0; i < elements.length; ++i) {
yield elements[i] as HTMLElement

View File

@ -1,5 +1,5 @@
export function hexToHSL(hex: string) {
let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
if(!result) {
return null
@ -13,17 +13,17 @@ export function hexToHSL(hex: string) {
g /= 255
b /= 255
let max = Math.max(r, g, b)
let min = Math.min(r, g, b)
const max = Math.max(r, g, b)
const min = Math.min(r, g, b)
let h = 0
let s = 0
let l = (max + min) / 2
const l = (max + min) / 2
if(max == min) {
h = s = 0
} else {
let d = max - min
const d = max - min
s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
switch(max) {

View File

@ -1,7 +1,7 @@
// swapElements assumes that both elements have valid parent nodes.
export function swapElements(a: Node, b: Node) {
let bParent = b.parentNode as Node
let bNext = b.nextSibling
const bParent = b.parentNode as Node
const bNext = b.nextSibling
// Special case for when a is the next sibling of b
if(bNext === a) {

View File

@ -1,6 +1,6 @@
export function uploadWithProgress(url, options: RequestInit, onProgress: ((ev: ProgressEvent) => any) | null): Promise<string> {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest()
const xhr = new XMLHttpRequest()
xhr.onload = () => {
if(xhr.status >= 400) {
@ -21,7 +21,7 @@ export function uploadWithProgress(url, options: RequestInit, onProgress: ((ev:
xhr.open(options.method || "GET", url, true)
if(options.headers) {
for(let key in options.headers) {
for(const key in options.headers) {
xhr.setRequestHeader(key, options.headers[key])
}
}