walk-up-path
Given a path string, return a generator that walks up the path, emitting each dirname.
Last updated 2 years ago by isaacs .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install walk-up-path 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 3.0.1                                ...           latest (2 years ago)

4 Versions

  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (9)

Copyright 2013 - present © cnpmjs.org | Home |