JSPM

walk-up-path

4.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7401887
  • Score
    100M100P100Q220389F
  • License ISC

Given a path string, return a generator that walks up the path, emitting each dirname.

Package Exports

  • walk-up-path
  • walk-up-path/package.json

Readme

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.