Skip to content

Commit 1d4626c

Browse files
committed
Implement text output example in JavaScript.
1 parent c78b8b7 commit 1d4626c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

js/cat-run.cmd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node cat.js < ..\Test.json

js/cat.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var assert = require('assert');
2+
3+
process.stdin.setEncoding('utf8');
4+
process.stdout.setEncoding('utf8');
5+
6+
var input = '';
7+
8+
process.stdin.on('data', function(data) { input += data; });
9+
process.stdin.on('end', function() { handleInput(); });
10+
process.stdin.resume();
11+
12+
function handleInput() {
13+
var root = JSON.parse(input);
14+
assert.equal(root.shift(), 'text');
15+
16+
root.forEach(function(block) {
17+
var blockType = block.shift();
18+
var blockAttr = block.shift();
19+
20+
block.forEach(function(span) {
21+
var spanType = span.shift();
22+
assert(span.length, 1);
23+
var text = span[0];
24+
process.stdout.write(text);
25+
});
26+
27+
process.stdout.write('\n\n');
28+
});
29+
};

0 commit comments

Comments
 (0)