Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/file-tree
Generate a tree of file metadata that matches d3's hierarchy layout format
https://github.com/hughsk/file-tree
Last synced: 12 days ago
JSON representation
Generate a tree of file metadata that matches d3's hierarchy layout format
- Host: GitHub
- URL: https://github.com/hughsk/file-tree
- Owner: hughsk
- License: other
- Created: 2013-08-10T00:03:35.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-10-09T15:30:15.000Z (about 9 years ago)
- Last Synced: 2024-10-17T16:41:14.596Z (22 days ago)
- Language: JavaScript
- Size: 151 KB
- Stars: 11
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# file-tree #
A more flexible, asynchronous version of
[file-size-tree](http://github.com/hughsk/file-size-tree).## Installation ##
``` bash
npm install file-tree
```## Usage ##
### `require('file-tree')(files, mapper, callback)` ###
Takes an array of `files`.
`mapper(filename, next)` should pass an object to the the callback
with the metadata you want to associate with the file.`callback(err, tree)` is called when everything's done.
``` javascript
var tree = require('file-tree')
var fs = require('fs')tree([
__dirname + '/project/src/index.js'
, __dirname + '/project/src/README.md'
, __dirname + '/project/src/package.json'
, __dirname + '/LICENSE'
], function(filename, next) {
fs.stat(filename, function(err, stats) {
if (err) return next(err)
next(null, {
size: stats.size
})
})
}, function(err, fileTree) {
console.log(fileTree) // done!
})
```