2 exports
.encode
= encode
;
3 function encode(sections
) {
4 return sections
.map(function (section
) {
5 return section
.map(function (paragraph
) {
6 return paragraph
.map(function (line
) {
7 return line
.map(function (word
) {
8 return word
.map(function (column
) {
11 parts
.push(column
.above
);
13 parts
.push(column
.below
);
15 parts
.push(column
.following
);
16 if (column
.tildeAbove
)
17 parts
.push("tilde-above");
18 if (column
.tildeBelow
)
19 parts
.push("tilde-below");
21 return column
.tengwa
+ ":" + parts
.join(",");
32 exports
.decode
= decode
;
33 function decode(encoding
, makeColumn
) {
34 return encoding
.split("\n\n\n").map(function (section
) {
35 return section
.split("\n\n").map(function (paragraph
) {
36 return paragraph
.split("\n").map(function (line
) {
37 return line
.split(" ").map(function (word
) {
38 return decodeWord(word
, makeColumn
);
45 exports
.decodeWord
= decodeWord
;
46 function decodeWord(word
, makeColumn
) {
47 return word
.split(";").map(function (column
) {
48 var parts
= column
.split(":");
49 var tengwa
= parts
.shift();
50 var tehtar
= parts
.length
? parts
.shift().split(",") : [];
51 var result
= makeColumn(tengwa
);
52 tehtar
.forEach(function (tehta
) {
53 if (tehta
=== "tilde-above") {
54 result
.addTildeAbove();
55 } else if (tehta
=== "tilde-below") {
56 result
.addTildeBelow();
57 } else if (tehta
=== "y") {
61 tehta
=== "s-inverse" ||
62 tehta
=== "s-extended" ||
63 tehta
=== "s-flourish"
67 (tengwa
=== "calma" || tengwa
=== "quesse")
69 result
.addBelow(tehta
, "s");
71 result
.addFollowing(tehta
, "s");
74 result
.addAbove(tehta
, "s");