Skip to content

Commit d909097

Browse files
authored
Misc JS tidy (hestiacp#4877)
1 parent 73b24db commit d909097

File tree

13 files changed

+40
-30
lines changed

13 files changed

+40
-30
lines changed

docs/.vitepress/theme/components/InstallBuilder.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,20 @@ const toggleOption = (option) => {
107107
const installCommand = ref("bash hst-install.sh");
108108
watchEffect(() => {
109109
let cmd = "bash hst-install.sh";
110-
let quoteshellarg = function (str) {
110+
const quoteshellarg = (str) => {
111111
if (!str) return "''";
112-
return "'" + str.replace(/'/g, "'\\''") + "'";
112+
return `'${str.replace(/'/g, "'\\''")}'`;
113113
};
114114
for (const [key, { enabled, value }] of Object.entries(selectedOptions.value)) {
115115
const opt = options.find((o) => o.flag === key);
116116
if (opt.flag == "force" && enabled) {
117-
cmd += ` --force`;
117+
cmd += " --force";
118118
} else if (!opt.type || opt.type === "checkbox") {
119119
if (enabled !== (opt.default === "yes")) {
120120
cmd += ` --${key} ${enabled ? "yes" : "no"}`;
121121
}
122122
} else if (enabled && value !== opt.default) {
123-
let value_quoted = quoteshellarg(value);
123+
const value_quoted = quoteshellarg(value);
124124
cmd += ` --${key} ${value_quoted}`;
125125
}
126126
}

src/deb/web-terminal/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const { config } = JSON.parse(
1515
);
1616

1717
const wss = new WebSocketServer({
18-
port: parseInt(config.WEB_TERMINAL_PORT, 10),
18+
port: Number.parseInt(config.WEB_TERMINAL_PORT, 10),
1919
verifyClient: async (info, cb) => {
2020
if (!info.req.headers.cookie.includes(sessionName)) {
2121
cb(false, 401, 'Unauthorized');
@@ -83,8 +83,8 @@ wss.on('connection', (ws, req) => {
8383
// Spawn shell as logged in user
8484
const pty = spawn(shell, [], {
8585
name: 'xterm-color',
86-
uid: parseInt(uid, 10),
87-
gid: parseInt(gid, 10),
86+
uid: Number.parseInt(uid, 10),
87+
gid: Number.parseInt(gid, 10),
8888
cwd: homedir,
8989
env: {
9090
SHELL: shell,

web/js/src/dnsRecordHint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function handleDnsRecordHint() {
88
return;
99
}
1010

11-
if (recordInput.value.trim() != '') {
11+
if (recordInput.value.trim() !== '') {
1212
updateHint(recordInput);
1313
}
1414

web/js/src/formSubmit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { enableUnlimitedInputs } from './unlimitedInput';
1+
import { delay, isDesktopSafari, showSpinner } from './helpers';
22
import { updateAdvancedTextarea } from './toggleAdvanced';
3-
import { isDesktopSafari, showSpinner, delay } from './helpers';
3+
import { enableUnlimitedInputs } from './unlimitedInput';
44

55
export default function handleFormSubmit() {
66
const mainForm = document.querySelector('#main-form');

web/js/src/ftpAccountHints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function updateFtpPathHint(pathInput, path) {
4646
function normalizePath(path) {
4747
// Add leading slash
4848
if (path[0] !== '/') {
49-
path = '/' + path;
49+
path = `/${path}`;
5050
}
5151

5252
// Remove double slashes

web/js/src/listSorting.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function handleListSorting() {
2929

3030
// Inner dropdown sorting behavior
3131
sortingMenu.querySelectorAll('span').forEach((span) => {
32-
span.addEventListener('click', function () {
32+
span.addEventListener('click', () => {
3333
sortingMenu.classList.add('u-hidden');
3434

3535
// Skip if the clicked sort is already active

web/js/src/listUnitSelect.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export default function handleListUnitSelect() {
2525

2626
selectAllCheckbox.addEventListener('change', () => {
2727
const isChecked = selectAllCheckbox.checked;
28-
checkboxes.forEach((checkbox) => (checkbox.checked = isChecked));
28+
checkboxes.forEach((checkbox) => {
29+
checkbox.checked = isChecked;
30+
});
2931
units.forEach((unit) => updateUnitSelection(unit, isChecked));
3032
});
3133
}

web/js/src/nameServerInput.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ function addNsInput(addNsButton) {
3333
function removeNsInput(removeNsElement) {
3434
removeNsElement.parentElement.remove();
3535
const currentNsInputs = document.querySelectorAll('input[name^=v_ns]');
36-
currentNsInputs.forEach((input, index) => (input.name = `v_ns${index + 1}`));
36+
currentNsInputs.forEach((input, index) => {
37+
input.name = `v_ns${index + 1}`;
38+
});
3739
document.querySelector('.js-add-ns').classList.remove('u-hidden');
3840
}

web/js/src/navigation.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ export function moveFocusUp() {
2323

2424
// Navigate to whatever item has been selected in the UI by other shortcuts
2525
export function enterFocused() {
26-
const activeMainMenuItem = document.querySelector(state.menu_selector + '.focus a');
26+
const activeMainMenuItem = document.querySelector(`${state.menu_selector}.focus a`);
2727
if (activeMainMenuItem) {
28-
return (location.href = activeMainMenuItem.getAttribute('href'));
28+
location.href = activeMainMenuItem.getAttribute('href');
29+
return;
2930
}
3031

3132
const activeUnit = document.querySelector(
@@ -53,7 +54,7 @@ function moveFocusLeftRight(direction) {
5354
const activeSelector = state.menu_active_selector;
5455
const menuItems = Array.from(document.querySelectorAll(menuSelector));
5556
const currentFocused = document.querySelector(`${menuSelector}.focus`);
56-
const currentActive = document.querySelector(menuSelector + activeSelector);
57+
const currentActive = document.querySelector(`${menuSelector}${activeSelector}`);
5758
let index = menuItems.indexOf(currentFocused);
5859

5960
if (index === -1) {

web/js/src/passwordInput.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { passwordStrength } from 'check-password-strength';
2-
import { randomPassword, debounce } from './helpers';
2+
import { debounce, randomPassword } from './helpers';
33

44
// Adds listeners to password inputs (to monitor strength) and generate password buttons
55
export default function handlePasswordInput() {
@@ -30,7 +30,8 @@ function recalculatePasswordStrength(input) {
3030

3131
if (meter) {
3232
if (password === '') {
33-
return (meter.value = 0);
33+
meter.value = 0;
34+
return;
3435
}
3536

3637
meter.value = passwordStrength(password).id + 1;

0 commit comments

Comments
 (0)