diff --git a/src/ace/commands.js b/src/ace/commands.js
index 516253d19..aa197769e 100644
--- a/src/ace/commands.js
+++ b/src/ace/commands.js
@@ -200,9 +200,9 @@ const commands = [
name: "cut",
description: "Cut",
exec(editor) {
- let cutLine =
+ const cutLine =
editor.$copyWithEmptySelection && editor.selection.isEmpty();
- let range = cutLine
+ const range = cutLine
? editor.selection.getLineRange()
: editor.selection.getRange();
editor._emit("cut", range);
@@ -285,9 +285,9 @@ const commands = [
name: "increaseFontSize",
description: "Increase font size",
exec(editor) {
- let size = Number.parseInt(editor.getFontSize(), 10) || 12;
+ const size = Number.parseInt(editor.getFontSize(), 10) || 12;
editor.setFontSize(size + 1);
- settings.value.fontSize = size + 1 + "px";
+ settings.value.fontSize = `${size + 1}px`;
settings.update(false);
},
},
@@ -295,9 +295,9 @@ const commands = [
name: "decreaseFontSize",
description: "Decrease font size",
exec(editor) {
- let size = Number.parseInt(editor.getFontSize(), 10) || 12;
+ const size = Number.parseInt(editor.getFontSize(), 10) || 12;
editor.setFontSize(Math.max(size - 1 || 1));
- settings.value.fontSize = Math.max(size - 1 || 1) + "px";
+ settings.value.fontSize = `${Math.max(size - 1 || 1)}px`;
settings.update(false);
},
},
@@ -344,9 +344,9 @@ const commands = [
];
export function setCommands(editor) {
- commands.forEach((command) => {
+ for (const command of commands) {
editor.commands.addCommand(command);
- });
+ }
}
/**
@@ -368,7 +368,7 @@ export async function setKeyBindings({ commands }) {
await resetKeyBindings();
}
- Object.keys(commands.byName).forEach((name) => {
+ for (const name of Object.keys(commands.byName)) {
const shortcut = keyboardShortcuts[name];
const command = commands.byName[name];
@@ -379,7 +379,7 @@ export async function setKeyBindings({ commands }) {
// not chekiang if shortcut is empty because it can be used to remove shortcut
command.bindKey = { win: shortcut?.key ?? null };
commands.addCommand(command);
- });
+ }
}
/**
diff --git a/src/ace/modelist.js b/src/ace/modelist.js
index c6f70d8ca..6b1e95218 100644
--- a/src/ace/modelist.js
+++ b/src/ace/modelist.js
@@ -5,11 +5,11 @@ export function initModes() {
ace.define(
"ace/ext/modelist",
["require", "exports", "module"],
- function (require, exports, module) {
+ (require, exports, module) => {
module.exports = {
getModeForPath(path) {
let mode = modesByName.text;
- let fileName = path.split(/[\/\\]/).pop();
+ const fileName = path.split(/[\/\\]/).pop();
for (const iMode of modes) {
if (iMode.supportsFile?.(fileName)) {
mode = iMode;
@@ -81,9 +81,8 @@ class Mode {
if (/\^/.test(extensions)) {
re =
- extensions.replace(/\|(\^)?/g, function (a, b) {
- return "$|" + (b ? "^" : "^.*\\.");
- }) + "$";
+ extensions.replace(/\|(\^)?/g, (a, b) => "$|" + (b ? "^" : "^.*\\.")) +
+ "$";
} else {
re = "^.*\\.(" + extensions + ")$";
}
diff --git a/src/ace/supportedModes.js b/src/ace/supportedModes.js
index 4bfd11bc6..5557dee4c 100644
--- a/src/ace/supportedModes.js
+++ b/src/ace/supportedModes.js
@@ -211,9 +211,9 @@ const languageNames = {
AutoHotKey: "AutoHotkey/AutoIt",
};
-Object.keys(modeList).forEach((key) => {
+for (const key of Object.keys(modeList)) {
const extensions = modeList[key];
const caption = languageNames[key];
addMode(key, extensions, caption);
-});
+}
diff --git a/src/ace/touchHandler.js b/src/ace/touchHandler.js
index 6c9eed374..9f5bc47b8 100644
--- a/src/ace/touchHandler.js
+++ b/src/ace/touchHandler.js
@@ -548,9 +548,9 @@ export default function addTouchListeners(editor, minimal, onclick) {
* @param {number} y
*/
function scroll(x, y) {
- let direction = reverseScrolling ? 1 : -1;
- let scrollX = direction * x;
- let scrollY = direction * y;
+ const direction = reverseScrolling ? 1 : -1;
+ const scrollX = direction * x;
+ const scrollY = direction * y;
renderer.scrollBy(scrollX, scrollY);
}
diff --git a/src/components/WebComponents/wcPage.js b/src/components/WebComponents/wcPage.js
index 5a73a6618..6fee35762 100644
--- a/src/components/WebComponents/wcPage.js
+++ b/src/components/WebComponents/wcPage.js
@@ -34,7 +34,7 @@ export default class WCPage extends HTMLElement {
this.onwilldisconnect();
}
- this.#on.willdisconnect.forEach((cb) => cb.call(this));
+ for (const cb of this.#on.willdisconnect) cb.call(this);
};
this.handler.onRestore = () => {
@@ -42,7 +42,7 @@ export default class WCPage extends HTMLElement {
this.onwillconnect();
}
- this.#on.willconnect.forEach((cb) => cb.call(this));
+ for (const cb of this.#on.willconnect) cb.call(this);
};
this.#leadBtn = (
@@ -50,7 +50,7 @@ export default class WCPage extends HTMLElement {
className="icon arrow_back"
onclick={() => this.hide.call(this)}
attr-action="go-back"
- >
+ />
);
this.#header = tile({
@@ -61,7 +61,7 @@ export default class WCPage extends HTMLElement {
}
appendBody(...$els) {
- let $main = this.body;
+ const $main = this.body;
if (!$main) return;
for (const $el of $els) {
$main.append($el);
@@ -81,12 +81,12 @@ export default class WCPage extends HTMLElement {
connectedCallback() {
this.classList.remove("hide");
if (typeof this.onconnect === "function") this.onconnect();
- this.#on.show.forEach((cb) => cb.call(this));
+ for (const cb of this.#on.show) cb.call(this);
}
disconnectedCallback() {
if (typeof this.ondisconnect === "function") this.ondisconnect();
- this.#on.hide.forEach((cb) => cb.call(this));
+ for (const cb of this.#on.hide) cb.call(this);
}
/**
@@ -187,7 +187,7 @@ export default class WCPage extends HTMLElement {
#addHeaderOrAssignHeader() {
if (!this.classList.contains("primary")) {
this.#append(this.#header);
- this.#append(
);
+ this.#append();
} else {
this.#header = this.get("header");
if (this.#header) {
@@ -213,7 +213,7 @@ class PageHandler {
this.onhide = this.onhide.bind(this);
this.onshow = this.onshow.bind(this);
- this.$replacement = ;
+ this.$replacement = ;
this.$replacement.handler = this;
this.$el.on("hide", this.onhide);
@@ -262,7 +262,7 @@ class PageHandler {
*/
function handlePagesForSmoothExperience() {
const $pages = [...tag.getAll("wc-page")];
- for (let $page of $pages.slice(0, -1)) {
+ for (const $page of $pages.slice(0, -1)) {
$page.handler.replaceEl();
}
}
diff --git a/src/components/audioPlayer/index.js b/src/components/audioPlayer/index.js
index ebc8c73f8..426ad2432 100644
--- a/src/components/audioPlayer/index.js
+++ b/src/components/audioPlayer/index.js
@@ -25,19 +25,17 @@ export default class AudioPlayer {
const audioPlayer = (
@@ -46,10 +44,11 @@ export default class AudioPlayer {
+ />
);
diff --git a/src/components/checkbox/index.js b/src/components/checkbox/index.js
index c473b0ea0..116490878 100644
--- a/src/components/checkbox/index.js
+++ b/src/components/checkbox/index.js
@@ -40,7 +40,7 @@ function Checkbox(text, checked, name, id, type, ref, size) {
name={name}
id={id}
/>
-
+
{text}
);
diff --git a/src/components/contextmenu/index.js b/src/components/contextmenu/index.js
index 025977f2f..6115277d5 100644
--- a/src/components/contextmenu/index.js
+++ b/src/components/contextmenu/index.js
@@ -67,9 +67,9 @@ export default function Contextmenu(content, options) {
});
if (Array.isArray(options.items)) {
- options.items.forEach(([text, action]) => {
+ for (const [text, action] of options.items) {
$el.append(
{text});
- });
+ }
}
if (!options.innerHTML) addTabindex();
@@ -90,17 +90,17 @@ export default function Contextmenu(content, options) {
if (options.toggler) {
const client = options.toggler.getBoundingClientRect();
if (!options.top && !options.bottom) {
- $el.style.top = client.top + "px";
+ $el.style.top = `${client.top}px`;
}
if (!options.left && !options.right) {
- $el.style.right = innerWidth - client.right + "px";
+ $el.style.right = `${innerWidth - client.right}px`;
}
}
app.append($el, $mask);
const $firstChild = $el.firstChild;
- if ($firstChild && $firstChild.focus) $firstChild.focus();
+ if ($firstChild?.focus) $firstChild.focus();
}
function hide() {
@@ -121,7 +121,7 @@ export default function Contextmenu(content, options) {
function addTabindex() {
/**@type {Array
} */
const children = [...$el.children];
- for (let $el of children) $el.tabIndex = "0";
+ for (const $el of children) $el.tabIndex = "0";
}
function destroy() {
diff --git a/src/components/inputhints/index.js b/src/components/inputhints/index.js
index a340730a9..3e58c5a73 100644
--- a/src/components/inputhints/index.js
+++ b/src/components/inputhints/index.js
@@ -140,12 +140,12 @@ export default function inputhints($input, hints, onSelect) {
const { value: toTest } = this;
const matched = [];
const regexp = new RegExp(toTest, "i");
- hints.forEach((hint) => {
+ for (const hint of hints) {
const { value, text } = hint;
if (regexp.test(value) || regexp.test(text)) {
matched.push(hint);
}
- });
+ }
updateUl(matched);
}
@@ -360,7 +360,7 @@ function Hint({ hint }) {
text = hint.text;
}
- return ;
+ return ;
}
/**
diff --git a/src/components/page.js b/src/components/page.js
index 9b3b13857..252486e94 100644
--- a/src/components/page.js
+++ b/src/components/page.js
@@ -9,7 +9,7 @@ import WCPage from "./WebComponents/wcPage";
* @returns {WCPage}
*/
function Page(title, options = {}) {
- let page = ;
+ const page = ;
page.append = page.appendBody;
page.initializeIfNotAlreadyInitialized();
page.settitle(title);
diff --git a/src/components/quickTools/footer.js b/src/components/quickTools/footer.js
index d94d2411f..7a9c275dd 100644
--- a/src/components/quickTools/footer.js
+++ b/src/components/quickTools/footer.js
@@ -65,14 +65,11 @@ export const SearchRow2 = ({ inputRef, posRef, totalRef }) => (
);
/**@type {HTMLElement} */
-export const $footer = ;
+export const $footer = ;
/**@type {HTMLElement} */
export const $toggler = (
-
+
);
/**@type {HTMLTextAreaElement} */
@@ -89,7 +86,7 @@ export const $input = (
top: 0,
left: 0,
}}
- >
+ />
);
/**
@@ -107,13 +104,14 @@ export const $input = (
export function RowItem({ id, icon, letters, action, value, ref, repeat }) {
const $item = (
+ />
);
if (typeof value === "function") {
@@ -132,16 +130,16 @@ export function RowItem({ id, icon, letters, action, value, ref, repeat }) {
* @returns {Array}
*/
function Extras({ extras }) {
- const div = ;
+ const div = ;
if (Array.isArray(extras)) {
- extras.forEach((i) => {
+ for (const i of extras) {
if (i instanceof HTMLElement) {
div.appendChild(i);
return;
}
div.append();
- });
+ }
}
return div;
}
diff --git a/src/components/scrollbar/index.js b/src/components/scrollbar/index.js
index 4f8ca598c..b94de0852 100644
--- a/src/components/scrollbar/index.js
+++ b/src/components/scrollbar/index.js
@@ -57,7 +57,7 @@ export default function ScrollBar(options) {
const isVertical = placement === "right" || placement === "left";
const observer = new MutationObserver(observerCallback);
let scroll = 0;
- let touchStartValue = {
+ const touchStartValue = {
x: 0,
y: 0,
};
@@ -89,8 +89,8 @@ export default function ScrollBar(options) {
}
function setWidth(width) {
- if (isVertical) $scrollbar.style.width = $cursor.style.width = width + "px";
- else $scrollbar.style.height = $cursor.style.height = width + "px";
+ if (isVertical) $scrollbar.style.width = $cursor.style.width = `${width}px`;
+ else $scrollbar.style.height = $cursor.style.height = `${width}px`;
}
/**
@@ -132,7 +132,7 @@ export default function ScrollBar(options) {
else if (top > height) top = height;
if (currentTopValue !== top) {
- $cursor.style.top = top + "px";
+ $cursor.style.top = `${top}px`;
scroll = top / height;
if (typeof $scrollbar.onScroll === "function")
$scrollbar.onScroll(scroll);
@@ -145,7 +145,7 @@ export default function ScrollBar(options) {
else if (left > width) left = width;
if (currentLeftValue !== left) {
- $cursor.style.left = left + "px";
+ $cursor.style.left = `${left}px`;
scroll = left / width;
if (typeof $scrollbar.onScroll === "function")
$scrollbar.onScroll(scroll);
@@ -180,16 +180,15 @@ export default function ScrollBar(options) {
if (render && height && width) setValue(scroll);
}
- function setValue(val) {
+ function setValue(value) {
if (!height || !width) resize(false);
//Make sure value is between 0 and 1
- if (val < 0) val = 0;
- else if (val > 1) val = 1;
+ const boundedValue = Math.max(0, Math.min(1, value));
- scroll = val;
- if (isVertical) $cursor.style.top = val * height + "px";
- else $cursor.style.left = val * width + "px";
+ scroll = boundedValue;
+ if (isVertical) $cursor.style.top = `${boundedValue * height}px`;
+ else $cursor.style.left = `${boundedValue * width}px`;
}
function destroy() {
diff --git a/src/components/searchbar/index.js b/src/components/searchbar/index.js
index 592ae8e08..12168fe46 100644
--- a/src/components/searchbar/index.js
+++ b/src/components/searchbar/index.js
@@ -22,7 +22,7 @@ function searchBar($list, setHide, onhideCb, searchFunction) {
placeholder={strings.search}
enterKeyHint="go"
/>
-
+
);
diff --git a/src/components/sideButton/index.js b/src/components/sideButton/index.js
index 831cb2fb6..10931b3bd 100644
--- a/src/components/sideButton/index.js
+++ b/src/components/sideButton/index.js
@@ -1,7 +1,7 @@
import "./style.scss";
/**@type {HTMLDivElement} */
-export const sideButtonContainer = ;
+export const sideButtonContainer = ;
export default function SideButtons({
text,
@@ -12,11 +12,12 @@ export default function SideButtons({
}) {
const $button = (
);
diff --git a/src/components/sidebar/index.js b/src/components/sidebar/index.js
index a012db4d5..868960039 100644
--- a/src/components/sidebar/index.js
+++ b/src/components/sidebar/index.js
@@ -5,7 +5,7 @@ import constants from "lib/constants";
let $sidebar;
/**@type {Array<(el:HTMLElement)=>boolean>} */
-let preventSlideTests = [];
+const preventSlideTests = [];
const events = {
show: [],
@@ -247,7 +247,7 @@ function create($container, $toggler) {
touch.totalX = touch.endX - touch.startX;
touch.totalY = touch.endY - touch.startY;
- let width = $el.getWidth();
+ const width = $el.getWidth();
if (
!$el.activated &&
@@ -347,7 +347,7 @@ function create($container, $toggler) {
$el.hide = hide;
$el.toggle = toggle;
$el.onshow = () => {};
- $el.getWidth = function () {
+ $el.getWidth = () => {
const width = innerWidth * 0.7;
return mode === "phone" ? (width >= 350 ? 350 : width) : MIN_WIDTH;
};
diff --git a/src/dialogs/alert.js b/src/dialogs/alert.js
index 4c2d2a7a2..d7b497630 100644
--- a/src/dialogs/alert.js
+++ b/src/dialogs/alert.js
@@ -16,9 +16,7 @@ function alert(titleText, message, onhide) {
const regex = /(https?:\/\/[^\s]+)/g;
if (regex.test(message)) {
- message = message.replace(regex, function (url) {
- return `${url}`;
- });
+ message = message.replace(regex, (url) => `${url}`);
}
const titleSpan = tag("strong", {
diff --git a/src/dialogs/box.js b/src/dialogs/box.js
index 96ae860fa..71fab4537 100644
--- a/src/dialogs/box.js
+++ b/src/dialogs/box.js
@@ -31,7 +31,8 @@ function box(titleText, html, hideButtonText, cancelButtonText) {
};
let cancelBtn;
- let hideButton = typeof hideButtonText === "boolean" ? hideButtonText : false;
+ const hideButton =
+ typeof hideButtonText === "boolean" ? hideButtonText : false;
if (cancelButtonText) {
cancelBtn = tag("button", {
@@ -117,7 +118,7 @@ function box(titleText, html, hideButtonText, cancelButtonText) {
if (waitFor) return;
const imgs = box.getAll("img");
if (imgs) {
- for (let img of imgs) {
+ for (const img of imgs) {
URL.revokeObjectURL(img.src);
}
}
diff --git a/src/dialogs/color.js b/src/dialogs/color.js
index 8369d4cc0..a908978b0 100644
--- a/src/dialogs/color.js
+++ b/src/dialogs/color.js
@@ -23,7 +23,7 @@ function color(defaultColor, onhide) {
});
const okBtn = tag("button", {
textContent: strings.ok,
- onclick: function () {
+ onclick: () => {
hide();
lastPicked = color;
localStorage.__picker_last_picked = color;
diff --git a/src/dialogs/confirm.js b/src/dialogs/confirm.js
index 6c70aeba4..a376f34a7 100644
--- a/src/dialogs/confirm.js
+++ b/src/dialogs/confirm.js
@@ -27,14 +27,14 @@ function confirm(titleText, message, isHTML) {
});
const okBtn = tag("button", {
textContent: strings.ok,
- onclick: function () {
+ onclick: () => {
hide();
resolve(true);
},
});
const cancelBtn = tag("button", {
textContent: strings.cancel,
- onclick: function () {
+ onclick: () => {
hide();
resolve(false);
},
diff --git a/src/dialogs/multiPrompt.js b/src/dialogs/multiPrompt.js
index 0a8324748..ffedc2d7c 100644
--- a/src/dialogs/multiPrompt.js
+++ b/src/dialogs/multiPrompt.js
@@ -51,12 +51,12 @@ export default function multiPrompt(message, inputs, help) {
const okBtn = tag("button", {
type: "submit",
textContent: strings.ok,
- onclick: function (e) {
+ onclick: (e) => {
e.preventDefault();
e.stopPropagation();
const inputAr = [...$body.getAll("input")];
- for (let $input of inputAr) {
+ for (const $input of inputAr) {
if ($input.isRequired && !$input.value) {
$errorMessage.textContent = strings.required.capitalize();
const $sibling = $input.nextElementSibling;
@@ -73,7 +73,7 @@ export default function multiPrompt(message, inputs, help) {
const cancelBtn = tag("button", {
textContent: strings.cancel,
type: "button",
- onclick: function () {
+ onclick: () => {
reject();
hide();
},
@@ -215,7 +215,7 @@ export default function multiPrompt(message, inputs, help) {
} = input;
const inputType = type === "textarea" ? "textarea" : "input";
- let _type = type === "filename" ? "text" : type || "text";
+ const _type = type === "filename" ? "text" : type || "text";
let $input;
diff --git a/src/dialogs/prompt.js b/src/dialogs/prompt.js
index 19a96e5cc..f339c95cc 100644
--- a/src/dialogs/prompt.js
+++ b/src/dialogs/prompt.js
@@ -42,7 +42,7 @@ export default function prompt(
type: "submit",
textContent: strings.ok,
disabled: !defaultValue,
- onclick: function () {
+ onclick: () => {
if (options.required && !input.value) {
errorMessage.textContent = strings.required;
return;
@@ -56,7 +56,7 @@ export default function prompt(
const cancelBtn = tag("button", {
textContent: strings.cancel,
type: "button",
- onclick: function () {
+ onclick: () => {
hide();
resolve(null);
},
@@ -97,7 +97,7 @@ export default function prompt(
}
}
- input.oninput = function () {
+ input.oninput = () => {
const { match, test } = options;
let isValid = true;
diff --git a/src/dialogs/select.js b/src/dialogs/select.js
index 35ce1ae6e..542ce017e 100644
--- a/src/dialogs/select.js
+++ b/src/dialogs/select.js
@@ -81,7 +81,7 @@ function select(title, options, opts = {}) {
$item.tabIndex = "0";
- $item.onclick = function () {
+ $item.onclick = () => {
if (value === undefined) return;
if (opts.hideOnSelect) hide();
resolve(value);
@@ -124,7 +124,7 @@ function select(title, options, opts = {}) {
if (typeof opts.onHide === "function") opts.onHide();
actionStack.remove("select");
hideSelect();
- let listItems = [...$list.children];
+ const listItems = [...$list.children];
listItems.map((item) => (item.onclick = null));
}
});
diff --git a/src/fileSystem/externalFs.js b/src/fileSystem/externalFs.js
index 8f6b22f2f..ee58aaa9a 100644
--- a/src/fileSystem/externalFs.js
+++ b/src/fileSystem/externalFs.js
@@ -12,7 +12,7 @@ const externalFs = {
},
async writeFile(filename, data) {
- return new Promise(async (resolve, reject) => {
+ return new Promise((resolve, reject) => {
sdcard.write(filename, data, resolve, reject);
});
},
diff --git a/src/fileSystem/ftp.js b/src/fileSystem/ftp.js
index 7002e89eb..d4fec76b6 100644
--- a/src/fileSystem/ftp.js
+++ b/src/fileSystem/ftp.js
@@ -315,7 +315,7 @@ class FtpClient {
get #cacheFile() {
return Url.join(
CACHE_STORAGE,
- "ftp" + Url.join(this.#origin, this.#path).hashCode(),
+ `ftp${Url.join(this.#origin, this.#path).hashCode()}`,
);
}
diff --git a/src/fileSystem/internalFs.js b/src/fileSystem/internalFs.js
index c53654cf7..ab026f2ae 100644
--- a/src/fileSystem/internalFs.js
+++ b/src/fileSystem/internalFs.js
@@ -334,7 +334,7 @@ const internalFs = {
};
function setMessage(reject) {
- return function (err) {
+ return (err) => {
if (err.code) {
const message = getErrorMessage(err.code);
err.message = message;
diff --git a/src/fileSystem/sftp.js b/src/fileSystem/sftp.js
index 8c582113e..c7eceefad 100644
--- a/src/fileSystem/sftp.js
+++ b/src/fileSystem/sftp.js
@@ -32,7 +32,7 @@ class SftpClient {
this.#hostname = hostname;
this.#port = port;
this.#username = username;
- this.#authenticationType = !!authentication.keyFile ? "key" : "password";
+ this.#authenticationType = authentication.keyFile ? "key" : "password";
this.#keyFile = authentication.keyFile;
this.#passPhrase = authentication.passPhrase;
this.#password = authentication.password;
@@ -78,13 +78,13 @@ class SftpClient {
sftp.lsDir(
path,
(res) => {
- res.forEach((file) => {
+ for (const file of res) {
file.url = Url.join(this.#base, file.url);
file.type = mimeType.lookup(filename);
if (file.isLink) {
file.linkTarget = Url.join(this.#base, file.linkTarget);
}
- });
+ }
resolve(res);
},
(err) => {
@@ -357,8 +357,8 @@ class SftpClient {
await this.#setStat();
sftp.rm(
this.#safeName(filename),
- this.#stat.isDirectory ? true : false,
- this.#stat.isDirectory ? true : false,
+ this.#stat.isDirectory,
+ this.#stat.isDirectory,
(_res) => {
resolve(fullFilename);
},
@@ -565,7 +565,7 @@ class SftpClient {
#getLocalname(filename) {
return Url.join(
CACHE_STORAGE,
- "sftp" + Url.join(this.#base, filename).hashCode(),
+ `sftp${Url.join(this.#base, filename).hashCode()}`,
);
}
diff --git a/src/handlers/editorFileTab.js b/src/handlers/editorFileTab.js
index 9c64df7cd..f7a59fa32 100644
--- a/src/handlers/editorFileTab.js
+++ b/src/handlers/editorFileTab.js
@@ -271,8 +271,8 @@ function getClientPos(e) {
function updateFileList($parent) {
const children = [...$parent.children];
const newFileList = [];
- for (let el of children) {
- for (let file of editorManager.files) {
+ for (const el of children) {
+ for (const file of editorManager.files) {
if (file.tab === el) {
newFileList.push(file);
break;
diff --git a/src/handlers/keyboard.js b/src/handlers/keyboard.js
index 83ab2c24b..483387b86 100644
--- a/src/handlers/keyboard.js
+++ b/src/handlers/keyboard.js
@@ -154,7 +154,9 @@ keyboardHandler.off = (eventName, callback) => {
*/
function emit(eventName) {
if (!event[eventName]) return;
- event[eventName].forEach((cb) => cb());
+ for (const cb of event[eventName]) {
+ cb();
+ }
}
/**
diff --git a/src/handlers/purchase.js b/src/handlers/purchase.js
index 394ab9eb6..1b1c7fd86 100644
--- a/src/handlers/purchase.js
+++ b/src/handlers/purchase.js
@@ -35,7 +35,7 @@ export default function purchaseListener(onpurchase, onerror) {
return;
}
- let message =
+ const message =
error === iap.USER_CANCELED ? strings.failed : strings.canceled;
if (typeof onerror === "function") onerror(message);
diff --git a/src/handlers/quickTools.js b/src/handlers/quickTools.js
index 5285090be..f90658bf3 100644
--- a/src/handlers/quickTools.js
+++ b/src/handlers/quickTools.js
@@ -120,7 +120,7 @@ export default function actions(action, value) {
setInput();
value = !state[action];
state[action] = value;
- events[action].forEach((cb) => cb(value));
+ for (const cb of events[action]) cb(value);
if (Object.values(state).includes(true)) {
$input.focus();
} else if (input) {
@@ -345,15 +345,17 @@ function updateSearchState() {
const { editor } = editorManager;
const { $searchPos, $searchTotal } = quickTools;
- let regex = editor.$search.$options.re;
+ const regex = editor.$search.$options.re;
let all = 0;
let before = 0;
if (regex) {
const value = editor.getValue();
const offset = editor.session.doc.positionToIndex(editor.selection.anchor);
- let last = (regex.lastIndex = 0);
+ regex.lastIndex = 0;
+ let last = 0;
let m;
- while ((m = regex.exec(value))) {
+ m = regex.exec(value);
+ while (m) {
all++;
last = m.index;
if (last <= offset) before++;
@@ -362,6 +364,7 @@ function updateSearchState() {
regex.lastIndex = last += 1;
if (last >= value.length) break;
}
+ m = regex.exec(value);
}
}
$searchTotal.textContent = all > MAX_COUNT ? "999+" : all;
@@ -402,13 +405,13 @@ function focusEditor() {
function resetKeys() {
state.shift = false;
- events.shift.forEach((cb) => cb(false));
+ for (const cb of events.shift) cb(false);
state.alt = false;
- events.alt.forEach((cb) => cb(false));
+ for (const cb of events.alt) cb(false);
state.ctrl = false;
- events.ctrl.forEach((cb) => cb(false));
+ for (const cb of events.ctrl) cb(false);
state.meta = false;
- events.meta.forEach((cb) => cb(false));
+ for (const cb of events.meta) cb(false);
input.focus();
}
diff --git a/src/handlers/windowResize.js b/src/handlers/windowResize.js
index 04b7f9701..a418e3b96 100644
--- a/src/handlers/windowResize.js
+++ b/src/handlers/windowResize.js
@@ -70,5 +70,7 @@ function onResize() {
*/
function emit(eventName) {
if (!event[eventName]) return;
- event[eventName].forEach((cb) => cb());
+ for (const cb of event[eventName]) {
+ cb();
+ }
}
diff --git a/src/lib/actionStack.js b/src/lib/actionStack.js
index 03b92e2e8..c09efcea6 100644
--- a/src/lib/actionStack.js
+++ b/src/lib/actionStack.js
@@ -77,7 +77,7 @@ export default {
}
if (appSettings.value.confirmOnExit) {
- let closeMessage =
+ const closeMessage =
acode.exitAppMessage || strings["close app"].capitalize(0);
confirmation = await confirm(strings.warning.toUpperCase(), closeMessage);
}
@@ -110,7 +110,7 @@ export default {
*/
remove(id) {
for (let i = 0; i < stack.length; ++i) {
- let action = stack[i];
+ const action = stack[i];
if (action.id === id) {
stack.splice(i, 1);
return true;
@@ -125,7 +125,7 @@ export default {
* @returns {Boolean}
*/
has(id) {
- for (let act of stack) if (act.id === id) return true;
+ for (const act of stack) if (act.id === id) return true;
return false;
},
/**
diff --git a/src/lib/applySettings.js b/src/lib/applySettings.js
index a70d85933..f0c667e19 100644
--- a/src/lib/applySettings.js
+++ b/src/lib/applySettings.js
@@ -15,7 +15,7 @@ export default {
}
//setup vibration
- app.addEventListener("click", function (e) {
+ app.addEventListener("click", (e) => {
const $target = e.target;
if ($target.hasAttribute("vibrate") && appSettings.value.vibrateOnTap) {
navigator.vibrate(constants.VIBRATION_TIME);
diff --git a/src/lib/commands.js b/src/lib/commands.js
index 305eb35fc..546a37679 100644
--- a/src/lib/commands.js
+++ b/src/lib/commands.js
@@ -304,7 +304,7 @@ export default {
async "insert-color"() {
const { editor } = editorManager;
const range = getColorRange();
- let defaultColor = range ? editor.session.getTextRange(range) : "";
+ const defaultColor = range ? editor.session.getTextRange(range) : "";
editor.blur();
const wasFocused = editorManager.activeFile.focused;
@@ -415,7 +415,7 @@ export default {
Promise.all([getWebviewInfo, getAppInfo])
.then(() => {
- let info = `Device Information:
+ const info = `Device Information:
WebView Info:
Package Name: ${webviewInfo?.packageName || "N/A"}
Version: ${webviewInfo?.versionName || "N/A"}
diff --git a/src/lib/console.js b/src/lib/console.js
index 4367463b4..8eca2fe6d 100644
--- a/src/lib/console.js
+++ b/src/lib/console.js
@@ -4,7 +4,7 @@ import * as esprima from "esprima";
import css from "styles/console.module.scss";
import loadPolyFill from "utils/polyfill";
-(function () {
+(() => {
loadPolyFill.apply(window);
let consoleVisible = false;
@@ -37,7 +37,7 @@ import loadPolyFill from "utils/polyfill";
passive: false,
});
- document.ontouchend = function (e) {
+ document.ontouchend = (e) => {
document.removeEventListener("touchmove", touchmove, {
passive: "false",
});
@@ -219,8 +219,8 @@ import loadPolyFill from "utils/polyfill";
isFocused = true;
if (key === "Enter") {
const regex = /[\[|{\(\)\}\]]/g;
- let code = this.value.trim();
- let isOdd = (code.length - code.replace(regex, "").length) % 2;
+ const code = this.value.trim();
+ const isOdd = (code.length - code.replace(regex, "").length) % 2;
if (!code || isOdd) return;
e.preventDefault();
@@ -242,7 +242,7 @@ import loadPolyFill from "utils/polyfill";
if (obj instanceof Promise && !("[[PromiseStatus]]" in obj))
obj = getPromiseStatus(obj);
- let value = objValue(obj, ...keys);
+ const value = objValue(obj, ...keys);
const $group = tag("c-group");
const $toggler = tag("c-type", {
attr: {
@@ -263,7 +263,7 @@ import loadPolyFill from "utils/polyfill";
const possibleKeys = [];
- for (let key in value) {
+ for (const key in value) {
possibleKeys.push(key);
}
@@ -345,7 +345,7 @@ import loadPolyFill from "utils/polyfill";
if (obj.info) return;
let status = "pending";
let value;
- let result = obj.then(
+ const result = obj.then(
(val) => {
status = "resolved";
value = val;
@@ -401,7 +401,7 @@ import loadPolyFill from "utils/polyfill";
str = joinParams(expression.params);
}
} else {
- let string = parsed.id.name + joinParams(parsed.params || []);
+ const string = parsed.id.name + joinParams(parsed.params || []);
str = string;
}
@@ -429,7 +429,7 @@ import loadPolyFill from "utils/polyfill";
* @param {...any} args
*/
function log(mode, options, ...args) {
- let location = options.location || "console";
+ const location = options.location || "console";
const $messages = tag("c-message", {
attr: {
"log-level": mode,
@@ -533,7 +533,7 @@ import loadPolyFill from "utils/polyfill";
break;
case "%o":
case "%O":
- let id = new Date().getMilliseconds() + "";
+ const id = new Date().getMilliseconds() + "";
window.__objs[id] = value;
value = `Object`;
break;
@@ -595,7 +595,7 @@ import loadPolyFill from "utils/polyfill";
if (error === null) {
error = new Error();
}
- let stack = error.stack.split("\n");
+ const stack = error.stack.split("\n");
if (!skip) stack.splice(1, 1);
let regExecRes = /<(.*)>:(\d+):(\d+)/.exec(stack[1]) || [];
if (!regExecRes.length) {
diff --git a/src/lib/editorManager.js b/src/lib/editorManager.js
index efed71da0..553c0aca6 100644
--- a/src/lib/editorManager.js
+++ b/src/lib/editorManager.js
@@ -28,7 +28,7 @@ async function EditorManager($header, $body) {
* @type {Collapsible & HTMLElement}
*/
let $openFileList;
- let TIMEOUT_VALUE = 500;
+ const TIMEOUT_VALUE = 500;
let preventScrollbarV = false;
let preventScrollbarH = false;
let scrollBarVisibilityCount = 0;
@@ -119,7 +119,7 @@ async function EditorManager($header, $body) {
},
emit(event, ...args) {
let detailedEvent;
- let detailedEventArgs = args.slice(1);
+ const detailedEventArgs = args.slice(1);
if (event === "update") {
const subEvent = args[0];
if (subEvent) {
@@ -144,79 +144,79 @@ async function EditorManager($header, $body) {
);
$hScrollbar.onhide = $vScrollbar.onhide = updateFloatingButton.bind({}, true);
- appSettings.on("update:textWrap", function (value) {
+ appSettings.on("update:textWrap", (value) => {
updateMargin();
- for (let file of manager.files) {
+ for (const file of manager.files) {
file.session.setUseWrapMode(value);
if (!value) file.session.on("changeScrollLeft", onscrollleft);
else file.session.off("changeScrollLeft", onscrollleft);
}
});
- appSettings.on("update:tabSize", function (value) {
+ appSettings.on("update:tabSize", (value) => {
manager.files.forEach((file) => file.session.setTabSize(value));
});
- appSettings.on("update:softTab", function (value) {
+ appSettings.on("update:softTab", (value) => {
manager.files.forEach((file) => file.session.setUseSoftTabs(value));
});
- appSettings.on("update:showSpaces", function (value) {
+ appSettings.on("update:showSpaces", (value) => {
editor.setOption("showInvisibles", value);
});
- appSettings.on("update:fontSize", function (value) {
+ appSettings.on("update:fontSize", (value) => {
editor.setFontSize(value);
});
- appSettings.on("update:openFileListPos", function (value) {
+ appSettings.on("update:openFileListPos", (value) => {
initFileTabContainer();
$vScrollbar.resize();
});
- appSettings.on("update:showPrintMargin", function (value) {
+ appSettings.on("update:showPrintMargin", (value) => {
editorManager.editor.setOption("showPrintMargin", value);
});
- appSettings.on("update:scrollbarSize", function (value) {
+ appSettings.on("update:scrollbarSize", (value) => {
$vScrollbar.size = value;
$hScrollbar.size = value;
});
- appSettings.on("update:liveAutoCompletion", function (value) {
+ appSettings.on("update:liveAutoCompletion", (value) => {
editor.setOption("enableLiveAutocompletion", value);
});
- appSettings.on("update:linenumbers", function (value) {
+ appSettings.on("update:linenumbers", (value) => {
updateMargin(true);
editor.resize(true);
});
- appSettings.on("update:lineHeight", function (value) {
+ appSettings.on("update:lineHeight", (value) => {
editor.container.style.lineHeight = value;
});
- appSettings.on("update:relativeLineNumbers", function (value) {
+ appSettings.on("update:relativeLineNumbers", (value) => {
editor.setOption("relativeLineNumbers", value);
});
- appSettings.on("update:elasticTabstops", function (value) {
+ appSettings.on("update:elasticTabstops", (value) => {
editor.setOption("useElasticTabstops", value);
});
- appSettings.on("update:rtlText", function (value) {
+ appSettings.on("update:rtlText", (value) => {
editor.setOption("rtlText", value);
});
- appSettings.on("update:hardWrap", function (value) {
+ appSettings.on("update:hardWrap", (value) => {
editor.setOption("hardWrap", value);
});
- appSettings.on("update:printMargin", function (value) {
+ appSettings.on("update:printMargin", (value) => {
editor.setOption("printMarginColumn", value);
});
- appSettings.on("update:colorPreview", function (value) {
+ appSettings.on("update:colorPreview", (value) => {
if (value) {
return initColorView(editor, true);
}
@@ -224,16 +224,16 @@ async function EditorManager($header, $body) {
deactivateColorView();
});
- appSettings.on("update:showSideButtons", function () {
+ appSettings.on("update:showSideButtons", () => {
updateMargin();
updateSideButtonContainer();
});
- appSettings.on("update:showAnnotations", function () {
+ appSettings.on("update:showAnnotations", () => {
updateMargin(true);
});
- appSettings.on("update:fadeFoldWidgets", function (value) {
+ appSettings.on("update:fadeFoldWidgets", (value) => {
editor.setOption("fadeFoldWidgets", value);
});
diff --git a/src/lib/fileList.js b/src/lib/fileList.js
index 79a04c5dc..1e04a5986 100644
--- a/src/lib/fileList.js
+++ b/src/lib/fileList.js
@@ -124,7 +124,7 @@ export default function files(dir) {
* @param {FileListEvent} event - Event name
* @param {(tree:Tree)=>void} callback - Callback function
*/
-files.on = function (event, callback) {
+files.on = (event, callback) => {
if (!events[event]) events[event] = [];
events[event].push(callback);
};
@@ -134,7 +134,7 @@ files.on = function (event, callback) {
* @param {FileListEvent} event - Event name
* @param {(tree:Tree)=>void} callback - Callback function
*/
-files.off = function (event, callback) {
+files.off = (event, callback) => {
if (!events[event]) return;
events[event] = events[event].filter((cb) => cb !== callback);
};
@@ -168,7 +168,7 @@ function getTree(treeList, dir) {
*/
function getFile(path, tree) {
const { children } = tree;
- let { url } = tree;
+ const { url } = tree;
if (url === path) return tree;
if (!children) return null;
const len = children.length;
diff --git a/src/lib/installPlugin.js b/src/lib/installPlugin.js
index cddbe3614..c9a828cda 100644
--- a/src/lib/installPlugin.js
+++ b/src/lib/installPlugin.js
@@ -376,7 +376,7 @@ async function listFileRecursive(dir, files) {
*/
async function deleteRedundantFiles(pluginDir, state) {
/** @type {string[]} */
- let files = [];
+ const files = [];
await listFileRecursive(pluginDir, files);
for (const file of files) {
diff --git a/src/lib/loadPlugin.js b/src/lib/loadPlugin.js
index dd968758d..93a23dd9c 100644
--- a/src/lib/loadPlugin.js
+++ b/src/lib/loadPlugin.js
@@ -30,7 +30,7 @@ export default async function loadPlugin(pluginId, justInstalled = false) {
app.append($page);
};
- $page.onhide = function () {
+ $page.onhide = () => {
actionStack.remove(pluginId);
};
diff --git a/src/lib/logger.js b/src/lib/logger.js
index 60bdeea0d..e3d10942a 100644
--- a/src/lib/logger.js
+++ b/src/lib/logger.js
@@ -83,7 +83,7 @@ class Logger {
logContent,
);
} else {
- let existingData = await fsOperation(logFilePath).readFile("utf8");
+ const existingData = await fsOperation(logFilePath).readFile("utf8");
let newData = existingData + "\n" + logContent;
// Check if the new data exceeds the maximum file size
if (new Blob([newData]).size > this.#maxFileSize) {
diff --git a/src/lib/openFile.js b/src/lib/openFile.js
index 76102f7ce..672bae9e4 100644
--- a/src/lib/openFile.js
+++ b/src/lib/openFile.js
@@ -29,7 +29,7 @@ import appSettings from "./settings";
export default async function openFile(file, options = {}) {
try {
- let uri = typeof file === "string" ? file : file.uri;
+ const uri = typeof file === "string" ? file : file.uri;
if (!uri) return;
/**@type {EditorFile} */
diff --git a/src/lib/openFolder.js b/src/lib/openFolder.js
index cbde5fa28..ac3eb72c6 100644
--- a/src/lib/openFolder.js
+++ b/src/lib/openFolder.js
@@ -475,7 +475,7 @@ function execOperation(type, action, url, $target, name) {
if (helpers.isFile(type)) {
$target.querySelector(":scope>span").className =
helpers.getIconForFile(newName);
- let file = editorManager.getFile(url, "uri");
+ const file = editorManager.getFile(url, "uri");
if (file) {
file.uri = newUrl;
file.filename = newName;
diff --git a/src/lib/polyfill.js b/src/lib/polyfill.js
index 9a853d5bc..4df14bb9b 100644
--- a/src/lib/polyfill.js
+++ b/src/lib/polyfill.js
@@ -1,7 +1,7 @@
// polyfill for prepend
-(function (arr) {
- arr.forEach(function (item) {
+((arr) => {
+ arr.forEach((item) => {
if (item.hasOwnProperty("prepend")) {
return;
}
@@ -13,7 +13,7 @@
var argArr = Array.prototype.slice.call(arguments),
docFrag = document.createDocumentFragment();
- argArr.forEach(function (argItem) {
+ argArr.forEach((argItem) => {
var node =
argItem instanceof Node
? argItem
@@ -29,8 +29,8 @@
// polyfill for closest
-(function (arr) {
- arr.forEach(function (item) {
+((arr) => {
+ arr.forEach((item) => {
if (item.hasOwnProperty("closest")) {
return;
}
@@ -54,8 +54,8 @@
// polyfill for replaceWith
-(function (arr) {
- arr.forEach(function (item) {
+((arr) => {
+ arr.forEach((item) => {
if (item.hasOwnProperty("replaceWith")) {
return;
}
@@ -93,8 +93,8 @@
// polyfill for toggleAttribute
-(function (arr) {
- arr.forEach(function (item) {
+((arr) => {
+ arr.forEach((item) => {
if (item.hasOwnProperty("toggleAttribute")) {
return;
}
@@ -116,17 +116,17 @@
// polyfill for performance.now
-(function () {
+(() => {
if ("performance" in window === false) {
window.performance = {};
}
Date.now =
Date.now ||
- function () {
+ (() => {
// thanks IE8
return new Date().getTime();
- };
+ });
if ("now" in window.performance === false) {
var nowOffset = Date.now();
diff --git a/src/lib/recents.js b/src/lib/recents.js
index 9d99526c7..82d551871 100644
--- a/src/lib/recents.js
+++ b/src/lib/recents.js
@@ -87,8 +87,8 @@ const recents = {
};
if (type === "dir" || type === "all") {
- let dirs = this.folders;
- for (let dir of dirs) {
+ const dirs = this.folders;
+ for (const dir of dirs) {
const { url } = dir;
all.push([
@@ -103,8 +103,8 @@ const recents = {
}
if (type === "file" || type === "all") {
- let files = this.files;
- for (let file of files) {
+ const files = this.files;
+ for (const file of files) {
if (!file) continue;
const name = shortName(Url.parse(file).url);
all.push([
diff --git a/src/lib/remoteStorage.js b/src/lib/remoteStorage.js
index 1050eaf80..6d95b858c 100644
--- a/src/lib/remoteStorage.js
+++ b/src/lib/remoteStorage.js
@@ -214,7 +214,7 @@ export default {
if (exists) {
await fs.writeFile(text);
} else {
- let fs = fsOperation(DATA_STORAGE);
+ const fs = fsOperation(DATA_STORAGE);
await fs.createFile(filename, text);
}
}
diff --git a/src/lib/settings.js b/src/lib/settings.js
index 090bf94ab..de72097af 100644
--- a/src/lib/settings.js
+++ b/src/lib/settings.js
@@ -396,7 +396,7 @@ function areEqual(obj1, obj2) {
if (obj1 == null || obj2 == null) return false;
if (obj1.constructor !== obj2.constructor) return false;
- for (let key in obj1) {
+ for (const key in obj1) {
if (!obj2.hasOwnProperty(key)) return false;
if (obj1[key] === obj2[key]) continue;
if (typeof obj1[key] !== "object") return false;
diff --git a/src/pages/about/about.js b/src/pages/about/about.js
index 0d7019ee5..a3f673357 100644
--- a/src/pages/about/about.js
+++ b/src/pages/about/about.js
@@ -18,7 +18,7 @@ export default function AboutInclude() {
action: $page.hide,
});
- $page.onhide = function () {
+ $page.onhide = () => {
actionStack.remove("about");
helpers.hideAd();
};
diff --git a/src/pages/changelog/changelog.js b/src/pages/changelog/changelog.js
index fb5a21b85..f724083eb 100644
--- a/src/pages/changelog/changelog.js
+++ b/src/pages/changelog/changelog.js
@@ -31,7 +31,7 @@ export default async function Changelog() {
$content.innerHTML = 'Failed to load changelog
';
}
- $page.onhide = function () {
+ $page.onhide = () => {
actionStack.remove("changelog");
};
diff --git a/src/pages/donate/donate.js b/src/pages/donate/donate.js
index d44fd543e..c8aba6176 100644
--- a/src/pages/donate/donate.js
+++ b/src/pages/donate/donate.js
@@ -23,7 +23,7 @@ export default function DonateInclude() {
action: $page.hide,
});
- $page.onhide = function () {
+ $page.onhide = () => {
actionStack.remove("donate page");
if (adShown) helpers.hideAd();
};
@@ -33,9 +33,9 @@ export default function DonateInclude() {
iap.setPurchaseUpdatedListener(
(purchases) => {
if (Array.isArray(purchases)) {
- (async function () {
+ (async () => {
const promises = [];
- for (let purchase of purchases) {
+ for (const purchase of purchases) {
promises.push(
new Promise((resolve, reject) => {
iap.consume(
@@ -85,7 +85,7 @@ export default function DonateInclude() {
},
);
- app.onclick = function (e) {
+ app.onclick = (e) => {
const $target = e.target;
if (!($target instanceof HTMLElement)) return;
const action = $target.getAttribute("action");
diff --git a/src/pages/fileBrowser/fileBrowser.js b/src/pages/fileBrowser/fileBrowser.js
index 0e75e0c2b..33337d0a8 100644
--- a/src/pages/fileBrowser/fileBrowser.js
+++ b/src/pages/fileBrowser/fileBrowser.js
@@ -65,7 +65,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
let storageList = JSON.parse(localStorage.storageList || "[]");
let isSelectionMode = false;
- let selectedItems = new Set();
+ const selectedItems = new Set();
if (!info) {
if (mode !== "both") {
@@ -149,7 +149,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
$selectionMenuToggler.style.display = "none";
const progress = {};
- let cachedDir = {};
+ const cachedDir = {};
let currentDir = {
url: null,
name: null,
@@ -208,12 +208,12 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
action: close,
});
- $selectionModeToggler.onclick = function () {
+ $selectionModeToggler.onclick = () => {
isSelectionMode = !isSelectionMode;
toggleSelectionMode(isSelectionMode);
};
- $fbMenu.onclick = function (e) {
+ $fbMenu.onclick = (e) => {
$fbMenu.hide();
const action = e.target.getAttribute("action");
if (action === "settings") {
@@ -271,7 +271,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
}
case "import-project-zip": {
- let zipFile = await new Promise((resolve, reject) => {
+ const zipFile = await new Promise((resolve, reject) => {
sdcard.openDocumentFile(
(res) => {
resolve(res.uri);
@@ -361,7 +361,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
}
const zip = new JSZip();
- let loadingLoader = loader.create(
+ const loadingLoader = loader.create(
strings["loading"],
"Compressing files",
{
@@ -507,12 +507,12 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
}
};
- $search.onclick = function () {
+ $search.onclick = () => {
const $list = $content.get("#list");
if ($list) searchBar($list, (hide) => (hideSearchBar = hide));
};
- $page.onhide = function () {
+ $page.onhide = () => {
hideSearchBar();
helpers.hideAd();
actionStack.clearFromMark();
@@ -728,7 +728,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
const { url: parsedUrl, query } = Url.parse(url);
let path = "";
- for (let dir of dirs) {
+ for (const dir of dirs) {
path = Url.join(path, dir);
navigationArray.push({
url: `${Url.join(parsedUrl, path, "")}${query}`,
@@ -824,7 +824,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
case "open_with":
try {
- let mimeType = mimeTypes.lookup(name || "text/plain");
+ const mimeType = mimeTypes.lookup(name || "text/plain");
const fs = fsOperation(url);
if (/^s?ftp:/.test(url)) return fs.localName;
@@ -1049,7 +1049,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
} catch (err) {}
storageList.forEach((storage) => {
- let url = storage.url || /**@deprecated */ storage["uri"];
+ const url = storage.url || /**@deprecated */ storage["uri"];
util.pushFolder(allStorages, storage.name, url, {
storageType: storage.storageType,
diff --git a/src/pages/plugin/plugin.js b/src/pages/plugin/plugin.js
index 716f86bba..02947904c 100644
--- a/src/pages/plugin/plugin.js
+++ b/src/pages/plugin/plugin.js
@@ -58,7 +58,7 @@ export default async function PluginInclude(
action: $page.hide,
});
- $page.onhide = function () {
+ $page.onhide = () => {
helpers.hideAd();
actionStack.remove("plugin");
loader.removeTitleLoader();
diff --git a/src/pages/plugin/plugin.view.js b/src/pages/plugin/plugin.view.js
index c51592f5a..2192391b4 100644
--- a/src/pages/plugin/plugin.view.js
+++ b/src/pages/plugin/plugin.view.js
@@ -143,7 +143,7 @@ export default (props) => {
>
{(() => {
- let contributorsList = contributors?.length
+ const contributorsList = contributors?.length
? [
{ name: author, role: "Developer", github: authorGithub },
...contributors,
@@ -421,8 +421,8 @@ function Review({
author_reply: authorReply,
}) {
let dp = Url.join(constants.API_BASE, `../user.png`);
- let voteImage = new Ref();
- let review = new Ref();
+ const voteImage = new Ref();
+ const review = new Ref();
if (github) {
dp = `https://avatars.githubusercontent.com/${github}`;
diff --git a/src/pages/problems/problems.js b/src/pages/problems/problems.js
index df7156ffa..f9aadcd79 100644
--- a/src/pages/problems/problems.js
+++ b/src/pages/problems/problems.js
@@ -63,7 +63,7 @@ export default function Problems() {
app.append($page);
helpers.showAd();
- $page.onhide = function () {
+ $page.onhide = () => {
helpers.hideAd();
actionStack.remove("problems");
};
diff --git a/src/palettes/commandPalette/index.js b/src/palettes/commandPalette/index.js
index e3cb90e46..f8fcaca07 100644
--- a/src/palettes/commandPalette/index.js
+++ b/src/palettes/commandPalette/index.js
@@ -15,7 +15,7 @@ export default async function commandPalette() {
function generateHints() {
const hints = [];
- commands.forEach(({ name, description, bindKey }) => {
+ for (const { name, description, bindKey } of commands) {
/**
* @param {boolean} recentlyUsed Is the command recently used
* @returns {{value: string, text: string}}
@@ -26,10 +26,10 @@ export default async function commandPalette() {
});
if (recentCommands.commands.includes(name)) {
hints.unshift(item(true));
- return;
+ continue;
}
hints.push(item());
- });
+ }
return hints;
}
diff --git a/src/palettes/findFile/index.js b/src/palettes/findFile/index.js
index 95dafb642..a8a894430 100644
--- a/src/palettes/findFile/index.js
+++ b/src/palettes/findFile/index.js
@@ -28,7 +28,7 @@ export default async function findFile() {
hintsModification = hints;
const list = [];
- editorManager.files.forEach((file) => {
+ for (const file of editorManager.files) {
const { uri, name } = file;
let { location = "" } = file;
@@ -37,7 +37,7 @@ export default async function findFile() {
}
list.push(hintItem(name, location, uri));
- });
+ }
list.push(...files(hintItem));
return list;
diff --git a/src/settings/backupRestore.js b/src/settings/backupRestore.js
index 1e28f466c..d85dddf85 100644
--- a/src/settings/backupRestore.js
+++ b/src/settings/backupRestore.js
@@ -10,8 +10,7 @@ import Url from "utils/Url";
import helpers from "utils/helpers";
function backupRestore() {
- const title =
- strings.backup.capitalize() + "/" + strings.restore.capitalize();
+ const title = `${strings.backup.capitalize()}/${strings.restore.capitalize()}`;
const items = [
{
key: "backup",
@@ -102,9 +101,9 @@ function backupRestore() {
}
}
-backupRestore.restore = async function (url) {
+backupRestore.restore = async (url) => {
try {
- let fs = fsOperation(url);
+ const fs = fsOperation(url);
let backup = await fs.readFile("utf8");
try {
diff --git a/src/settings/mainSettings.js b/src/settings/mainSettings.js
index 07c5924e3..8399e54f3 100644
--- a/src/settings/mainSettings.js
+++ b/src/settings/mainSettings.js
@@ -62,7 +62,7 @@ export default function mainSettings() {
},
{
key: "backup-restore",
- text: strings.backup.capitalize() + "/" + strings.restore.capitalize(),
+ text: `${strings.backup.capitalize()}/${strings.restore.capitalize()}`,
icon: "cached",
},
{
@@ -72,7 +72,7 @@ export default function mainSettings() {
},
{
key: "plugins",
- text: strings["plugins"],
+ text: strings.plugins,
icon: "extension",
},
{
@@ -89,12 +89,12 @@ export default function mainSettings() {
},
{
key: "editSettings",
- text: `${strings["edit"]} settings.json`,
+ text: `${strings.edit} settings.json`,
icon: "edit",
},
{
key: "changeLog",
- text: `${strings["changelog"]}`,
+ text: `${strings.changelog}`,
icon: "update",
},
];
@@ -151,7 +151,7 @@ export default function mainSettings() {
break;
}
- case "reset":
+ case "reset": {
const confirmation = await confirm(
strings.warning,
strings["restore default settings"],
@@ -161,6 +161,7 @@ export default function mainSettings() {
location.reload();
}
break;
+ }
case "removeads":
try {
diff --git a/src/settings/previewSettings.js b/src/settings/previewSettings.js
index d9529f92e..04bbe7cdf 100644
--- a/src/settings/previewSettings.js
+++ b/src/settings/previewSettings.js
@@ -65,7 +65,7 @@ export default function previewSettings() {
},
{
key: "useCurrentFileForPreview",
- text: strings["should_use_current_file_for_preview"],
+ text: strings.should_use_current_file_for_preview,
checkbox: !!values.useCurrentFileForPreview,
},
{
diff --git a/src/sidebarApps/files/index.js b/src/sidebarApps/files/index.js
index 42a866290..8812d0820 100644
--- a/src/sidebarApps/files/index.js
+++ b/src/sidebarApps/files/index.js
@@ -8,7 +8,7 @@ let container;
export default [
"documents", // icon
"files", // id
- strings["files"], // title
+ strings.files, // title
initApp, // init function
false, // prepend
onSelected, // onSelected function
@@ -45,9 +45,9 @@ function initApp(el) {
*/
function onSelected(el) {
const $scrollableLists = container.getAll(":scope .scroll[data-scroll-top]");
- $scrollableLists.forEach(($el) => {
+ for (const $el of $scrollableLists) {
$el.scrollTop = $el.dataset.scrollTop;
- });
+ }
}
/**
@@ -99,25 +99,24 @@ export function fixHeight(target) {
}
}
- lists.forEach((list) => {
- if (list === activeFileList) return;
+ for (const list of lists) {
+ if (list === activeFileList) continue;
if (target === activeFileList) {
- if (list.collapsed) return;
+ if (list.collapsed) continue;
target = list;
}
if (list === target && target.unclasped) {
list.style.maxHeight = `calc(100% - ${height}px)`;
list.style.height = `calc(100% - ${height}px)`;
- return;
+ continue;
}
- if (list.collapsed) return;
+ if (list.collapsed) continue;
list.collapse();
list.style.removeProperty("max-height");
list.style.removeProperty("height");
- return;
- });
+ }
}
diff --git a/src/sidebarApps/notification/index.js b/src/sidebarApps/notification/index.js
index ea72b599e..81dc45676 100644
--- a/src/sidebarApps/notification/index.js
+++ b/src/sidebarApps/notification/index.js
@@ -12,7 +12,7 @@ let notificationManager;
export default [
"notifications", // icon
"notification", // id
- strings["notifications"], // title
+ strings.notifications, // title
initApp, // init function
false, // prepend
onSelected, // onSelected function
@@ -21,11 +21,11 @@ export default [
const $header = (
- {strings["notifications"]}
+ {strings.notifications}
notificationManager.clearAll()}
- >
+ />
);
@@ -38,9 +38,7 @@ function initApp(el) {
container = el;
container.classList.add("notifications");
container.content = $header;
- $notificationContainer = (
-
- );
+ $notificationContainer =
;
container.append($notificationContainer);
notificationManager = new NotificationManager();
@@ -54,7 +52,7 @@ function initApp(el) {
*/
function onSelected(el) {
const $scrollableLists = container.getAll(":scope .scroll[data-scroll-top]");
- $scrollableLists.forEach(($el) => {
+ for (const $el of $scrollableLists) {
$el.scrollTop = $el.dataset.scrollTop;
- });
+ }
}
diff --git a/src/sidebarApps/searchInFiles/index.js b/src/sidebarApps/searchInFiles/index.js
index 8ab82a162..39a34844e 100644
--- a/src/sidebarApps/searchInFiles/index.js
+++ b/src/sidebarApps/searchInFiles/index.js
@@ -59,25 +59,25 @@ const store = {
return localStorage.getItem(WHOLE_WORD) === "true";
},
set wholeWord(value) {
- return localStorage.setItem(WHOLE_WORD, value);
+ localStorage.setItem(WHOLE_WORD, value);
},
get regExp() {
return localStorage.getItem(REG_EXP) === "true";
},
set regExp(value) {
- return localStorage.setItem(REG_EXP, value);
+ localStorage.setItem(REG_EXP, value);
},
get exclude() {
return localStorage.getItem(EXCLUDE);
},
set exclude(value) {
- return localStorage.setItem(EXCLUDE, value);
+ localStorage.setItem(EXCLUDE, value);
},
get include() {
return localStorage.getItem(INCLUDE);
},
set include(value) {
- return localStorage.setItem(INCLUDE, value);
+ localStorage.setItem(INCLUDE, value);
},
};
@@ -159,19 +159,20 @@ export default [
ref={$search}
type="search"
name="search"
- placeholder={strings["search"]}
+ placeholder={strings.search}
/>
+ />
@@ -203,14 +204,14 @@ export default [
- {" "}
- ({$progress}%)
+ (
+ {$progress}%)
{$error}
+ />
>
);
},
@@ -423,12 +424,12 @@ async function searchAll() {
addEvents();
const allFiles = files();
- editorManager.files.forEach((file) => {
+ for (const file of editorManager.files) {
const exists = allFiles.find((f) => f.url === file.uri);
- if (exists) return;
+ if (exists) continue;
allFiles.push(new Tree(file.name, file.uri, false));
- });
+ }
if (!allFiles.length) {
searchResult.removeGhostText();
@@ -508,7 +509,7 @@ function onErrorMessage(e) {
* @param {boolean} [initializeNewWorkers=true] - Whether to initialize new workers after terminating the existing ones.
*/
function terminateWorker(initializeNewWorkers = true) {
- workers.forEach((worker) => worker.terminate());
+ for (const worker of workers) worker.terminate();
workers.length = 0;
if (!initializeNewWorkers) return;
@@ -629,7 +630,7 @@ function Details({ onexpand }, children) {
function Summary({ marker = true, className }, children) {
return (
- {marker ? : <>>}
+ {marker ? : <>>}
{children}
);
@@ -670,9 +671,7 @@ function Summary({ marker = true, className }, children) {
* @returns {HTMLTextAreaElement}
*/
function Textarea({ name, placeholder, ref }) {
- return autosize(
- ,
- );
+ return autosize();
}
/**
@@ -688,7 +687,7 @@ function Textarea({ name, placeholder, ref }) {
function toRegex(search, options) {
const { caseSensitive = false, wholeWord = false, regExp = false } = options;
- let flags = caseSensitive ? "gm" : "gim";
+ const flags = caseSensitive ? "gm" : "gim";
let regexString = regExp ? search : escapeStringRegexp(search);
if (wholeWord) {
diff --git a/src/sidebarApps/searchInFiles/searchResultMode.js b/src/sidebarApps/searchInFiles/searchResultMode.js
index 2260c502f..b51536e94 100644
--- a/src/sidebarApps/searchInFiles/searchResultMode.js
+++ b/src/sidebarApps/searchInFiles/searchResultMode.js
@@ -10,7 +10,7 @@ ace.define(
"ace/lib/oop",
"ace/mode/text_highlight_rules",
],
- function (require, exports, module) {
+ (require, exports, module) => {
const oop = require("../lib/oop");
const { TextHighlightRules } = require("./text_highlight_rules");
@@ -34,10 +34,10 @@ ace.define(
regex: /[|>][-+\d]*(?:$|\s+(?:$|#))/,
onMatch: function (val, state, stack, line) {
line = line.replace(/ #.*/, "");
- var indent = /^ *((:\s*)?-(\s*[^|>])?)?/
+ let indent = /^ *((:\s*)?-(\s*[^|>])?)?/
.exec(line)[0]
.replace(/\S\s*$/, "").length;
- var indentationIndicator = Number.parseInt(
+ const indentationIndicator = Number.parseInt(
/\d+[\s+-]*$/.exec(line),
);
@@ -68,7 +68,7 @@ ace.define(
token: "indent",
regex: /^ */,
onMatch: function (val, state, stack) {
- var curIndent = stack[1];
+ const curIndent = stack[1];
if (curIndent >= val.length) {
this.next = "start";
@@ -92,7 +92,7 @@ ace.define(
token: "indent",
regex: /^ */,
onMatch: function (val, state, stack) {
- var curIndent = stack[1];
+ const curIndent = stack[1];
if (curIndent >= val.length) {
this.next = "start";
@@ -120,7 +120,7 @@ define("ace/mode/folding/search_result_fold", [
"ace/lib/oop",
"ace/mode/folding/fold_mode",
"ace/range",
-], function (require, exports, module) {
+], (require, exports, module) => {
const oop = require("ace/lib/oop");
const { FoldMode: BaseFoldMode } = require("./fold_mode");
const { Range } = require("ace/range");
@@ -131,35 +131,35 @@ define("ace/mode/folding/search_result_fold", [
(function () {
this.getFoldWidgetRange = function (session, foldStyle, row) {
- var range = this.indentationBlock(session, row);
+ const range = this.indentationBlock(session, row);
if (range) return range;
- var re = /\S/;
- var line = session.getLine(row);
- var startLevel = line.search(re);
+ const re = /\S/;
+ let line = session.getLine(row);
+ const startLevel = line.search(re);
if (startLevel === -1 || line[startLevel] !== "#") return;
- var startColumn = line.length;
- var maxRow = session.getLength();
- var startRow = row;
- var endRow = row;
+ const startColumn = line.length;
+ const maxRow = session.getLength();
+ const startRow = row;
+ let endRow = row;
while (++row < maxRow) {
line = session.getLine(row);
- var level = line.search(re);
+ const level = line.search(re);
if (level === -1) continue;
if (line[level] !== "#") break;
endRow = row;
}
if (endRow > startRow) {
- var endColumn = session.getLine(endRow).length;
+ const endColumn = session.getLine(endRow).length;
return new Range(startRow, startColumn, endRow, endColumn);
}
};
- this.getFoldWidget = function (session, foldStyle, row) {
- var line = session.getLine(row);
- var indent = line.search(/\S/);
- var next = session.getLine(row + 1);
- var prev = session.getLine(row - 1);
- var prevIndent = prev.search(/\S/);
- var nextIndent = next.search(/\S/);
+ this.getFoldWidget = (session, foldStyle, row) => {
+ const line = session.getLine(row);
+ const indent = line.search(/\S/);
+ const next = session.getLine(row + 1);
+ const prev = session.getLine(row - 1);
+ const prevIndent = prev.search(/\S/);
+ const nextIndent = next.search(/\S/);
if (indent === -1) {
session.foldWidgets[row - 1] =
prevIndent !== -1 && prevIndent < nextIndent ? "start" : "";
@@ -190,7 +190,7 @@ define("ace/mode/folding/search_result_fold", [
session.foldWidgets[row - 1] = "start";
else session.foldWidgets[row - 1] = "";
if (indent < nextIndent) return "start";
- else return "";
+ return "";
};
}).call(FoldMode.prototype);
});
@@ -206,7 +206,7 @@ ace.define(
"ace/mode/folding/search_result_fold",
"ace/search_result_highlight_rules",
],
- function (require, exports, module) {
+ (require, exports, module) => {
const oop = require("ace/lib/oop");
const { Mode: TextMode } = require("./text");
const { SearchHighlightRules } = require("./search_result_highlight_rules");
diff --git a/src/sidebarApps/searchInFiles/worker.js b/src/sidebarApps/searchInFiles/worker.js
index 3798715fc..d88a417a4 100644
--- a/src/sidebarApps/searchInFiles/worker.js
+++ b/src/sidebarApps/searchInFiles/worker.js
@@ -83,7 +83,8 @@ function searchInFile({ file, content, search }) {
text = `...${text.slice(-30)}`;
}
- while ((match = search.exec(content))) {
+ match = search.exec(content);
+ while (match) {
const [word] = match;
const start = match.index;
const end = start + word.length;
@@ -94,6 +95,7 @@ function searchInFile({ file, content, search }) {
const [line, renderText] = getSurrounding(content, word, start, end);
text += `\n\t${line.trim()}`;
matches.push({ match: word, position, renderText });
+ match = search.exec(content);
}
self.postMessage({
@@ -139,11 +141,11 @@ function getSurrounding(content, word, start, end) {
word = word.slice(-max);
result = [`...${word}`, word];
} else {
- let left = Math.floor(remaining / 2);
- let right = left;
+ const left = Math.floor(remaining / 2);
+ const right = left;
- let leftText = content.substring(start - left, start);
- let rightText = content.substring(end, end + right);
+ const leftText = content.substring(start - left, start);
+ const rightText = content.substring(end, end + right);
result = [`${leftText}${word}${rightText}`, word];
}
diff --git a/src/sidebarApps/sidebarApp.js b/src/sidebarApps/sidebarApp.js
index 95409f0e6..3e3eba871 100644
--- a/src/sidebarApps/sidebarApp.js
+++ b/src/sidebarApps/sidebarApp.js
@@ -31,7 +31,7 @@ export default class SidebarApp {
*/
constructor(icon, id, title, init, onselect) {
const emptyFunc = () => {};
- this.#container = ;
+ this.#container = ;
this.#icon = ;
this.#id = id;
this.#title = title;
@@ -133,7 +133,7 @@ function Icon({ icon, id, title }) {
data-id={id}
title={title}
className={className}
- >
+ />
);
}
diff --git a/src/utils/Path.js b/src/utils/Path.js
index dd5d9f126..7b917cb39 100644
--- a/src/utils/Path.js
+++ b/src/utils/Path.js
@@ -13,7 +13,7 @@ export default {
const res = parts.join("/");
if (!res) return "/";
- else return res;
+ return res;
},
/**
@@ -30,7 +30,7 @@ export default {
const last = ar.slice(-1)[0];
if (!last) return ar.slice(-2)[0];
let res = decodeURI(last.split("?")[0] || "");
- if (this.extname(res) === ext) res = res.replace(new RegExp(ext + "$"), "");
+ if (this.extname(res) === ext) res = res.replace(new RegExp(`${ext}$`), "");
return res;
},
@@ -83,7 +83,7 @@ export default {
* @param {...string} paths
*/
join(...paths) {
- let res = paths.join("/");
+ const res = paths.join("/");
return this.normalize(res);
},
@@ -98,15 +98,15 @@ export default {
const resolved = [];
const pathAr = path.split("/");
- pathAr.forEach((dir) => {
+ for (const dir of pathAr) {
if (dir === "..") {
if (resolved.length) resolved.pop();
} else if (dir === ".") {
- return;
+ // Empty block since the continue was unnecessary
} else {
resolved.push(dir);
}
- });
+ }
return resolved.join("/");
},
@@ -137,24 +137,24 @@ export default {
```js
resolvePath('path/to/some/dir/', '../../dir') //returns 'path/to/dir'
```
- * @param {...string} paths
+ * @param {...string} paths
*/
resolve(...paths) {
if (!paths.length) throw new Error("resolve(...path) : Arguments missing!");
let result = "";
- paths.forEach((path) => {
+ for (const path of paths) {
if (path.startsWith("/")) {
result = path;
- return;
+ continue;
}
result = this.normalize(this.join(result, path));
- });
+ }
if (result.startsWith("/")) return result;
- else return "/" + result;
+ return `/${result}`;
},
/**
@@ -170,7 +170,7 @@ resolvePath('path/to/some/dir/', '../../dir') //returns 'path/to/dir'
const p2len = path2.length;
let flag = false;
- let path = [];
+ const path = [];
path1.forEach((dir, i) => {
if (dir === path2[i] && !flag) return;
diff --git a/src/utils/Uri.js b/src/utils/Uri.js
index 195ab1762..5aca061cc 100644
--- a/src/utils/Uri.js
+++ b/src/utils/Uri.js
@@ -84,7 +84,7 @@ export default {
const storageList = JSON.parse(localStorage.storageList || "[]");
const matches = [];
- for (let storage of storageList) {
+ for (const storage of storageList) {
const regex = new RegExp(
"^" + escapeStringRegexp(storage.uri ?? storage.url),
);
diff --git a/src/utils/Url.js b/src/utils/Url.js
index 34bca3043..81e5bb2fc 100644
--- a/src/utils/Url.js
+++ b/src/utils/Url.js
@@ -56,7 +56,7 @@ export default {
extname(url) {
const name = this.basename(url);
if (name) return path.extname(name);
- else return null;
+ return null;
},
/**
* Join all arguments together and normalize the resulting path.
@@ -92,7 +92,7 @@ export default {
return null;
}
} else if (protocol) {
- url = url.replace(new RegExp("^" + protocol), "");
+ url = url.replace(new RegExp(`^${protocol}`), "");
pathnames[0] = url;
return protocol + path.join(...pathnames) + query;
} else {
@@ -105,10 +105,10 @@ export default {
* @returns {string}
*/
safe(url) {
- let { url: uri, query } = this.parse(url);
+ const { url: uri, query } = this.parse(url);
url = uri;
const protocol = (this.PROTOCOL_PATTERN.exec(url) || [])[0] || "";
- if (protocol) url = url.replace(new RegExp("^" + protocol), "");
+ if (protocol) url = url.replace(new RegExp(`^${protocol}`), "");
const parts = url.split("/").map((part, i) => {
if (i === 0) return part;
return fixedEncodeURIComponent(part);
@@ -116,9 +116,10 @@ export default {
return protocol + parts.join("/") + query;
function fixedEncodeURIComponent(str) {
- return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
- return "%" + c.charCodeAt(0).toString(16);
- });
+ return encodeURIComponent(str).replace(
+ /[!'()*]/g,
+ (c) => `%${c.charCodeAt(0).toString(16)}`,
+ );
}
},
/**
@@ -136,17 +137,17 @@ export default {
try {
const { rootUri, docId, isFileUri } = Uri.parse(url);
if (isFileUri) return this.pathname(rootUri);
- else return "/" + (docId.split(":")[1] || docId);
+ return `/${docId.split(":")[1] || docId}`;
} catch (error) {
return null;
}
} else {
- if (protocol) url = url.replace(new RegExp("^" + protocol), "");
+ if (protocol) url = url.replace(new RegExp(`^${protocol}`), "");
if (protocol !== "file:///")
- return "/" + url.split("/").slice(1).join("/");
+ return `/${url.split("/").slice(1).join("/")}`;
- return "/" + url;
+ return `/${url}`;
}
},
@@ -167,11 +168,9 @@ export default {
let { rootUri, docId, isFileUri } = Uri.parse(url);
if (isFileUri) return this.dirname(rootUri);
- else {
- if (docId.endsWith("/")) docId = docId.slice(0, -1);
- docId = [...docId.split("/").slice(0, -1), ""].join("/");
- return Uri.format(rootUri, docId);
- }
+ if (docId.endsWith("/")) docId = docId.slice(0, -1);
+ docId = [...docId.split("/").slice(0, -1), ""].join("/");
+ return Uri.format(rootUri, docId);
} catch (error) {
return null;
}
@@ -224,7 +223,7 @@ export default {
if (port) string += `:${port}`;
if (path) {
- if (!path.startsWith("/")) path = "/" + path;
+ if (!path.startsWith("/")) path = `/${path}`;
string += path;
}
@@ -232,7 +231,7 @@ export default {
if (query && typeof query === "object") {
string += "?";
- for (let key in query) string += `${enc(key)}=${enc(query[key])}&`;
+ for (const key in query) string += `${enc(key)}=${enc(query[key])}&`;
string = string.slice(0, -1);
}
@@ -256,9 +255,8 @@ export default {
const { protocol, username, hostname, pathname } = URLParse(url);
if (protocol === "file:") {
return url;
- } else {
- return `${protocol}//${username}@${hostname}${pathname}`;
}
+ return `${protocol}//${username}@${hostname}${pathname}`;
},
/**
* Decodes url and returns username, password, hostname, pathname, port and query
@@ -266,7 +264,7 @@ export default {
* @returns {URLObject}
*/
decodeUrl(url) {
- const uuid = "uuid" + Math.floor(Math.random() + Date.now() * 1000000);
+ const uuid = `uuid${Math.floor(Math.random() + Date.now() * 1000000)}`;
if (/#/.test(url)) {
url = url.replace(/#/g, uuid);
@@ -294,7 +292,7 @@ export default {
port = Number.parseInt(port);
}
- let { keyFile, passPhrase } = query;
+ const { keyFile, passPhrase } = query;
if (keyFile) {
query.keyFile = decodeURIComponent(keyFile);
diff --git a/src/utils/color/hsl.js b/src/utils/color/hsl.js
index ddb7769bd..90c20ba3e 100644
--- a/src/utils/color/hsl.js
+++ b/src/utils/color/hsl.js
@@ -111,9 +111,9 @@ export default class Hsl {
}
// now convert hsl value to rgb
- let c = (1 - Math.abs(2 * this.l - 1)) * this.s;
- let x = c * (1 - Math.abs(((this.h * 6) % 2) - 1));
- let m = this.l - c / 2;
+ const c = (1 - Math.abs(2 * this.l - 1)) * this.s;
+ const x = c * (1 - Math.abs(((this.h * 6) % 2) - 1));
+ const m = this.l - c / 2;
let r = 0;
let g = 0;
let b = 0;
diff --git a/src/utils/color/index.js b/src/utils/color/index.js
index 027c6e526..d7c6c6cb8 100644
--- a/src/utils/color/index.js
+++ b/src/utils/color/index.js
@@ -3,7 +3,7 @@ import Hsl from "./hsl";
import Rgb from "./rgb";
/**@type {CanvasRenderingContext2D} */
-const ctx = ().getContext("2d", {
+const ctx = ().getContext("2d", {
willReadFrequently: true,
});
diff --git a/src/utils/encodings.js b/src/utils/encodings.js
index fbe122df6..b7cece1a1 100644
--- a/src/utils/encodings.js
+++ b/src/utils/encodings.js
@@ -1,7 +1,7 @@
import alert from "dialogs/alert";
import settings from "lib/settings";
-let encodings = {};
+const encodings = {};
/**
* @typedef {Object} Encoding
@@ -87,10 +87,10 @@ export async function initEncodings() {
return new Promise((resolve, reject) => {
cordova.exec(
(map) => {
- Object.keys(map).forEach((key) => {
+ for (const key of Object.keys(map)) {
const encoding = map[key];
encodings[key] = encoding;
- });
+ }
resolve();
},
(error) => {
diff --git a/src/utils/helpers.js b/src/utils/helpers.js
index f70fdf776..65bb83fe6 100644
--- a/src/utils/helpers.js
+++ b/src/utils/helpers.js
@@ -265,7 +265,7 @@ export default {
const files = editorManager.files;
const { url } = Url.parse(oldUrl);
- for (let file of files) {
+ for (const file of files) {
if (!file.uri) continue;
const fileUrl = Url.parse(file.uri).url;
if (new RegExp("^" + escapeStringRegexp(url)).test(fileUrl)) {
diff --git a/src/utils/keyboardEvent.js b/src/utils/keyboardEvent.js
index 3eabdd098..336b89381 100644
--- a/src/utils/keyboardEvent.js
+++ b/src/utils/keyboardEvent.js
@@ -37,7 +37,7 @@ const keys = {
46: "Delete",
};
-const initKeyboardEventType = (function (event) {
+let initKeyboardEventType = ((event) => {
try {
event.initKeyboardEvent(
"keyup", // in DOMString typeArg
@@ -54,9 +54,8 @@ const initKeyboardEventType = (function (event) {
);
return (
- ((((event["keyIdentifier"] || event["key"]) === "+" &&
- event["location"]) ||
- event["keyLocation"] === 3) &&
+ ((((event.keyIdentifier || event.key) === "+" && event.location) ||
+ event.keyLocation === 3) &&
(event.ctrlKey
? event.altKey
? // webkit
@@ -98,11 +97,11 @@ const own = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
const ObjectDefineProperty =
Object.defineProperty ||
- function (obj, prop, val) {
+ ((obj, prop, val) => {
if ("value" in val) {
- obj[prop] = val["value"];
+ obj[prop] = val.value;
}
- };
+ });
/**
* Creates a keyboard event
@@ -120,7 +119,7 @@ export default function KeyboardEvent(type, dict) {
}
let propName;
- let localDict = {};
+ const localDict = {};
if (!dict.key && (dict.keyCode || dict.which)) {
let key = keys[dict.keyCode || dict.which];
@@ -139,11 +138,11 @@ export default function KeyboardEvent(type, dict) {
keyboardEventPropertiesDictionary)[propName];
}
- const ctrlKey = localDict["ctrlKey"];
- const shiftKey = localDict["shiftKey"];
- const altKey = localDict["altKey"];
- const metaKey = localDict["metaKey"];
- const altGraphKey = localDict["altGraphKey"];
+ const ctrlKey = localDict.ctrlKey;
+ const shiftKey = localDict.shiftKey;
+ const altKey = localDict.altKey;
+ const metaKey = localDict.metaKey;
+ const altGraphKey = localDict.altGraphKey;
const modifiersListArg =
initKeyboardEventType > 3
@@ -156,22 +155,28 @@ export default function KeyboardEvent(type, dict) {
).trim()
: null;
- const key = localDict["key"] + "";
- const char = localDict["char"] + "";
- const location = localDict["location"];
- const keyCode =
- localDict["keyCode"] ||
- (localDict["keyCode"] = (key && key.charCodeAt(0)) || 0);
- const charCode =
- localDict["charCode"] ||
- (localDict["charCode"] = (char && char.charCodeAt(0)) || 0);
- const bubbles = localDict["bubbles"];
- const cancelable = localDict["cancelable"];
- const repeat = localDict["repeat"];
- const locale = localDict["locale"];
+ const key = `${localDict.key}`;
+ const char = `${localDict.char}`;
+ const location = localDict.location;
+ let keyCode = localDict.keyCode;
+ if (!keyCode) {
+ localDict.keyCode = key?.charCodeAt(0) || 0;
+ keyCode = localDict.keyCode;
+ }
+ let charCode = localDict.charCode;
+ if (!charCode) {
+ localDict.charCode = char?.charCodeAt(0) || 0;
+ charCode = localDict.charCode;
+ }
+ const bubbles = localDict.bubbles;
+ const cancelable = localDict.cancelable;
+ const repeat = localDict.repeat;
+ const locale = localDict.locale;
const view = window;
- localDict["which"] || (localDict["which"] = localDict["keyCode"]);
+ if (!localDict.which) {
+ localDict.which = localDict.keyCode;
+ }
if ("initKeyEvent" in event) {
//FF
diff --git a/src/utils/polyfill.js b/src/utils/polyfill.js
index 695c56ce2..a930d6b3f 100644
--- a/src/utils/polyfill.js
+++ b/src/utils/polyfill.js
@@ -39,7 +39,7 @@ export default function loadPolyFill() {
if (!HTMLElement.prototype.getParent) {
HTMLElement.prototype.getParent = function (queryString) {
const $$ = [...document.querySelectorAll(queryString)];
- for (let $ of $$) if ($.contains(this)) return $;
+ for (const $ of $$) if ($.contains(this)) return $;
return null;
};
}
@@ -61,7 +61,7 @@ export default function loadPolyFill() {
if (!String.prototype.subtract) {
Object.defineProperty(String.prototype, "subtract", {
value: function (str) {
- return this.replace(new RegExp("^" + str), "");
+ return this.replace(new RegExp(`^${str}`), "");
},
});
}
@@ -76,14 +76,13 @@ export default function loadPolyFill() {
this.slice(index + 1),
];
return strs[0] + (strs[1] ? strs[1].toUpperCase() : "") + strs[2];
- } else {
- let strs = this.split(" ");
- strs = strs.map((str) => {
- if (str.length > 0) return str[0].toUpperCase() + str.slice(1);
- return "";
- });
- return strs.join(" ");
}
+ let strs = this.split(" ");
+ strs = strs.map((str) => {
+ if (str.length > 0) return str[0].toUpperCase() + str.slice(1);
+ return "";
+ });
+ return strs.join(" ");
},
});
}
diff --git a/src/utils/taskManager.js b/src/utils/taskManager.js
index 076403219..15f4d6c89 100644
--- a/src/utils/taskManager.js
+++ b/src/utils/taskManager.js
@@ -73,7 +73,9 @@ export default class TaskManager {
this.#busy = false;
}
- this.#listeners.forEach((l) => l(task, result, error));
+ for (const l of this.#listeners) {
+ l(task, result, error);
+ }
if (this.#mode === "linear") this.#execNext();
}
}
diff --git a/utils/config.js b/utils/config.js
index 93448eb87..8a07ca513 100755
--- a/utils/config.js
+++ b/utils/config.js
@@ -35,12 +35,12 @@ const exec = promisify(require("node:child_process").exec);
let babelrcText = fs.readFileSync(babelrcpath, "utf-8");
let config = fs.readFileSync(configpath, "utf-8");
let html = fs.readFileSync(htmlpath, "utf-8");
- let platforms = fs
+ const platforms = fs
.readdirSync(platformsDir)
.filter((file) => !file.startsWith("."));
- let logo, id, currentId;
-
- currentId = /id="([a-z.]+)"/.exec(config)[1];
+ let logo;
+ let id;
+ const currentId = /id="([a-z.]+)"/.exec(config)[1];
babelrc = JSON.parse(babelrcText);
if (arg === "d") {
@@ -70,7 +70,7 @@ const exec = promisify(require("node:child_process").exec);
fs.writeFileSync(logopath, logo, "utf8");
fs.writeFileSync(configpath, config, "utf8");
- for (let platform of platforms) {
+ for (const platform of platforms) {
if (!platform) continue;
promises.push(
@@ -80,23 +80,23 @@ const exec = promisify(require("node:child_process").exec);
);
if (id === ID_FREE) {
- console.log(`|--- Installing Admob ---|`);
+ console.log("|--- Installing Admob ---|");
await exec(
- `cordova plugin add cordova-plugin-consent@2.4.0 --save`,
+ "cordova plugin add cordova-plugin-consent@2.4.0 --save",
);
await exec(
`cordova plugin add admob-plus-cordova@1.28.0 --save --variable APP_ID_ANDROID="${AD_APP_ID}" --variable PLAY_SERVICES_VERSION="21.5.0"`,
);
console.log("DONE! Installing admob-plus-cordova");
} else {
- console.log(`|--- Removing Admob ---|`);
- await exec(`cordova plugin remove cordova-plugin-consent --save`);
- await exec(`cordova plugin remove admob-plus-cordova --save`);
+ console.log("|--- Removing Admob ---|");
+ await exec("cordova plugin remove cordova-plugin-consent --save");
+ await exec("cordova plugin remove admob-plus-cordova --save");
console.log("DONE! Removing admob-plus-cordova");
}
- console.log(`|--- Reinstalling platform ---|`);
- const { stderr } = await exec(`yarn clean`);
+ console.log("|--- Reinstalling platform ---|");
+ const { stderr } = await exec("yarn clean");
if (stderr) console.error(stderr);
else console.log("DONE! Reinstalling platform");
})(),
diff --git a/utils/lang.js b/utils/lang.js
index b6af02506..4c5fea328 100755
--- a/utils/lang.js
+++ b/utils/lang.js
@@ -68,7 +68,7 @@ async function update() {
if (file === "en-us.json") return;
let flagError = false;
- let langFile = path.join(dir, file);
+ const langFile = path.join(dir, file);
const exit = (i, len) => {
if (i + 1 === len) {
if (!error) {
@@ -85,7 +85,7 @@ async function update() {
return;
}
- let langError = () => {
+ const langError = () => {
if (!flagError) {
error = true;
flagError = true;
@@ -95,7 +95,7 @@ async function update() {
const langData = JSON.parse(data);
flagError = false;
- for (let enKey in enLangData) {
+ for (const enKey in enLangData) {
const key = Object.keys(langData).find((k) => {
try {
if (new RegExp(`^${escapeRegExp(k)}$`, "i").test(enKey)) {
@@ -185,9 +185,8 @@ async function update() {
delete strings[key];
console.log(`Removed: ${key}`);
return strings;
- } else {
- console.error("String not exists");
}
+ console.error("String not exists");
});
} else if (command === "update-key") {
update((strings) => {
@@ -203,10 +202,10 @@ async function update() {
return strings;
});
} else {
- getStr(`${langName}: `).then((res) => {
- res = res || arg;
+ getStr(`${langName}: `).then((translatedString) => {
+ const updatedString = translatedString || arg;
update((strings) => {
- strings[key] = res;
+ strings[key] = updatedString;
return strings;
});
});
@@ -243,19 +242,19 @@ async function update() {
if (i === list.length - 1) {
process.exit();
} else {
- askTranslation(++i);
+ askTranslation(i + 1);
}
}
}
- function addString(string) {
- string = string || arg;
+ function addString(inputString) {
+ const stringToAdd = inputString || arg;
update((strings) => {
if (key in strings) {
console.error("String already exists");
process.exit(1);
} else {
- strings[key] = string;
+ strings[key] = stringToAdd;
return strings;
}
});
diff --git a/utils/loadStyles.js b/utils/loadStyles.js
index cfe038dab..68d9cf1b8 100644
--- a/utils/loadStyles.js
+++ b/utils/loadStyles.js
@@ -9,7 +9,7 @@ const cssFiles = fs.readdirSync(CSS).filter((file) => file.endsWith(".css"));
const htmlFiles = fs.readdirSync(WWW).filter((file) => file.endsWith(".html"));
try {
- for (let htmlFile of htmlFiles) {
+ for (const htmlFile of htmlFiles) {
loadStyles(path.resolve(WWW, htmlFile));
}
} catch (error) {
@@ -27,7 +27,7 @@ process.exit(0);
function loadStyles(htmlFile) {
let styles = "";
- for (let cssFile of cssFiles) {
+ for (const cssFile of cssFiles) {
styles += `\n`;
}
@@ -37,6 +37,6 @@ function loadStyles(htmlFile) {
/([^<]*(?:<(?!!--styles_end-->)[^<]*)*)\n*/gim;
let html = fs.readFileSync(htmlFile, "utf8");
html = html.replace(rgx, "");
- html = html.replace("", styles + "");
+ html = html.replace("", `${styles}`);
fs.writeFileSync(htmlFile, html);
}
diff --git a/utils/setup.js b/utils/setup.js
index 9eaafa923..b7919f78a 100644
--- a/utils/setup.js
+++ b/utils/setup.js
@@ -33,7 +33,7 @@ execSync("cordova plugin add cordova-plugin-device", { stdio: "inherit" });
execSync("cordova plugin add cordova-plugin-file", { stdio: "inherit" });
const plugins = fs.readdirSync(path.join(__dirname, "../src/plugins"));
-plugins.forEach((plugin) => {
- if (PLATFORM_FILES.includes(plugin) || plugin.startsWith(".")) return;
+for (const plugin of plugins) {
+ if (PLATFORM_FILES.includes(plugin) || plugin.startsWith(".")) continue;
execSync(`cordova plugin add ./src/plugins/${plugin}`, { stdio: "inherit" });
-});
+}