-
Notifications
You must be signed in to change notification settings - Fork 9
/
notation.js
85 lines (81 loc) · 3 KB
/
notation.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"use strict";
exports.encode = encode;
function encode(sections) {
return sections.map(function (section) {
return section.map(function (paragraph) {
return paragraph.map(function (line) {
return line.map(function (word) {
return word.map(function (column) {
var parts = [];
if (column.above)
parts.push(column.above);
if (column.below)
parts.push(column.below);
if (column.following)
parts.push(column.following);
if (column.tildeAbove)
parts.push("tilde-above");
if (column.tildeBelow)
parts.push("tilde-below");
if (parts.length) {
return column.tengwa + ":" + parts.join(",");
} else {
return column.tengwa;
}
}).join(";");
}).join(" ");;
}).join("\n");
}).join("\n\n");
}).join("\n\n\n");
}
exports.decode = decode;
function decode(encoding, makeColumn) {
return encoding.split("\n\n\n").map(function (section) {
return section.split("\n\n").map(function (paragraph) {
return paragraph.split("\n").map(function (line) {
return line.split(" ").map(function (word) {
return decodeWord(word, makeColumn);
});
});
});
});
}
exports.decodeWord = decodeWord;
function decodeWord(word, makeColumn) {
return word.split(";").map(function (column) {
var parts = column.split(":");
var tengwa = parts.shift();
var tehtar = parts.length ? parts.shift().split(",") : [];
var result = makeColumn(tengwa);
tehtar.forEach(function (tehta) {
if (tehta === "tilde-above") {
result.addTildeAbove();
} else if (tehta === "tilde-below") {
result.addTildeBelow();
} else if (tehta === "y-quenya") {
result.addBelow("y-quenya");
} else if (tehta === "y-sindarin") {
result.addAbove("y-sindarin");
} else if (tehta === "y-english") {
result.addAbove("y-english");
} else if (
tehta === "s" ||
tehta === "s-inverse" ||
tehta === "s-extended" ||
tehta === "s-flourish"
) {
if (
tehta === "s" &&
(tengwa === "calma" || tengwa === "quesse")
) {
result.addBelow(tehta, "s");
} else {
result.addFollowing(tehta, "s");
}
} else {
result.addAbove(tehta, "s");
}
});
return result;
});
}