Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Add path.parse, path.format #8750

Closed
wants to merge 6 commits into from

Conversation

chrisdickinson
Copy link

Continuing from #7429.

The feature was originally given the go-ahead by @isaacs.
@roryrjb opened a pr that stalled -- I'm reopening this, having fixed the style issues.

Tested on Win7 + OSX 10.10.

/cc @tjfontaine @indutny

path.parse

Returns an object from a path string.

An example on *nix:

path.parse('/home/user/dir/file.txt')
// returns
{
    root : "/",
    dir : "/home/user/dir",
    base : "file.txt",
    ext : ".txt",
    name : "file"
}

An example on Windows:

path.parse('C:\\path\\dir\\index.html')
// returns
{
    root : "C:\",
    dir : "C:\path\dir",
    base : "index.html",
    ext : ".html",
    name : "index"
}

path.format

Returns a path string from an object, the opposite of path.parse above.

path.format({
    root : "/",
    dir : "/home/user/dir",
    base : "file.txt",
    ext : ".txt",
    name : "file"
})
// returns
'/home/user/dir/file.txt'

@othiym23
Copy link

This is a very useful concept and I would use the heck out of it if it were in Node.

@tjfontaine
Copy link

From the irc conversation, I am +1 on this, and would like to see it rebased on top of https://github.com/misterdjules/node/compare/joyent:v0.12...path-platform?w=1 which reorders the path module to expose platform based semantics -- re #5661

tjfontaine and others added 3 commits November 19, 2014 17:02
Add path.posix and path.win32 which have the specific methods like
resolve and normalize so you can specifically normalize or resolve
based on the target platform.
The parse() function splits a path and returns an object
with the different elements. The format() function is the
reverse of this and adds an objects corresponding path
elements to make up a string. Fixes nodejs#6976.
chrisdickinson pushed a commit that referenced this pull request Nov 21, 2014
The parse() function splits a path and returns an object
with the different elements. The format() function is the
reverse of this and adds an objects corresponding path
elements to make up a string. Fixes #6976.

Fixes: #6976
PR-URL: #8750
Reviewed-by: Julien Gilli <julien.gilli@joyent.com>
@chrisdickinson
Copy link
Author

Merged in 2d17193.

kaiquewdev pushed a commit to kaiquewdev/node that referenced this pull request Nov 26, 2016
2d524bc

Original commit message:

  deps: limit regress/regress-crbug-514081 v8 test

  regress/regress-crbug-514081 allocates a 2G block of memory
  and if there  are multiple variants running at the
  same time this can lead to crashes, OOM kills or
  the OS failing to allocate memory.  This patch
  limits us to running a single variant of the test

  Fixes: nodejs/node#6340
  PR-URL: nodejs/node#6678
  Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  Reviewed-By: James M Snell <jasnell@gmail.com>
  Reviewed-By: Fedor Indutny <fedor@indutny.com>

PR-URL: nodejs/node#8907
Fixes: nodejs#8750
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants