Skip to content

Commit 19f6462

Browse files
AimeTPGMozdemirburak
authored andcommitted
Added Thai alphabets (#2)
Added Thai morse code
1 parent 71b37ee commit 19f6462

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Set the priority option according to the list below.
6969
- 9 => Persian
7070
- 10 => Japanese
7171
- 11 => Korean
72+
- 12 => Thai
7273

7374
```js
7475
var cyrillic = morsify.encode('Ленинград', { priority: 5 }) // .-.././-./../-./--./.-./.-/-..

dist/morsify.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/morsify.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,40 @@
8787
'ㅅ': '110', 'ㅇ': '101', 'ㅈ': '0110', 'ㅊ': '1010', 'ㅋ': '1001', 'ㅌ': '1100',
8888
'ㅍ': '111', 'ㅎ': '0111', 'ㅏ': '0', 'ㅑ': '00', 'ㅓ': '1', 'ㅕ': '000',
8989
'ㅗ': '01', 'ㅛ': '10', 'ㅜ': '0000', 'ㅠ': '010', 'ㅡ': '100', 'ㅣ': '001'
90+
},
91+
'12' : { // Thai Alphabet => https://th.wikipedia.org/wiki/รหัสมอร์ส
92+
// characters
93+
'ก': '110',
94+
'ข': '1010', // 'ฃ': '1010', => duplicated with ข
95+
'ค': '101', // 'ฅ': '101', 'ฆ': '101', => duplicated with ค
96+
'ง': '10110',
97+
'จ': '10010', 'ฉ': '1111', 'ช': '1001', 'ซ': '1100', 'ญ': '0111',
98+
'ด': '100', //'ฎ': '100', => duplicated with ด
99+
'ต': '1', //'ฏ': '1', => duplicated with ต
100+
'ถ': '10100', //'ฐ': '10100', => duplicated with ถ
101+
'ท': '10011', //'ธ': '10011', 'ฑ': '10011', 'ฒ': '10011', => duplicated with ท
102+
'น': '10', //'ณ': '10', => duplicated with ณ
103+
'บ': '1000', 'ป': '0110', 'ผ':'1101', 'ฝ': '10101',
104+
'พ': '01100', //'ภ': '01100', => duplicated with พ
105+
'ฟ': '0010', 'ม': '11', 'ย': '1011', 'ร': '010',
106+
'ล': '0100', //'ฬ': '0100', => duplicated with ล
107+
'ว': '011',
108+
'ส': '000', // 'ษ': '000', 'ศ': '000', => duplicated with ส
109+
'ห': '0000', 'อ': '10001', 'ฮ': '11011',
110+
'ฤ': '01011', //'ฤๅ': '01011', => duplicated with ฤ
111+
112+
// vowels
113+
'ะ': '01000', 'า': '01', 'ิ': '00100', 'ี': '00', 'ึ': '00110', 'ื': '0011', 'ุ': '00101', 'ู': '1110',
114+
'เ': '0', 'แ': '0101',
115+
'ไ': '01001', //'ใ': '01001', => duplicated with ไ
116+
'โ': '111', 'ำ': '00010',
117+
118+
// tone marks
119+
'่': '001', '้': '0001', '๊': '11000', '๋':'01010',
120+
121+
// special marks
122+
'ั': '01101', '็': '11100', '์': '11001', 'ๆ': '10111',
123+
'ฯ': '11010', // 'ฯลฯ': '11101' => conflicts with ฯ
90124
}
91125
};
92126

test/morsify.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,60 @@ describe('morsify', function () {
158158
t.equal(morsify.decode('---/.---/./../-/...', options), 'ㅍ ㅎ ㅏ ㅑ ㅓ ㅕ');
159159
t.equal(morsify.decode('.-/-./..../.-./-../..-', options), 'ㅗ ㅛ ㅜ ㅠ ㅡ ㅣ');
160160
});
161+
it('encodes thai alphabet', function () {
162+
var options = { priority: 11 };
163+
t.equal(morsify.encode('กขคง', options), '--./-.-./-.-/-.--.');
164+
t.equal(morsify.encode('จฉชซญด', options), '-..-./----/-..-/--../.---/-..');
165+
t.equal(morsify.encode('ตถทนบ', options), '-/-.-../-..--/-./-...');
166+
t.equal(morsify.encode('ปผฝพฟ', options), '.--./--.-/-.-.-/.--../..-.');
167+
t.equal(morsify.encode('มยรลว', options), '--/-.--/.-./.-../.--');
168+
t.equal(morsify.encode('สหอฮฤ', options), '.../..../-...-/--.--/.-.--');
169+
t.equal(morsify.encode('ะาิีึืุูเแไโำ', options), '.-.../.-/..-../../..--./..--/..-.-/---././.-.-/.-..-/---/...-.');
170+
t.equal(morsify.encode('่้๊๋', options), '..-/...-/--.../.-.-.');
171+
t.equal(morsify.encode('ั็์ๆฯ', options), '.--.-/---../--..-/-.---/--.-.');
172+
173+
/* full test
174+
** this test can be used after figure out how to deal with Thai alphabeth duplications and conflicts
175+
176+
t.equal(morsify.encode('กขฃคฅฆง', options), '--./-.-./-.-./-.-/-.-/-.-/-.--.');
177+
t.equal(morsify.encode('จฉชซญดฎ', options), '-..-./----/-..-/--../.---/-../-..');
178+
t.equal(morsify.encode('ตฏถฐทธฑฒนณบ', options), '-/-/-.-../-.-../-..--/-..--/-..--/-..--/-./-./-...');
179+
t.equal(morsify.encode('ปผฝพภฟ', options), '.--./--.-/-.-.-/.--../.--../..-.');
180+
t.equal(morsify.encode('มยรลฬว', options), '--/-.--/.-./.-../.-../.--');
181+
t.equal(morsify.encode('ศษสหอฮฤฤๅ', options), '.../.../.../..../-...-/--.--/.-.--/.-.--');
182+
t.equal(morsify.encode('ะาิีึืุูเแไใโำ', options), '.-.../.-/..-../../..--./..--/..-.-/---././.-.-/.-..-/.-..-/---/...-.');
183+
t.equal(morsify.encode('่้๊๋', options), '..-/...-/--.../.-.-.');
184+
t.equal(morsify.encode('ั็์ๆฯฯลฯ', options), '.--.-/---../--..-/-.---/--.-./---.-');
185+
186+
*/
187+
});
188+
it('decodes thai alphabet', function () {
189+
var options = { priority: 12 };
190+
t.equal(morsify.decode('--./-.-./-.-/-.--.', options), 'ก ข ค ง');
191+
t.equal(morsify.decode('-..-./----/-..-/--../.---/-..', options), 'จ ฉ ช ซ ญ ด');
192+
t.equal(morsify.decode('-/-.-../-..--/-./-...', options), 'ต ถ ท น บ');
193+
t.equal(morsify.decode('.--./--.-/-.-.-/.--../..-.', options), 'ป ผ ฝ พ ฟ');
194+
t.equal(morsify.decode('--/-.--/.-./.-../.--', options), 'ม ย ร ล ว');
195+
t.equal(morsify.decode('.../..../-...-/--.--/.-.--', options), 'ส ห อ ฮ ฤ');
196+
t.equal(morsify.decode('.-.../.-/..-../../..--./..--/..-.-/---././.-.-/.-..-/---/...-.', options), 'ะ า ิ ี ึ ื ุ ู เ แ ไ โ ำ');
197+
t.equal(morsify.decode('..-/...-/--.../.-.-.', options), '่ ้ ๊ ๋');
198+
t.equal(morsify.decode('.--.-/---../--..-/-.---/--.-.', options), 'ั ็ ์ ๆ ฯ');
199+
200+
/* full test
201+
** this test can be used after figure out how to deal with Thai alphabeth duplications and conflicts
202+
203+
t.equal(morsify.decode('--./-.-./-.-./-.-/-.-/-.-/-.--.', options), 'ก ข ฃ ค ฅ ฆ ง');
204+
t.equal(morsify.decode('-..-./----/-..-/--../.---/-../-..', options), 'จ ฉ ช ซ ญ ด ฎ');
205+
t.equal(morsify.decode('-/-/-.-../-.-../-..--/-..--/-..--/-..--/-./-./-...', options), 'ต ฏ ถ ฐ ท ธ ฑ ฒ น ณ บ');
206+
t.equal(morsify.decode('.--./--.-/-.-.-/.--../..-.', options), 'ป ผ ฝ พ ภ ฟ');
207+
t.equal(morsify.decode('--/-.--/.-./.-../.-../.--', options), 'ม ย ร ล ฬ ว');
208+
t.equal(morsify.decode('.../.../.../..../-...-/--.--/.-.--', options), 'ศ ษ ส ห อ ฮ ฤ ฤๅ');
209+
t.equal(morsify.decode('.-.../.-/..-../../..--./..--/..-.-/---././.-.-/.-..-/.-..-/---/...-.', options), 'ะ า ิ ี ึ ื ุ ู เ แ ไ ใ โ ำ');
210+
t.equal(morsify.decode('..-/...-/--.../.-.-.', options), '่ ้ ๊ ๋');
211+
t.equal(morsify.decode('.--.-/---../--..-/-.---/--.-./---.-', options), 'ั ็ ์ ๆ ฯ ฯลฯ');
212+
213+
*/
214+
});
161215
it('returns mapped characters', function () {
162216
var characters = morsify.characters();
163217
t.equal(characters[1]['A'], '.-');
@@ -171,6 +225,7 @@ describe('morsify', function () {
171225
t.equal(characters[9]['ا'], '.-');
172226
t.equal(characters[10]['ア'], '--.--');
173227
t.equal(characters[11]['ㄱ'], '.-..');
228+
t.equal(characters[12]['ก'], '--.');
174229
characters = morsify.characters({ dash: '–', dot: '•', space: ' ' });
175230
t.equal(characters[1]['A'], '•–');
176231
t.equal(characters[2]['0'], '–––––');
@@ -183,5 +238,7 @@ describe('morsify', function () {
183238
t.equal(characters[9]['ا'], '•–');
184239
t.equal(characters[10]['ア'], '––•––');
185240
t.equal(characters[11]['ㄱ'], '•–••');
241+
t.equal(characters[12]['ก'], '––•');
186242
});
243+
187244
});

0 commit comments

Comments
 (0)