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`
This commit is contained in:
Oliver Joseph Ash
2017-11-10 15:37:12 +00:00
committed by Andy
parent 0a4418d0f5
commit a8e88654be
2 changed files with 34 additions and 1 deletions

26
types/node/index.d.ts vendored
View File

@@ -13,6 +13,7 @@
// Deividas Bakanas <https://github.com/DeividasBakanas>
// Kelvin Jin <https://github.com/kjin>
// Alvis HT Tang <https://github.com/alvis>
// Oliver Joseph Ash <https://github.com/OliverJAsh>
// 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;

View File

@@ -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'
}
////////////////////////////////////////////////////