obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
60 lines (59 loc) • 1.46 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 minimum timeout for the notice.
*/
noticeMinTimeoutInMilliseconds?: number;
/**
* Process each item.
*
* @param item - The current item.
*/
processItem(item: T): Promisable<void>;
/**
* A title of the progress bar.
*/
progressBarTitle?: string;
/**
* Whether to continue the loop on error.
*/
shouldContinueOnError?: boolean;
/**
* Whether to show a progress bar.
*/
shouldShowProgressBar?: boolean;
/**
* A threshold for the UI update.
*/
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>;