Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

walk-up-path

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

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.

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7M
increased by3.02%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 08 Jul 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc