A focused Docker Compose management web application.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: add jsdoc

Brooke 617330b5 396ce506

+41 -1
+41 -1
packages/panel/src/lib/index.ts
··· 8 8 9 9 export { isMobile } from "../routes/+layout.svelte"; 10 10 11 + /** 12 + * Trims {@paramstr} to {@param maxLength}, adding ellipses if it was too long. 13 + * @param str The string to trim 14 + * @param maxLength The maximum number of characters to allow before trimming. 15 + * @returns The trimmed string. 16 + */ 11 17 export function trim(str: string, maxLength: number) { 12 18 if (str.length <= maxLength) return str; 13 19 return str.slice(0, maxLength - 3) + "..."; 14 20 } 15 21 22 + /** 23 + * Displays a warning toast to the user. 24 + * @param message The message to display on the toast. 25 + * @param details Any extra details to show in the toast modal. 26 + */ 16 27 export function warn(message: string, details?: string | string[]) { 17 28 addToast({ data: { icon: faTriangleExclamation, color: "peach", title: trim(message, 40), details } }); 18 29 } 19 30 31 + /** 32 + * Displays an error toast to the user. 33 + * @param message The message to display on the toast. 34 + * @param details Any extra details to show in the toast modal. 35 + */ 20 36 export function error(message: string, details?: string | string[]) { 21 37 addToast({ data: { icon: faCircleXmark, color: "red", title: trim(message, 40), details } }); 22 38 } 23 39 40 + /** 41 + * A simple async sleep function that resolves after {@param ms} milliseconds. 42 + * @param ms The number of milliseconds to sleep for. 43 + */ 24 44 export function sleep(ms: number) { 25 45 return new Promise((resolve) => setTimeout(resolve, ms)); 26 46 } 27 47 48 + /** 49 + * A exponential backoff utility class used for managing retry attempts. 50 + */ 28 51 export class Backoff { 52 + /** 53 + * The current delay before the next retry attempt, in milliseconds. 54 + */ 29 55 public currentDelay: number; 56 + 57 + /** 58 + * The initial delay, set when the class is instantiated or reset. 59 + */ 30 60 public initialDelay: number; 61 + 62 + /** 63 + * The maximum delay allowed. 64 + */ 31 65 public maxDelay: number; 32 66 33 - public constructor(initialDelay: number = 1000, maxDelay: number = 30000) { 67 + public constructor(initialDelay: number = 1000, maxDelay: number = 30 * 1000) { 34 68 this.currentDelay = initialDelay; 35 69 this.initialDelay = initialDelay; 36 70 this.maxDelay = maxDelay; 37 71 } 38 72 73 + /** 74 + * Resets the backoff delay to the initial value. 75 + */ 39 76 public reset() { 40 77 this.currentDelay = this.initialDelay; 41 78 } 42 79 80 + /** 81 + * Waits for the current delay duration, and then doubles it. 82 + */ 43 83 public async wait() { 44 84 await sleep(this.currentDelay); 45 85 this.currentDelay = Math.min(this.currentDelay * 2, this.maxDelay);