@stryke/path
Version:
A package containing various utilities that expand the functionality of NodeJs's built-in `path` module
56 lines • 2.01 kB
text/typescript
//#region src/append.d.ts
interface AppendPathOptions {
/**
* If `true`, the function will skip appending if the `childPath` is already a child of the `parentPath`.
*
* @defaultValue true
*/
skipIfAlreadyParent?: boolean;
}
/**
* If not already a parent path, append the base path from the beginning of the given child path.
*
* @example
* ```ts
* appendPath("src/index.ts", "/home/user/project");
* // returns "/home/user/project/src/index.ts"
*
* appendPath("/user/dev/app.ts", "/user/dev");
* // returns "/user/dev/app.ts"
*
* appendPath("docs/readme.md");
* // returns "<current_working_directory>/docs/readme.md"
*
* appendPath("src/index.ts", "/home/user/project", { skipIfAlreadyParent: false });
* // returns "/home/user/project/src/index.ts"
*
* appendPath("/home/user/project/src/index.ts", "/home/user/project", { skipIfAlreadyParent: false });
* // returns "/home/user/project/src/index.ts"
* ```
*
* @param childPath - The child path to append to the {@link parentPath}
* @param parentPath - The parent path to add the {@link childPath} to
* @param options - Options for appending the path
* @returns The {@link parentPath} with the {@link childPath} appended
*/
declare function appendPath(childPath: string, parentPath?: string, options?: AppendPathOptions): string;
declare const append: typeof appendPath;
/**
* Append the extension to the given path.
*
* @example
* ```ts
* appendExtension("/home/user/project/src/index", ".ts");
* // returns "/home/user/project/src/index.ts"
* appendExtension("/home/user/project/src/index.ts", ".js");
* // returns "/home/user/project/src/index.ts.js"
* ```
*
* @param path - The path to append the extension to.
* @param extension - The extension to append.
* @returns The path with the appended extension.
*/
declare function appendExtension(path: string, extension: string): string;
//#endregion
export { AppendPathOptions, append, appendExtension, appendPath };
//# sourceMappingURL=append.d.mts.map