UNPKG

@stryke/path

Version:

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

46 lines 1.48 kB
//#region src/common.d.ts /** * Get the common path from an array of paths * * @example * ```ts * commonPath(['/foo/bar/baz', '/foo/bar/qux', '/foo/bar/baz/quux']); * // returns '/foo/bar' * * commonPath(['C:/foo/bar/baz', 'C:/foo/bar/qux', 'C:/foo/bar/baz/quux']); * // returns 'C:/foo/bar' * ``` * * @param paths - The array of paths * @returns The common path */ declare function commonPath(paths: string[]): string; declare const findCommonPath: typeof commonPath; /** * Find the base path from a string path/glob or an array of string paths/globs. If a string is provided, it is returned as the base path. If an array of strings is provided, the common path among them is returned. If the input is invalid or empty, "/" is returned. * * @example * ```ts * findBasePath('/foo/bar/baz'); * // returns '/foo/bar/baz' * * findBasePath(['/foo/bar/baz', '/foo/bar/qux', '/foo/bar/baz/quux']); * // returns '/foo/bar' * * findBasePath(['C:/foo/bar/baz', 'C:/foo/bar/qux', 'C:/foo/bar/baz/quux']); * // returns 'C:/foo/bar' * * findBasePath(['foo/bar/**\/baz', 'foo/bar/qux/*', 'foo/bar/baz/quux']); * // returns 'foo/bar' * * findBasePath([]); * // returns '/' * ``` * * @param paths - The string or array of strings to find the base path from * @returns The base path */ declare function findBasePath(paths: string | string[]): string; //#endregion export { commonPath, findBasePath, findCommonPath }; //# sourceMappingURL=common.d.mts.map