-
Notifications
You must be signed in to change notification settings - Fork 0
/
loo.js
54 lines (54 loc) · 1.33 KB
/
loo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
exports.__esModule = true;
var fs_1 = require("fs");
var process_1 = require("process");
function execute(data) {
var currentCharacter = function (pos, source) {
if (source.length == pos) {
return null;
}
else {
return source[pos];
}
};
var position = 0;
var ascii = 0;
var character = currentCharacter(position, data);
while (character != null) {
if (character == '+') {
ascii += 1;
}
else if (character == '-') {
ascii -= 1;
}
else if (character == '#') {
process_1.stdout.write(String.fromCharCode(ascii));
}
else if (character == ';') {
return 0;
}
position += 1;
character = currentCharacter(position, data);
}
}
function content(args) {
if (args.length == 0) {
return null;
}
var filename = arguments[0][0];
try {
var exists = fs_1.existsSync(filename);
if (!fs_1.statSync(filename).isFile()) {
console.error(filename + " not a file");
}
}
catch (exception) {
console.error(exception.message);
}
var data = fs_1.readFileSync(filename).toString();
return data;
}
var data = content(process_1.argv.slice(2));
if (data) {
execute(data);
}