Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: explain path.format() algorithm #5688

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion doc/api/path.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,22 @@ path.extname('.index')

## path.format(pathObject)

Returns a path string from an object, the opposite of [`path.parse`][].
Returns a path string from an object. This is the opposite of [`path.parse`][].

If `pathObject` has all expected properties, the returned string will be a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to expand on this just a bit to say what all the expected properties are up front.

concatenation of the `dir` property, the platform-dependent path separator, and
the `base` property.

If the `dir` property is not supplied, the `root` property will be used as the
`dir` property. However, it will be assumed that the `root` property already
ends with the platform-dependent path separator. In this case, the returned
string will be the concatenation fo the `root` property and the `base` property.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples of each of these cases would be helpful

If both the `dir` and the `root` properties are not supplied, then the returned
string will be the contents of the `base` property.

If the `base` property is not supplied, a concatenation of the `name` property
and the `ext` property will be used as the `base` property.

```js
path.format({
Expand Down