Permalink
Browse files

non-unicode test passes

  • Loading branch information...
substack committed Mar 8, 2012
1 parent e5e932a commit ec16907a5cb7db00799bc2fda787e9627bde12bc
Showing with 19 additions and 6 deletions.
  1. +19 −6 index.js
View
@@ -1,21 +1,34 @@
-module.exports = function archy (obj, prefix) {
+module.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 ? '' : ' ') + ' ';
+ 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 ? ' ' : '') + ' ';
+ var prefix_ = prefix + (last ? ' ' : chr('')) + ' ';
return prefix
- + (last ? '' : '') + ''
- + (more ? '' : '') + ' '
- + archy(node, prefix_).slice(prefix.length + 2)
+ + (last ? chr('') : chr('')) + chr('')
+ + (more ? chr('') : chr('')) + ' '
+ + archy(node, prefix_, opts).slice(prefix.length + 2)
;
}).join('')
;

0 comments on commit ec16907

Please sign in to comment.