New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

directory-tree-promise

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

directory-tree-promise

Asynchronously return a directory tree as a JS object

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

##directory-tree-promise

Install

  npm install directory-tree-promise

Usage

Use async await while traversing a directory tree.

  const {directoryTree} = require('../lib/directory-tree')
  const tree = directoryTree('./example')

Output of tree:

{
  "path": "./example",
  "name": "example",
  "children": [
    {
      "path": "example/subfolder",
      "name": "subfolder",
      "children": [
        // excluded
      ],
      "size": 22
    },
    {
      // excluded
    }
  ],
  "size": 34
}

You can also pass an async function as a second parameter to modify the object returned for files

  const {directoryTree} = require('../lib/directory-tree')
  const tree = directoryTree('./example', async file => {
    file.content = await someFunctionToReadFileData(file.path)
    return file
  })

Object Property Reference

Items are returned with the following properties:

  • path (path to item)
  • name (name of file including extension)
  • extension (extension of object if isFile())
  • size (file or folder size in bytes)
  • children (array of items)

API Reference

isFile() -> bool

Each object in the tree is extended with a function isFile

  const {directoryTree} = require('../lib/directory-tree')
  const tree = directoryTree(process.cwd())
  tree.children[0].isFile() // true or false

Note

Device, FIFO and socket files are ignored.

Contributing

Fork this repository and run npm install in project directory.

Tests

npm run test

Keywords

FAQs

Package last updated on 11 Mar 2017

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