UNPKG

@visulima/path

Version:

Drop-in replacement of the Node.js path module.

49 lines (48 loc) 2.23 kB
/** * Normalises alias mappings, ensuring that more specific aliases are resolved before less specific ones. * This function also ensures that aliases do not resolve to themselves cyclically. * @param _aliases A set of alias mappings where each key is an alias and its value is the actual path it points to. * @returns a set of normalised alias mappings. */ export declare const normalizeAliases: (_aliases: Record<string, string>) => Record<string, string>; /** * Resolves a path string to its alias if applicable, otherwise returns the original path. * This function normalises the path, resolves the alias and then joins it to the alias target if necessary. * @param path The path string to resolve. * @param aliases A set of alias mappings to use for resolution. * @returns the resolved path as a string. */ export declare const resolveAlias: (path: string, aliases: Record<string, string>) => string; /** * Extracts the filename from a given path, excluding any directory paths and the file extension. * @param path The full path of the file from which to extract the filename. * @returns the filename without the extension, or `undefined` if the filename cannot be extracted. */ export declare const filename: (path: string) => string; /** * Reverting the resolveAlias method. * @param path * @param aliases * @returns */ export declare const reverseResolveAlias: (path: string, aliases: Record<string, string>) => string; /** * Determines whether a given path is relative. * @param path The path to check. * @returns `true` if the path is relative, otherwise `false`. */ export declare const isRelative: (path: string) => boolean; /** * Determines whether a given path is a binary file. * This function checks the file extension against a list of known binary file extensions. * @param path * @returns `true` if the path is a binary file, otherwise `false`. */ export declare const isBinaryPath: (path: string) => boolean; export declare const toPath: (urlOrPath: URL | string) => string; /** * Detect if the current platform uses Windows-style paths. * * This used automatically in functions prefixed by `sys` to get system-dependent behavior. */ export declare const isWindows: () => boolean;