1.0.15 • Published 9 years ago

my-ascii-tree v1.0.15

Weekly downloads
1
License
ISC
Repository
github
Last release
9 years ago

Ascii Tree

convert indented line block to an ascii directory tree.中文

API

sync

convert one tree.

  var tree = new AsciiTree(BytesLine.getArray("hello")).convert();
  assert.equal("└── hello", tree.toString());
  // or use builder helper.
  var tree = new AsciiTreeBuilder().withContent("hello").withEncode("UTF-8").build().convert();
  assert.equal("└── hello", tree.toString());

  tree.toBufferArray();
  tree.toStringArray();
  tree.toString();

convert mutilple blocks in a file. block is surround by startTag and endTag, which can be a string or a regex. prepend will be the first line of block result, append will be last line or result.

{% asciitree %}
app
-main.js
-helper.js
-others
--Brocfile.js
package.json
{% endasciitree %}
  var convertor = new Convertor(string, /^{%\s+asciitree\s+%}$/, "{% endasciitree %}", '<pre>', '</pre>').convert();
  //or use builder helper.

  var convertorBuilder = new ConvertorBuilder()
    .withContent(string)
    .withStartTag("{% asciitree %}")
    .withEndTag("{% endasciitree %}")
    .withPrepend("<pre>")
    .withAppend("</pre>");

  var convertor = convertorBuilder.build().convert();
  convertor.toStringArray();
  convertor.toBufferArray();
  convertor.toString();

results:

<pre>
├── app
|   ├── main.js
|   ├── helper.js
|   └── others
|       └── Brocfile.js
└── package.json
</pre>

in:

app
-main.js
-helper.js
-others
--Brocfile.js
package.json

out:

├── app
|   ├── main.js
|   ├── helper.js
|   └── others
|       └── Brocfile.js
└── package.json

stream

  var src = fs.createReadStream('fixtures/tagfile.txt');
  var dst = fs.createWriteStream('file.txt');
  src.pipe(splitterStream()) //to BytesLine
    .pipe(blockStream("{% asciitree %}", "{% endasciitree %}")) //produce one line or block of lines.
    .pipe(treeStream()) // bypass oneline, process block of lines.
    .pipe(unwrapStream()) // flatten block lines to Buffer.
    .pipe(dst);

  //or define a function
  function treepipe(src) {
   return src.pipe(splitterStream()) //to BytesLine
    .pipe(blockStream("{% asciitree %}", "{% endasciitree %}")) //produce one line or block of lines.
    .pipe(treeStream()) // bypass oneline, process block of lines.
    .pipe(unwrapStream()); // flatten block lines to Buffer.
  }

  treepipe(src).pipe(dst);
1.0.15

9 years ago

1.0.14

9 years ago

1.0.13

9 years ago

1.0.12

9 years ago

1.0.11

9 years ago

1.1.0

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago