UNPKG

obsidian-dev-utils

Version:

This is the collection of useful functions that you can use for your Obsidian plugin development

41 lines (40 loc) 2.09 kB
/** * @packageDocumentation * * Contains utility functions for managing files in Obsidian. */ import type { App } from 'obsidian'; import type { Promisable } from 'type-fest'; import type { MaybeReturn } from '../Type.cjs'; import type { PathOrFile } from './FileSystem.cjs'; import type { CombinedFrontmatter } from './Frontmatter.cjs'; import type { ProcessOptions } from './Vault.cjs'; /** * Adds an alias to the front matter of a given file if it does not already exist. * * @param app - The Obsidian app instance. * @param pathOrFile - The path or TFile object representing the note. * @param alias - The alias to add. * @returns A {@link Promise} that resolves when the alias has been added. */ export declare function addAlias(app: App, pathOrFile: PathOrFile, alias?: string): Promise<void>; /** * Deletes an alias from the front matter of a given file if it exists. * * @param app - The Obsidian app instance. * @param pathOrFile - The path or TFile object representing the note. * @param alias - The alias to delete. * @returns A {@link Promise} that resolves when the alias has been deleted. */ export declare function deleteAlias(app: App, pathOrFile: PathOrFile, alias?: string): Promise<void>; /** * Processes the front matter of a given file, allowing modifications via a provided function. * * @typeParam CustomFrontmatter - The type of custom front matter. * @param app - The Obsidian app instance. * @param pathOrFile - The path or TFile object representing the note. * @param frontmatterFn - A function that modifies the front matter. * @param processOptions - Optional. Configuration options for retrying the process. If not provided, default options will be used. * @returns A {@link Promise} that resolves when the front matter has been processed and saved. */ export declare function processFrontmatter<CustomFrontmatter = unknown>(app: App, pathOrFile: PathOrFile, frontmatterFn: (frontmatter: CombinedFrontmatter<CustomFrontmatter>, abortSignal: AbortSignal) => Promisable<MaybeReturn<null>>, processOptions?: ProcessOptions): Promise<void>;