diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 6d65f5999e..188e1315d6 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -13,6 +13,7 @@ // Deividas Bakanas // Kelvin Jin // Alvis HT Tang +// Oliver Joseph Ash // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /************************************************ @@ -4426,6 +4427,29 @@ declare module "path" { name: string; } + export interface FormatInputPathObject { + /** + * The root of the path such as '/' or 'c:\' + */ + root?: string; + /** + * The full directory path such as '/home/user/dir' or 'c:\path\dir' + */ + dir?: string; + /** + * The file name including extension (if any) such as 'index.html' + */ + base?: string; + /** + * The file extension (if any) such as '.html' + */ + ext?: string; + /** + * The file name without extension (if any) such as 'index' + */ + name?: string; + } + /** * Normalize a string path, reducing '..' and '.' parts. * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. @@ -4504,7 +4528,7 @@ declare module "path" { * * @param pathString path to evaluate. */ - export function format(pathObject: ParsedPath): string; + export function format(pathObject: FormatInputPathObject): string; export module posix { export function normalize(p: string): string; diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index d33dee0c93..315ec48d2f 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -1651,6 +1651,15 @@ namespace path_tests { }); // returns // '/home/user/dir/file.txt' + + path.format({ + root: "/", + dir: "/home/user/dir", + ext: ".txt", + name: "file" + }); + // returns + // '/home/user/dir/file.txt' } ////////////////////////////////////////////////////