1.0.0 • Published 11 years ago

hierarchy v1.0.0

Weekly downloads
3
License
-
Repository
-
Last release
11 years ago

hierarchy

Convert JSON object to a beautiful string representation of a directory structure

Like archy, but easier. Inspired in the text-tree found in an answer on StackOverflow.

Installation

npm i --save hierarchyjs

Usage

Considering the input.json file:

{
    "foo": {
        "bar": {
            "$files": ["baz.js", "piece.js"]
        },
        "paz": {}
    },
    "baz": {
        "$files": ["taz.js"]
    },
    "$files": ["Gruntfile.js", "package.json"]
}

From the command line

hierarchy input.json

In code

var hierarchy = require('hierarchy');
var input = require('input.json');
var tree = hierarchy(input);

console.log(tree);

Notation

The input is expected to be a tree-like object with optional $files arrays that describe a list of files in a directory. The $files construct can actually be avoided by treating files as empty directories, but its a little convenience sugar.

The following has the exact same output as the previous example.

{
    "foo": {
        "bar": {
            "$files": {
                "baz.js": {},
                "piece.js": {}
            },
        },
        "paz": {}
    },
    "baz": {
        "taz.js": {}
    },
    "Gruntfile.js": {},
    "package.json": {}
}

A file named $etc might be used to include a "and more.." '....' kind of message.

License

MIT

1.0.0

11 years ago