obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
68 lines (67 loc) • 1.79 kB
text/typescript
/**
* @packageDocumentation
*
* Contains utility functions for looping in Obsidian.
*/
import type { Promisable } from 'type-fest';
/**
* Options for {@link loop}.
*/
export interface LoopOptions<T> {
/**
* An optional abort signal to cancel the loop.
*/
abortSignal?: AbortSignal;
/**
* Build a notice message for each item.
*
* @param item - The current item.
* @param iterationStr - A string representing the current iteration.
* @returns A string to display in the notice.
*/
buildNoticeMessage(item: T, iterationStr: string): string;
/**
* Items to loop over.
*/
items: T[];
/**
* A timeout for the notice before it is shown. Default is `500`.
*/
noticeBeforeShownTimeoutInMilliseconds?: number;
/**
* A minimum timeout for the notice. Default is `2000`.
*/
noticeMinTimeoutInMilliseconds?: number;
/**
* Process each item.
*
* @param item - The current item.
*/
processItem(item: T): Promisable<void>;
/**
* A title of the progress bar. Default is `''`.
*/
progressBarTitle?: string;
/**
* Whether to continue the loop on error. Default is `true`.
*/
shouldContinueOnError?: boolean;
/**
* Whether to show a notice. Default is `true`.
*/
shouldShowNotice?: boolean;
/**
* Whether to show a progress bar. Default is `true`.
*/
shouldShowProgressBar?: boolean;
/**
* A threshold for the UI update. Default is `100`.
*/
uiUpdateThresholdInMilliseconds?: number;
}
/**
* Loops over a list of items and processes each item.
*
* @param options - The options for the loop.
*/
export declare function loop<T>(options: LoopOptions<T>): Promise<void>;