@visulima/path
Version:
Drop-in replacement of the Node.js path module.
105 lines (104 loc) • 4.17 kB
TypeScript
/**
* A modified version from `https://github.com/unjs/pathe/blob/main/src/path.ts`
*
* MIT License
* Copyright (c) Pooya Parsa <pooya@pi0.io> - Daniel Roe <daniel@roe.dev>
*/
/**
* Based on Node.js implementation:
* - Forked from: https://github.com/nodejs/node/blob/4b030d057375e58d2e99182f6ef7aa70f6ebcf99/lib/path.js
* - Latest: https://github.com/nodejs/node/blob/main/lib/path.js
* Check LICENSE file
*/
import type path from "node:path";
/**
* File system path separator constant, forced to POSIX style for consistency.
*/
export declare const sep = "/";
/**
* Path delimiter constant, used to separate paths in environment variables.
*/
export declare const delimiter: string;
/**
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
* @param path The path to normalise.
* @param allowAboveRoot Whether to allow the resulting path to be above the root directory.
* @returns the normalised path string.
*/
export declare const normalizeString: (path: string, allowAboveRoot: boolean) => string;
/**
* Determines if a path is an absolute path.
* @param path The path to check.
* @returns `true` if the path is absolute, otherwise `false`.
*/
export declare const isAbsolute: typeof path.isAbsolute;
/**
* Normalises the given path, resolving '.' and '.' segments.
* @param path The path to normalise.
* @returns the normalised path.
*/
export declare const normalize: typeof path.normalize;
/**
* Joins all given path segments using the POSIX separator, then normalises the resulting path.
* @param arguments_ The path segments to join.
* @returns the joined and normalised path.
*/
export declare const join: typeof path.join;
/**
* Resolves a sequence of paths to an absolute path.
* The resulting path is normalised and trailing slashes are removed unless the path is a root directory.
* @param arguments_ The sequence of paths to resolve.
* @returns the resolved absolute path.
*/
export declare const resolve: typeof path.resolve;
/**
* Converts a non-namespaced path into a namespaced path. On POSIX systems this is a noop.
* @param p The path to convert.
*/
export declare const toNamespacedPath: typeof path.toNamespacedPath;
/**
* Returns the extension of the path, from the last occurrence of the '.' (period) character to the end of the string in the last part of the path.
* If there is no '.' in the last part of the path, or if there are no '.' characters other than the first character of the basename of the path, an empty string is returned.
* @param p The path to evaluate.
* @returns the extension of the path.
*/
export declare const extname: typeof path.extname;
/**
* Specifies the relative path from one path to another.
* @param from The source path.
* @param to The destination path.
* @returns the relative path from the source to the target.
*/
export declare const relative: typeof path.relative;
/**
* Returns the directory name of a path, similar to the Unix dirname command.
* Trailing directory separators are ignored.
* @param path The path to evaluate.
* @returns the directory portion of the path.
*/
export declare const dirname: typeof path.dirname;
/**
* Returns a path string from an object.
*/
export declare const format: typeof path.format;
/**
* Returns the last part of a path, similar to the Unix basename command.
* Trailing directory separators are considered part of the path.
* @param path The path to evaluate.
* @param extension An optional file extension to remove from the result.
* @returns the last part of the path.
*/
export declare const basename: typeof path.basename;
/**
* Returns an object from a path string - the opposite of format().
* @param p The path string to parse.
* @returns an object representing the path.
*/
export declare const parse: typeof path.parse;
/**
* The `path.matchesGlob()` method determines if `path` matches the `pattern`.
* @param path The path to glob-match against.
* @param pattern The glob to check the path against.
* @returns `true` if the path matches the pattern, otherwise `false`.
*/
export declare const matchesGlob: typeof path.matchesGlob;