chore(prettier): fix all files

This commit is contained in:
Elian Doran
2025-01-09 18:07:02 +02:00
parent 19ee861699
commit 4cbb529fd4
571 changed files with 23226 additions and 23940 deletions

View File

@@ -11,8 +11,7 @@ function reloadFrontendApp(reason?: string) {
function parseDate(str: string) {
try {
return new Date(Date.parse(str));
}
catch (e: any) {
} catch (e: any) {
throw new Error(`Can't parse date from '${str}': ${e.message} ${e.stack}`);
}
}
@@ -34,26 +33,26 @@ function formatTimeInterval(ms: number) {
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
const plural = (count: number, name: string) => `${count} ${name}${count > 1 ? 's' : ''}`;
const plural = (count: number, name: string) => `${count} ${name}${count > 1 ? "s" : ""}`;
const segments = [];
if (days > 0) {
segments.push(plural(days, 'day'));
segments.push(plural(days, "day"));
}
if (days < 2) {
if (hours % 24 > 0) {
segments.push(plural(hours % 24, 'hour'));
segments.push(plural(hours % 24, "hour"));
}
if (hours < 4) {
if (minutes % 60 > 0) {
segments.push(plural(minutes % 60, 'minute'));
segments.push(plural(minutes % 60, "minute"));
}
if (minutes < 5) {
if (seconds % 60 > 0) {
segments.push(plural(seconds % 60, 'second'));
segments.push(plural(seconds % 60, "second"));
}
}
}
@@ -80,7 +79,7 @@ function formatDateTime(date: Date) {
}
function localNowDateTime() {
return dayjs().format('YYYY-MM-DD HH:mm:ss.SSSZZ');
return dayjs().format("YYYY-MM-DD HH:mm:ss.SSSZZ");
}
function now() {
@@ -95,12 +94,11 @@ function isElectron() {
}
function isMac() {
return navigator.platform.indexOf('Mac') > -1;
return navigator.platform.indexOf("Mac") > -1;
}
function isCtrlKey(evt: KeyboardEvent | MouseEvent | JQuery.ClickEvent) {
return (!isMac() && evt.ctrlKey)
|| (isMac() && evt.metaKey);
return (!isMac() && evt.ctrlKey) || (isMac() && evt.metaKey);
}
function assertArguments(...args: string[]) {
@@ -112,18 +110,18 @@ function assertArguments(...args: string[]) {
}
const entityMap: Record<string, string> = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
'/': '&#x2F;',
'`': '&#x60;',
'=': '&#x3D;'
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#39;",
"/": "&#x2F;",
"`": "&#x60;",
"=": "&#x3D;"
};
function escapeHtml(str: string) {
return str.replace(/[&<>"'`=\/]/g, s => entityMap[s]);
return str.replace(/[&<>"'`=\/]/g, (s) => entityMap[s]);
}
function formatSize(size: number) {
@@ -131,8 +129,7 @@ function formatSize(size: number) {
if (size < 1024) {
return `${size} KiB`;
}
else {
} else {
return `${Math.round(size / 102.4) / 10} MiB`;
}
}
@@ -161,15 +158,19 @@ function randomString(len: number) {
}
function isMobile() {
return window.glob?.device === "mobile"
return (
window.glob?.device === "mobile" ||
// window.glob.device is not available in setup
|| (!window.glob?.device && /Mobi/.test(navigator.userAgent));
(!window.glob?.device && /Mobi/.test(navigator.userAgent))
);
}
function isDesktop() {
return window.glob?.device === "desktop"
return (
window.glob?.device === "desktop" ||
// window.glob.device is not available in setup
|| (!window.glob?.device && !/Mobi/.test(navigator.userAgent));
(!window.glob?.device && !/Mobi/.test(navigator.userAgent))
);
}
/**
@@ -192,7 +193,7 @@ function getMimeTypeClass(mime: string) {
return "";
}
const semicolonIdx = mime.indexOf(';');
const semicolonIdx = mime.indexOf(";");
if (semicolonIdx !== -1) {
// stripping everything following the semicolon
@@ -227,9 +228,7 @@ function focusSavedElement() {
// must handle CKEditor separately because of this bug: https://github.com/ckeditor/ckeditor5/issues/607
// the bug manifests itself in resetting the cursor position to the first character - jumping above
const editor = $lastFocusedElement
.closest('.ck-editor__editable')
.prop('ckeditorInstance');
const editor = $lastFocusedElement.closest(".ck-editor__editable").prop("ckeditorInstance");
if (editor) {
editor.editing.view.focus();
@@ -254,7 +253,7 @@ async function openDialog($dialog: JQuery<HTMLElement>, closeActDialog = true) {
//@ts-ignore
bootstrap.Modal.getOrCreateInstance($dialog[0]).show();
$dialog.on('hidden.bs.modal', () => {
$dialog.on("hidden.bs.modal", () => {
const $autocompleteEl = $(".aa-input");
if ("autocomplete" in $autocompleteEl) {
$autocompleteEl.autocomplete("close");
@@ -276,22 +275,24 @@ async function openDialog($dialog: JQuery<HTMLElement>, closeActDialog = true) {
function isHtmlEmpty(html: string) {
if (!html) {
return true;
} else if (typeof html !== 'string') {
} else if (typeof html !== "string") {
logError(`Got object of type '${typeof html}' where string was expected.`);
return false;
}
html = html.toLowerCase();
return !html.includes('<img')
&& !html.includes('<section')
return (
!html.includes("<img") &&
!html.includes("<section") &&
// the line below will actually attempt to load images so better to check for images first
&& $("<div>").html(html).text().trim().length === 0;
$("<div>").html(html).text().trim().length === 0
);
}
async function clearBrowserCache() {
if (isElectron()) {
const win = dynamicRequire('@electron/remote').getCurrentWindow();
const win = dynamicRequire("@electron/remote").getCurrentWindow();
await win.webContents.session.clearCache();
}
}
@@ -304,16 +305,16 @@ function copySelectionToClipboard() {
}
function dynamicRequire(moduleName: string) {
if (typeof __non_webpack_require__ !== 'undefined') {
if (typeof __non_webpack_require__ !== "undefined") {
return __non_webpack_require__(moduleName);
}
else {
} else {
return require(moduleName);
}
}
function timeLimit<T>(promise: Promise<T>, limitMs: number, errorMessage?: string) {
if (!promise || !promise.then) { // it's not actually a promise
if (!promise || !promise.then) {
// it's not actually a promise
return promise;
}
@@ -323,7 +324,7 @@ function timeLimit<T>(promise: Promise<T>, limitMs: number, errorMessage?: strin
return new Promise<T>((res, rej) => {
let resolved = false;
promise.then(result => {
promise.then((result) => {
resolved = true;
res(result);
@@ -339,8 +340,8 @@ function timeLimit<T>(promise: Promise<T>, limitMs: number, errorMessage?: strin
function initHelpDropdown($el: JQuery<HTMLElement>) {
// stop inside clicks from closing the menu
const $dropdownMenu = $el.find('.help-dropdown .dropdown-menu');
$dropdownMenu.on('click', e => e.stopPropagation());
const $dropdownMenu = $el.find(".help-dropdown .dropdown-menu");
$dropdownMenu.on("click", (e) => e.stopPropagation());
// previous propagation stop will also block help buttons from being opened, so we need to re-init for this element
initHelpButtons($dropdownMenu);
@@ -354,21 +355,21 @@ function openHelp($button: JQuery<HTMLElement>) {
if (helpPage) {
const url = wikiBaseUrl + helpPage;
window.open(url, '_blank');
window.open(url, "_blank");
}
}
function initHelpButtons($el: JQuery<HTMLElement> | JQuery<Window>) {
// for some reason, the .on(event, listener, handler) does not work here (e.g. Options -> Sync -> Help button)
// so we do it manually
$el.on("click", e => {
$el.on("click", (e) => {
const $helpButton = $(e.target).closest("[data-help-page]");
openHelp($helpButton);
});
}
function filterAttributeName(name: string) {
return name.replace(/[^\p{L}\p{N}_:]/ug, "");
return name.replace(/[^\p{L}\p{N}_:]/gu, "");
}
const ATTR_NAME_MATCHER = new RegExp("^[\\p{L}\\p{N}_:]+$", "u");
@@ -393,12 +394,12 @@ function areObjectsEqual(...args: unknown[]) {
let leftChain: Object[];
let rightChain: Object[];
function compare2Objects (x: unknown, y: unknown) {
function compare2Objects(x: unknown, y: unknown) {
let p;
// remember that NaN === NaN returns false
// and isNaN(undefined) returns true
if (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)) {
if (typeof x === "number" && typeof y === "number" && isNaN(x) && isNaN(y)) {
return true;
}
@@ -412,11 +413,13 @@ function areObjectsEqual(...args: unknown[]) {
// Works in case when functions are created in constructor.
// Comparing dates is a common scenario. Another built-ins?
// We can even handle functions passed across iframes
if ((typeof x === 'function' && typeof y === 'function') ||
if (
(typeof x === "function" && typeof y === "function") ||
(x instanceof Date && y instanceof Date) ||
(x instanceof RegExp && y instanceof RegExp) ||
(x instanceof String && y instanceof String) ||
(x instanceof Number && y instanceof Number)) {
(x instanceof Number && y instanceof Number)
) {
return x.toString() === y.toString();
}
@@ -447,8 +450,7 @@ function areObjectsEqual(...args: unknown[]) {
for (p in y) {
if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
return false;
}
else if (typeof (y as any)[p] !== typeof (x as any)[p]) {
} else if (typeof (y as any)[p] !== typeof (x as any)[p]) {
return false;
}
}
@@ -456,15 +458,13 @@ function areObjectsEqual(...args: unknown[]) {
for (p in x) {
if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
return false;
}
else if (typeof (y as any)[p] !== typeof (x as any)[p]) {
} else if (typeof (y as any)[p] !== typeof (x as any)[p]) {
return false;
}
switch (typeof ((x as any)[p])) {
case 'object':
case 'function':
switch (typeof (x as any)[p]) {
case "object":
case "function":
leftChain.push(x);
rightChain.push(y);
@@ -493,7 +493,6 @@ function areObjectsEqual(...args: unknown[]) {
}
for (i = 1, l = arguments.length; i < l; i++) {
leftChain = []; //Todo: this can be cached
rightChain = [];
@@ -531,11 +530,11 @@ function createImageSrcUrl(note: { noteId: string; title: string }) {
*/
function downloadSvg(nameWithoutExtension: string, svgContent: string) {
const filename = `${nameWithoutExtension}.svg`;
const element = document.createElement('a');
element.setAttribute('href', `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgContent)}`);
element.setAttribute('download', filename);
const element = document.createElement("a");
element.setAttribute("href", `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgContent)}`);
element.setAttribute("download", filename);
element.style.display = 'none';
element.style.display = "none";
document.body.appendChild(element);
element.click();
@@ -555,13 +554,12 @@ function downloadSvg(nameWithoutExtension: string, svgContent: string) {
* @returns
*/
function compareVersions(v1: string, v2: string): number {
// Remove 'v' prefix and everything after dash if present
v1 = v1.replace(/^v/, '').split('-')[0];
v2 = v2.replace(/^v/, '').split('-')[0];
v1 = v1.replace(/^v/, "").split("-")[0];
v2 = v2.replace(/^v/, "").split("-")[0];
const v1parts = v1.split('.').map(Number);
const v2parts = v2.split('.').map(Number);
const v1parts = v1.split(".").map(Number);
const v2parts = v2.split(".").map(Number);
// Pad shorter version with zeros
while (v1parts.length < 3) v1parts.push(0);
@@ -593,10 +591,7 @@ function isUpdateAvailable(latestVersion: string, currentVersion: string): boole
}
function isLaunchBarConfig(noteId: string) {
return [
"_lbRoot", "_lbAvailableLaunchers", "_lbVisibleLaunchers",
"_lbMobileRoot", "_lbMobileAvailableLaunchers", "_lbMobileVisibleLaunchers"
].includes(noteId);
return ["_lbRoot", "_lbAvailableLaunchers", "_lbVisibleLaunchers", "_lbMobileRoot", "_lbMobileAvailableLaunchers", "_lbMobileVisibleLaunchers"].includes(noteId);
}
export default {