Skip to content

Commit 25d4cbd

Browse files
committed
export more object in index
1 parent 477a76a commit 25d4cbd

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

index.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
var TreeLine = require('./lib/tree-line');
22
var AsciiTree = require('./lib/ascii-tree');
3+
var AsciiTreeBuilder = require('./lib/asciitree-builder');
4+
var ConvertorBuilder = require('./lib/convertor-builder');
35
var Convertor = require('./lib/convertor');
46
var LineUtil = require('./lib/line-util');
7+
var BytesLine = require('./lib/bytes-line');
58
var Char = require('./lib/char');
69

710
module.exports.TreeLine = TreeLine;
811
module.exports.AsciiTree = AsciiTree;
912
module.exports.Convertor = Convertor;
1013
module.exports.LineUtil = LineUtil;
14+
module.exports.BytesLine = BytesLine;
15+
module.exports.AsciiTreeBuilder = AsciiTreeBuilder;
16+
module.exports.ConvertorBuilder = ConvertorBuilder;
1117
module.exports.Char = Char;

lib/ascii-tree.js

+18-14
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,24 @@ function AsciiTree(lines, leadingCharCode, enc) {
1616
this.topLine = null;
1717
this.enc = enc;
1818
}
19+
/**
20+
* @function toBufferLines
21+
* @return {Buffer[]} - converted Buffers.
22+
*/
23+
AsciiTree.prototype.toBufferArray = function() {
24+
var enc = this.enc;
25+
return this.toBytesLineArray().map(function(it) {
26+
return it.toBuffer();
27+
});
28+
};
1929
/**
2030
* @function toStringLines
2131
* @return {string[]} - converted lines.
2232
*/
23-
AsciiTree.prototype.toStringLines = function() {
33+
AsciiTree.prototype.toStringArray = function() {
2434
var enc = this.enc;
25-
return this.toBytesLines().map(function(it) {
26-
return enc ? it.toBuffer().toString(enc) : it.toBuffer().toString();
35+
return this.toBufferArray().map(function(it) {
36+
return enc ? it.toString(enc) : it.toString();
2737
});
2838
};
2939

@@ -32,22 +42,16 @@ AsciiTree.prototype.toStringLines = function() {
3242
* @return {string} - converted string.
3343
*/
3444
AsciiTree.prototype.toString = function() {
35-
var enc = this.enc,
36-
bytesArray,
37-
buf;
38-
39-
bytesArray = this.toBytesLines().reduce(function(val, it) {
40-
return val.concat(it.content, it.separator);
41-
}, []);
42-
buf = new Buffer(bytesArray);
43-
return enc ? buf.toString(enc) : buf.toString();
45+
return this.toStringArray().reduce(function(val, it) {
46+
return val + it;
47+
}, "");
4448
};
4549

4650
/**
47-
* @function toBytesLines
51+
* @function toBytesLineArray
4852
* @return {BytesLine[]} - return array of BytesLine.
4953
*/
50-
AsciiTree.prototype.toBytesLines = function() {
54+
AsciiTree.prototype.toBytesLineArray = function() {
5155
return this.topLine.toLines();
5256
};
5357

lib/convertor.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var BytesLine = require('./bytes-line');
22
var AsciiTree = require('./ascii-tree');
3+
var os = require('os');
34

45
module.exports = Convertor;
56

@@ -58,7 +59,7 @@ Convertor.prototype.convert = function() {
5859
if (this.prepend) {
5960
this.mixedLines.push(this.prepend);
6061
}
61-
this.mixedLines.push(new AsciiTree(lineArray).convert().toBytesLines());
62+
this.mixedLines.push(new AsciiTree(lineArray).convert().toBytesLineArray());
6263
if (this.append) {
6364
this.mixedLines.push(this.append);
6465
}

lib/tree-stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function TreeStream() {
1010
if (BytesLine.isBytesLine(bytesLines)) {
1111
this.push(bytesLines);
1212
} else {
13-
new AsciiTree(bytesLines,null, enc).convert().toBytesLines().forEach(function(it) {
13+
new AsciiTree(bytesLines,null, enc).convert().toBytesLineArray().forEach(function(it) {
1414
this.push(it);
1515
}, this);
1616
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "my-ascii-tree",
3-
"version": "1.0.8",
3+
"version": "1.0.11",
44
"description": "convert indented line block to an ascii directory tree",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "git+https://github.com/jianglibo/dtree-converter.git"
11+
"url": "git+https://github.com/jianglibo/ascii-tree.git"
1212
},
1313
"keywords": [
1414
"ascii",

test/ascii-tree.js

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var assert = require('assert');
44
var BytesLine = require('../lib/bytes-line');
55
var AsciiTree = require('../lib/ascii-tree');
66
var LineUtil = require('../lib/line-util');
7+
var os = require('os');
78

89
describe('AsciiTree', function() {
910
describe('#constructor', function() {
@@ -12,5 +13,10 @@ describe('AsciiTree', function() {
1213
assert.equal(null, tree.leadingCharCode);
1314
assert.equal("└── hello", tree.toString());
1415
});
16+
17+
it('should handle eol', function() {
18+
var eol = os.EOL;
19+
assert.equal('string', typeof eol);
20+
});
1521
});
1622
});

test/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ var assert = require('assert');
22
var AsciiTree = require('../index').AsciiTree;
33
var Convertor = require('../index').Convertor;
44
var TreeLine = require('../index').TreeLine;
5+
var BytesLine = require('../index').BytesLine;
56
var LineUtil = require('../index').LineUtil;
7+
var AsciiTreeBuilder = require('../index').AsciiTreeBuilder;
8+
var ConvertorBuilder = require('../index').ConvertorBuilder;
69
var Char = require('../index').Char;
710

811

@@ -14,6 +17,9 @@ describe('required', function() {
1417
assert(TreeLine, "Line should imported.");
1518
assert(LineUtil, "LineUtil should imported.");
1619
assert(Char, "Char should imported.");
20+
assert(BytesLine, "BytesLine should imported.");
21+
assert(AsciiTreeBuilder, "AsciiTreeBuilder should imported.");
22+
assert(ConvertorBuilder, "ConvertorBuilder should imported.");
1723
});
1824
});
1925
});

0 commit comments

Comments
 (0)