pax_global_header00006660000000000000000000000064117262355150014521gustar00rootroot0000000000000052 comment=c003ff911aa24e7afabe83550d2aad7c5ee786ab node-archy-0.0.2/000077500000000000000000000000001172623551500135515ustar00rootroot00000000000000node-archy-0.0.2/.travis.yml000066400000000000000000000000531172623551500156600ustar00rootroot00000000000000language: node_js node_js: - 0.4 - 0.6 node-archy-0.0.2/README.markdown000066400000000000000000000032531172623551500162550ustar00rootroot00000000000000archy ===== Render nested hierarchies `npm ls` style with unicode pipes. [![build status](https://secure.travis-ci.org/substack/node-archy.png)](http://travis-ci.org/substack/node-archy) example ======= ``` js var archy = require('archy'); var s = archy({ label : 'beep', nodes : [ 'ity', { label : 'boop', nodes : [ { label : 'o_O', nodes : [ { label : 'oh', nodes : [ 'hello', 'puny' ] }, 'human' ] }, 'party\ntime!' ] } ] }); console.log(s); ``` output ``` beep ├── ity └─┬ boop ├─┬ o_O │ ├─┬ oh │ │ ├── hello │ │ └── puny │ └── human └── party time! ``` methods ======= var archy = require('archy') archy(obj, prefix='', opts={}) ------------------------------ Return a string representation of `obj` with unicode pipe characters like how `npm ls` looks. `obj` should be a tree of nested objects with `'label'` and `'nodes'` fields. `'label'` is a string of text to display at a node level and `'nodes'` is an array of the descendents of the current node. If a node is a string, that string will be used as the `'label'` and an empty array of `'nodes'` will be used. `prefix` gets prepended to all the lines and is used by the algorithm to recursively update. If `'label'` has newlines they will be indented at the present indentation level with the current prefix. To disable unicode results in favor of all-ansi output set `opts.unicode` to `false`. install ======= With [npm](http://npmjs.org) do: ``` npm install archy ``` license ======= MIT/X11 node-archy-0.0.2/examples/000077500000000000000000000000001172623551500153675ustar00rootroot00000000000000node-archy-0.0.2/examples/beep.js000066400000000000000000000006031172623551500166370ustar00rootroot00000000000000var archy = require('../'); var s = archy({ label : 'beep', nodes : [ 'ity', { label : 'boop', nodes : [ { label : 'o_O', nodes : [ { label : 'oh', nodes : [ 'hello', 'puny' ] }, 'human' ] }, 'party\ntime!' ] } ] }); console.log(s); node-archy-0.0.2/examples/multi_line.js000066400000000000000000000006361172623551500200730ustar00rootroot00000000000000var archy = require('../'); var s = archy({ label : 'beep\none\ntwo', nodes : [ 'ity', { label : 'boop', nodes : [ { label : 'o_O\nwheee', nodes : [ { label : 'oh', nodes : [ 'hello', 'puny\nmeat' ] }, 'creature' ] }, 'party\ntime!' ] } ] }); console.log(s); node-archy-0.0.2/index.js000066400000000000000000000021641172623551500152210ustar00rootroot00000000000000module.exports = function archy (obj, prefix, opts) { if (prefix === undefined) prefix = ''; if (!opts) opts = {}; var chr = function (s) { var chars = { '│' : '|', '└' : '`', '├' : '+', '─' : '-', '┬' : '-' }; return opts.unicode === false ? chars[s] : s; }; if (typeof obj === 'string') obj = { label : obj }; var nodes = obj.nodes || []; var lines = (obj.label || '').split('\n'); var splitter = '\n' + prefix + (nodes.length ? chr('│') : ' ') + ' '; return prefix + lines.join(splitter) + '\n' + nodes.map(function (node, ix) { var last = ix === nodes.length - 1; var more = node.nodes && node.nodes.length; var prefix_ = prefix + (last ? ' ' : chr('│')) + ' '; return prefix + (last ? chr('└') : chr('├')) + chr('─') + (more ? chr('┬') : chr('─')) + ' ' + archy(node, prefix_, opts).slice(prefix.length + 2) ; }).join('') ; }; node-archy-0.0.2/package.json000066400000000000000000000014441172623551500160420ustar00rootroot00000000000000{ "name" : "archy", "version" : "0.0.2", "description" : "render nested hierarchies `npm ls` style with unicode pipes", "main" : "index.js", "directories" : { "lib" : ".", "example" : "example", "test" : "test" }, "devDependencies" : { "tap" : "~0.2.3" }, "scripts" : { "test" : "tap test" }, "repository" : { "type" : "git", "url" : "http://github.com/substack/node-archy.git" }, "keywords" : [ "hierarchy", "npm ls", "unicode", "pretty", "print" ], "author" : { "name" : "James Halliday", "email" : "mail@substack.net", "url" : "http://substack.net" }, "license" : "MIT/X11", "engine" : { "node" : ">=0.4" } } node-archy-0.0.2/test/000077500000000000000000000000001172623551500145305ustar00rootroot00000000000000node-archy-0.0.2/test/beep.js000066400000000000000000000015061172623551500160030ustar00rootroot00000000000000var test = require('tap').test; var archy = require('../'); test('beep', function (t) { var s = archy({ label : 'beep', nodes : [ 'ity', { label : 'boop', nodes : [ { label : 'o_O', nodes : [ { label : 'oh', nodes : [ 'hello', 'puny' ] }, 'human' ] }, 'party!' ] } ] }); t.equal(s, [ 'beep', '├── ity', '└─┬ boop', ' ├─┬ o_O', ' │ ├─┬ oh', ' │ │ ├── hello', ' │ │ └── puny', ' │ └── human', ' └── party!', '' ].join('\n')); t.end(); }); node-archy-0.0.2/test/multi_line.js000066400000000000000000000017441172623551500172350ustar00rootroot00000000000000var test = require('tap').test; var archy = require('../'); test('multi-line', function (t) { var s = archy({ label : 'beep\none\ntwo', nodes : [ 'ity', { label : 'boop', nodes : [ { label : 'o_O\nwheee', nodes : [ { label : 'oh', nodes : [ 'hello', 'puny\nmeat' ] }, 'creature' ] }, 'party\ntime!' ] } ] }); t.equal(s, [ 'beep', '│ one', '│ two', '├── ity', '└─┬ boop', ' ├─┬ o_O', ' │ │ wheee', ' │ ├─┬ oh', ' │ │ ├── hello', ' │ │ └── puny', ' │ │ meat', ' │ └── creature', ' └── party', ' time!', '' ].join('\n')); t.end(); }); node-archy-0.0.2/test/non_unicode.js000066400000000000000000000014431172623551500173700ustar00rootroot00000000000000var test = require('tap').test; var archy = require('../'); test('beep', function (t) { var s = archy({ label : 'beep', nodes : [ 'ity', { label : 'boop', nodes : [ { label : 'o_O', nodes : [ { label : 'oh', nodes : [ 'hello', 'puny' ] }, 'human' ] }, 'party!' ] } ] }, '', { unicode : false }); t.equal(s, [ 'beep', '+-- ity', '`-- boop', ' +-- o_O', ' | +-- oh', ' | | +-- hello', ' | | `-- puny', ' | `-- human', ' `-- party!', '' ].join('\n')); t.end(); });