šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Book a DemoInstallSign in
Socket

directory-tree

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

directory-tree

Convert a directory tree to a JS object.

1.1.0
Source
npm
Version published
Weekly downloads
107K
-26.84%
Maintainers
1
Weekly downloads
Ā 
Created
Source

Build Status

#directory-tree

Creates an javascript object representing a directory tree.

Install

npm i -S directory-tree

##Usage

var dirTree = require('directory-tree');
var tree = dirTree('/some/path');

And you can also filter by extensions:

var dirTree = require('directory-tree');
var filteredTree = dirTree('/some/path', ['.jpg', '.png']);

This will take a directory tree:

photos
ā”œā”€ā”€ summer
│   └── june
│       └── windsurf.jpg
└── winter
    └── january
        ā”œā”€ā”€ ski.png
        └── snowboard.jpg

And return a js object:

{
  "path": "photos",
  "name": "photos",
  "size": 600,
  "children": [
    {
      "path": "photos/summer",
      "name": "summer",
      "size": 400,
      "children": [
        {
          "path": "photos/summer/june",
          "name": "june",
          "size": 400,
          "children": [
            {
              "path": "photos/summer/june/windsurf.jpg",
              "name": "windsurf.jpg",
              "size": 400,
              "extension": ".jpg"
            }
          ]
        }
      ]
    },
    {
      "path": "photos/winter",
      "name": "winter",
      "size": 200,
      "children": [
        {
          "path": "photos/winter/january",
          "name": "january",
          "size": 200,
          "children": [
            {
              "path": "photos/winter/january/ski.png",
              "name": "ski.png",
              "size": 100,
              "extension": ".png"
            },
            {
              "path": "photos/winter/january/snowboard.jpg",
              "name": "snowboard.jpg",
              "size": 100,
              "extension": ".jpg"
            }
          ]
        }
      ]
    }
  ]
}

Note

Device, FIFO and socket files are ignored.

Files to which the user does not have permissions are included in the directory tree, however, directories to which the user does not have permissions, along with all of its contained files, are completely ignored.

Dev

To run tests go the package root in your CLI and run,

$ npm test

Make sure you have the dev dependcies installed (e.g. npm install .)

Node version

Check out version 0.1.1 if you need support for older versions of node.

Keywords

directory

FAQs

Package last updated on 11 Aug 2016

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