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

@universal-packages/directory-traversal

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@universal-packages/directory-traversal

Simple tool to traverse a directory deeply and get desired info

  • 1.3.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Directory Traversal

npm version Testing codecov

Sometimes you just need a way to map a directory to either load modules in real time or just get the available files to run a task, directory traversal will map a directory for you and deliver a convenient DirectoryMap object for you.

Install

npm install @universal-packages/directory-traversal

Global methods

traverse(locations: String, [options])

The traverse function will go recursively from a root directory until it maps the whole tree, you can execute a callback for every visited directory after being mapped, limit the depth and filter for files you want or you not want to be mapped, returning a DirectoryMap object

import { traverse } from '@universal-packages/directory-traversal'

const directoryMap = traverse('~/projects')

console.log(directoryMap)

Options

You can modify the behavior of the traverse function by providing options.

  • callback Function A function to call for every mapped directory for you to analyze in place, return false if you want to stop going deeper into that directory.

    const directoryMap = traverse('~/projects', {
      callback: (directoryMap) => {
        if (directoryMap.path.include('homework')) {
          return false
        }
      }
    })
    
  • fileFilter (yml | yaml | js | json)[] | Regex To only include files that satisfies this condition.

  • maxDepth Number To only map files going this level deep.

DirectoryMap

From the traverse example you will get something like this:

{
  "path": "home/projects",
  "files": [],
  "directories": [
    {
      "path": "home/projects/universal-directory-traversal",
      "files": [
        "home/projects/universal-directory-traversal/.editorconfig",
        "home/projects/universal-directory-traversal/.gitignore",
        "home/projects/universal-directory-traversal/CODE-OF-CONDUCT.md",
        "home/projects/universal-directory-traversal/CONTRIBUTING.md",
        "home/projects/universal-directory-traversal/LICENSE.md",
        "home/projects/universal-directory-traversal/README.md",
        "home/projects/universal-directory-traversal/package-lock.json",
        "home/projects/universal-directory-traversal/package.json",
        "home/projects/universal-directory-traversal/tsconfig.dis.json",
        "home/projects/universal-directory-traversal/tsconfig.json"
      ],
      "directories": []
    }
  ]
}

Typescript

This library is developed in TypeScript and shipped fully typed.

Contributing

The development of this library happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving this library.

License

MIT licensed.

FAQs

Package last updated on 20 Mar 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