Socket
Socket
Sign inDemoInstall

walk-up-path

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

walk-up-path

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


Version published
Maintainers
1
Weekly downloads
2,210,123
decreased by-6.68%

Weekly downloads

Readme

Source

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.

FAQs

Last updated on 10 Apr 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc