const words = ["a","akesi","ala","alasa","ale","anpa","ante","anu","awen","e","en","esun","ijo","ike","ilo","insa","jaki","jan","jelo","jo","kala","kalama","kama","kasi","ken","kepeken","kili","kiwen","ko","kon","kule","kulupu","kute","la","lape","laso","lawa","len","lete","li","lili","linja","lipu","loje","lon","luka","lukin","lupa","ma","mama","mani","meli","mi","mije","moku","moli","monsi","mu","mun","musi","mute","nanpa","nasa","nasin","nena","ni","nimi","noka","o","olin","ona","open","pakala","pali","palisa","pan","pana","pi","pilin","pimeja","pini","pipi","poka","poki","pona","pu","sama","seli","selo","seme","sewi","sijelo","sike","sin","sina","sinpin","sitelen","sona","soweli","suli","suno","supa","suwi","tan","taso","tawa","telo","tenpo","toki","tomo","tu","unpa","uta","utala","walo","wan","waso","wawa","weka","wile"];
const signs = ['ズブ', 'チツ'];
const coding_space = 'ニ';
const decoding_space = ' ';
function coder(text){
return coder_sentences(text);
}
function coder_one_sentence(text) {
const binaries = text.split(decoding_space).map(function (word) {
const binary = (words.indexOf(word)+1).toString(2);
return binary;
})
let codes = [];
for (let j = 0; j < binaries.length; j++) {
const elements =
binaries[j]
.split('')
.map((d)=>signs[
d=='1'?0:1
]);
codes.push(elements.join(''));
}
return codes.join(coding_space);
}
function coder_sentences(text){
return text.split(/\s*\.\s*/).map(str=>
str?coder_one_sentence(str):' '
).join(coding_space.repeat(2)).trim();
}
if(
typeof(process)!='undefined'&&
process.argv[2]
){
console.log(coder(process.argv[2]))
}
if(typeof(module)!='undefined'){
module.exports = {
coder,coder_one_sentence,coder_sentences,
words,
//signs, coding_space, decoding_space
};
}