mirror of
https://github.com/zadam/trilium.git
synced 2026-08-30 11:06:51 +02:00
chore(nx): move all monorepo-style in subfolder for processing
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
type DateTimeStyle = "full" | "long" | "medium" | "short" | "none" | undefined;
|
||||
|
||||
/**
|
||||
* Formats the given date and time to a string based on the current locale.
|
||||
*/
|
||||
export function formatDateTime(date: string | Date | number, dateStyle: DateTimeStyle = "medium", timeStyle: DateTimeStyle = "medium") {
|
||||
const locale = navigator.language;
|
||||
|
||||
let parsedDate;
|
||||
if (typeof date === "string" || typeof date === "number") {
|
||||
// Parse the given string as a date
|
||||
parsedDate = new Date(date);
|
||||
} else if (date instanceof Date) {
|
||||
// The given date is already a Date instance or a number
|
||||
parsedDate = date;
|
||||
} else {
|
||||
// Invalid type
|
||||
throw new TypeError(`Invalid type for the "date" argument.`);
|
||||
}
|
||||
|
||||
if (timeStyle !== "none" && dateStyle !== "none") {
|
||||
// Format the date and time
|
||||
const formatter = new Intl.DateTimeFormat(navigator.language, { dateStyle, timeStyle });
|
||||
return formatter.format(parsedDate);
|
||||
} else if (timeStyle === "none" && dateStyle !== "none") {
|
||||
// Format only the date
|
||||
return parsedDate.toLocaleDateString(locale, { dateStyle });
|
||||
} else if (dateStyle === "none" && timeStyle !== "none") {
|
||||
// Format only the time
|
||||
return parsedDate.toLocaleTimeString(locale, { timeStyle });
|
||||
}
|
||||
|
||||
throw new Error("Incorrect state.");
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
export default class Mutex {
|
||||
private current: Promise<void>;
|
||||
|
||||
constructor() {
|
||||
this.current = Promise.resolve();
|
||||
}
|
||||
|
||||
lock() {
|
||||
let resolveFun: () => void;
|
||||
const subPromise = new Promise<void>((resolve) => (resolveFun = () => resolve()));
|
||||
// Caller gets a promise that resolves when the current outstanding lock resolves
|
||||
const newPromise = this.current.then(() => resolveFun);
|
||||
// Don't allow the next request until the new promise is done
|
||||
this.current = subPromise;
|
||||
// Return the new promise
|
||||
return newPromise;
|
||||
}
|
||||
|
||||
async runExclusively<T>(cb: () => Promise<T>) {
|
||||
const unlock = await this.lock();
|
||||
|
||||
try {
|
||||
return await cb();
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user