file-size-tree

Take a list of file paths in Node, and get back an object matching d3's hierarchy layout format

npm install file-size-tree
74 downloads in the last week
1 710 downloads in the last month

file-size-tree unstable

Take a list of file paths in Node, and get back an object matching d3's hierarchy layout format. Great for making easy treemaps and the like.

Installation

npm install file-size-tree

Usage

require('file-size-tree')(files)

Takes an array of filenames and returns an object in d3's hierarchy layout format. For example, this:

var fileTree = require('file-size-tree')

fileTree([
    __dirname + '/project/src/index.js'
  , __dirname + '/project/src/README.md'
  , __dirname + '/project/src/package.json'
  , __dirname + '/LICENSE'
])

Should result in this:

[{
 "name": "project",
 "children": [
  {
   "name": "src",
   "children": [
    {"name": "index.js", "size": 3938},
    {"name": "README.md", "size": 3812},
    {"name": "package.json", "size": 743}
   ]
  }
 ]
}, {
 "name": "LICENSE",
 "size": 526
}]
npm loves you