From a8e88654bebb21649d1b45e708a13ebf3b44157c Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Fri, 10 Nov 2017 15:37:12 +0000 Subject: [PATCH] Node: `path.format` input properties are optional (#21003) * Node: `path.format` input properties are optional If `base` does not exist, `name` and `ext` will be used to compute it. http://devdocs.io/node/path#path_path_format_pathobject * Node: `FormatInputPathObject`: all properties are optional * Node: add myself as author * Avoid usage of `Partial` --- types/node/index.d.ts | 26 +++++++++++++++++++++++++- types/node/node-tests.ts | 9 +++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) 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' } ////////////////////////////////////////////////////