diff --git a/doc/api/path.md b/doc/api/path.md index 0bbb5b80c57ef3..dc2801e7cc3a88 100644 --- a/doc/api/path.md +++ b/doc/api/path.md @@ -267,6 +267,38 @@ path.format({ // Returns: 'C:\\path\\dir\\file.txt' ``` +## `path.fromURL(pathOrUrl)` + + + +* `pathOrUrl` {string|URL}. +* Returns: {string} + +Converts a [`URL`][] instance to a path string, +returns `pathOrUrl` if it is already a string. + +A [`TypeError`][] is thrown if `pathOrUrl` is a +[`URL`][] with a schema other than `file://`. + +```js +path.fromURL(new URL('file:///Users/node/dev')); +// Returns: '/Users/node/dev' + +path.fromURL('file:///Users/node/dev'); +// Returns: 'file:///Users/node/dev' + +path.fromURL(new URL('file:///c:/foo.txt')); +// Returns On Windows: 'c:\\foo.txt' + +path.fromURL('index/path'); +// Returns: 'index/path' + +path.fromURL(new URL('http://example.com')); +// Throws 'TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file' +``` + ## `path.isAbsolute(path)`