UNPKG

@stryke/path

Version:

A package containing various utilities that expand the functionality of NodeJs's built-in `path` module

114 lines 4.15 kB
//#region src/correct-path.d.ts declare function normalizeWindowsPath(input?: string): string; /** * Corrects/normalized a file path. * * @param path - The path to correct. * @returns The corrected path. */ declare function correctPath(path?: string): string; /** * Remove any star tokens (*) from the end of the file path * * @example * stripStars("src/**") // returns "src" * stripStars("src/*") // returns "src" * stripStars("src/**\/*") // returns "src" * stripStars("src/**\/*.txt") // returns "src" * stripStars("src/**\/file.txt") // returns "src" * stripStars("src/file.txt") // returns "src/file.txt" * stripStars("") // returns "." * * @param path - The path to correct. * @returns The corrected path. */ declare function stripStars(path?: string): string; /** * Resolves a string path, resolving '.' and '.' segments and allowing paths above the root. * * @param path - The path to normalize. * @param allowAboveRoot - Whether to allow the resulting path to be above the root directory. * @returns the normalize path string. */ declare function normalizeString(path: string, allowAboveRoot: boolean): string; /** * Converts a given path to an absolute path based on the current working directory. * * @param path - The path to convert to an absolute path. * @param cwd - The current working directory to use as the base path if the path is not absolute. * @returns The absolute path. */ declare function toAbsolutePath(path: string, cwd?: any): string; /** * Converts a given path to a relative path based on the current working directory. * * @param path - The path to convert to a relative path. * @param cwd - The current working directory to use as the base path if the path is not absolute. * @returns The relative path. */ declare function toRelativePath(path: string, cwd?: any): string; /** * Adds a trailing slash to a path if it doesn't already have one. * * @param path - The path to modify. * @returns The modified path with a trailing slash. */ declare function withTrailingSlash(path: string): string; /** * Removes a trailing slash from a path if it has one. * * @param path - The path to modify. * @returns The modified path without a trailing slash. */ declare function withoutTrailingSlash(path: string): string; /** * Converts a file URL to a local file system path with normalized slashes. * * @example * ```ts * let filePath = fileURLToPath("file:///C:/Users/user/Documents/file.txt"); * // filePath = "C:/Users/user/Documents/file.txt" * * filePath = fileURLToPath(new URL("file:///C:/Users/user/Documents/file.txt")); * // filePath = "C:/Users/user/Documents/file.txt" * ``` * * @param id - The file URL or local path to convert. * @returns A normalized file system path. */ declare function fileURLToPath(id: string | URL): string; /** * Converts a local file system path to a file URL. * * @example * ```ts * let fileUrl = pathToFileURL("C:/Users/user/Documents/file.txt"); * // fileUrl = new URL("file:///C:/Users/user/Documents/file.txt") * * fileUrl = pathToFileURL(new URL("C:/Users/user/Documents/file.txt")); * // fileUrl = new URL("file:///C:/Users/user/Documents/file.txt") * ``` * * @param id - The file system path to convert. * @returns The resulting file URL as a URL object. */ declare function pathToFileURL(id: string | URL): URL; /** * Converts a local file system path to a file URL string. * * @example * ```ts * let fileUrl = pathToFileURLString("C:/Users/user/Documents/file.txt"); * // fileUrl = "file:///C:/Users/user/Documents/file.txt" * * fileUrl = pathToFileURLString(new URL("C:/Users/user/Documents/file.txt")); * // fileUrl = "file:///C:/Users/user/Documents/file.txt" * ``` * * @param id - The file system path to convert. * @returns The resulting file URL as a string. */ declare function pathToFileURLString(id: string | URL): string; //#endregion export { correctPath, fileURLToPath, normalizeString, normalizeWindowsPath, pathToFileURL, pathToFileURLString, stripStars, toAbsolutePath, toRelativePath, withTrailingSlash, withoutTrailingSlash }; //# sourceMappingURL=correct-path.d.mts.map