obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
137 lines (136 loc) • 4.7 kB
text/typescript
/**
* @packageDocumentation
*
* Contains utility functions for handling paths.
*/
import pathBrowserify from 'path-browserify';
/**
* Provides methods for handling POSIX paths.
*/
export declare const posix: pathBrowserify.Path;
/**
* A POSIX path delimiter.
*/
export declare const delimiter: string;
/**
* A POSIX segment separator.
*/
export declare const sep: string;
/**
* Returns the base name of a file, optionally removing the file extension.
*
* @param path - The path to get the base name from.
* @param ext - An optional extension to remove from the base name.
* @returns The base name of the file.
*/
export declare const basename: (this: void, path: string, ext?: string) => string;
/**
* Returns the directory name of a path.
*
* `directory` is used instead of `folder` to preserve compatibility with `node:path` module.
*
* @param path - The path to get the directory name from.
* @returns The directory name of the path.
*/
export declare const dirname: (this: void, path: string) => string;
/**
* Returns the file extension of a path.
*
* @param path - The path to get the extension from.
* @returns The file extension of the path.
*/
export declare const extname: (this: void, path: string) => string;
/**
* Formats a path object into a path string.
*
* @param pathObject - The path object to format.
* @returns The formatted path string.
*/
export declare const format: (this: void, pathObject: Partial<pathBrowserify.PathObject>) => string;
/**
* Determines if a path is absolute.
*
* @param path - The path to check.
* @returns `true` if the path is absolute, `false` otherwise.
*/
export declare function isAbsolute(path: string): boolean;
/**
* Joins multiple path segments into a single path.
*
* @param paths - The path segments to join.
* @returns The joined path.
*/
export declare const join: (this: void, ...paths: string[]) => string;
/**
* Normalizes a path, resolving '..' and '.' segments.
*
* @param path - The path to normalize.
* @returns The normalized path.
*/
export declare const normalize: (this: void, path: string) => string;
/**
* Parses a path string into a path object.
*
* @param path - The path string to parse.
* @returns The parsed path object.
*/
export declare const parse: (this: void, path: string) => pathBrowserify.PathObject;
/**
* Returns the relative path from one path to another.
*
* @param from - The starting path.
* @param to - The destination path.
* @returns The relative path from `from` to `to`.
*/
export declare const relative: (this: void, from: string, to: string) => string;
/**
* Gets the file name from the `import(dot)meta(dot)url`, converting it to a POSIX-style path.
*
* @param importMetaUrl - The `import(dot)meta(dot)url` from which to extract the file name.
* @returns The POSIX-style file name.
*/
export declare function getFileName(importMetaUrl: string): string;
/**
* Gets the folder name from the `import(dot)meta(dot)url`, converting it to a POSIX-style path.
*
* @param importMetaUrl - The `import(dot)meta(dot)url` from which to extract the folder name.
* @returns The POSIX-style folder name.
*/
export declare function getFolderName(importMetaUrl: string): string;
/**
* Makes a file name by appending an extension to a given file name.
* If the extension is empty, the file name is returned as is.
*
* @param fileBaseName - The file name to append the extension to.
* @param fileExtension - The extension to append to the file name.
* @returns The file name with the extension appended.
*/
export declare function makeFileName(fileBaseName: string, fileExtension: string): string;
/**
* Normalizes a given path by ensuring it is relative, adding "./" if necessary.
*
* @param path - The path to normalize.
* @returns The normalized path, starting with "./" if it was relative.
*/
export declare function normalizeIfRelative(path: string): string;
/**
* Resolves a sequence of paths or path segments into an absolute path.
*
* @param pathSegments - The sequence of path segments to resolve.
* @returns The resolved absolute path.
*/
export declare function resolve(...pathSegments: string[]): string;
/**
* Converts a buffer containing a path to a POSIX-style buffer by replacing backslashes with forward slashes.
*
* @param buffer - The buffer to convert.
* @returns A new buffer containing the POSIX-style path.
*/
export declare function toPosixBuffer(buffer: Buffer): Buffer;
/**
* Converts a given path to a POSIX-style path by replacing backslashes with forward slashes.
*
* @param path - The path to convert.
* @returns The POSIX-style path.
*/
export declare function toPosixPath(path: string): string;