mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 03:29:46 +00:00
![]() PR-URL: https://github.com/nodejs/node/pull/35474 Reviewed-By: Ruy Adorno <ruyadorno@github.com> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> |
||
---|---|---|
.. | ||
index.js | ||
LICENSE | ||
package.json | ||
README.md |
walk-up-path
Given a path string, return a generator that walks up the path, emitting each dirname.
So, to get a platform-portable walk up, instead of doing something like this:
for (let p = dirname(path); p;) {
// ... do stuff ...
const pp = dirname(p)
if (p === pp)
p = null
else
p = pp
}
Or this:
for (let p = dirname(path); !isRoot(p); p = dirname(p)) {
// ... do stuff ...
}
You can do this:
const walkUpPath = require('walk-up-path')
for (const p of walkUpPath(path)) {
// ... do stuff ..
}
API
const walkUpPath = require('walk-up-path')
Give the fn a string, it'll yield all the directories walking up to the root.