Morse code encoder and Morse decoder with no dependencies. It supports Latin, Cyrillic, Greek, Hebrew, Arabic,
Persian, Japanese, Korean, and Thai, with audio-generation functionality using the Web Audio API.
Installation
npm
$ npm install @ozdemirburak/morse-code-translator --save
Usage
import morse from '@ozdemirburak/morse-code-translator';
const encoded = morse.encode('SOS');
const decoded = morse.decode('... --- ...');
const characters = morse.characters();
const audio = morse.audio('SOS');
audio.play();
audio.stop();
audio.exportWave();
const url = await audio.getWaveUrl();
const blob = await audio.getWaveBlob();
Options and localization
You can customize the dash, dot, or space characters and specify the alphabet with the priority option for
an accurate encoding and decoding.
The priority option gives direction to the plugin to start searching for the given character set first.
Set the priority option according to the list below.
- 1 => ASCII (Default)
- 2 => Numbers
- 3 => Punctuation
- 4 => Latin Extended (Turkish, Polish etc.)
- 5 => Cyrillic
- 6 => Greek
- 7 => Hebrew
- 8 => Arabic
- 9 => Persian
- 10 => Japanese
- 11 => Korean
- 12 => Thai
const cyrillic = morse.encode('Ленинград', { priority: 5 });
const greek = morse.decode('... .- --. .- .--. .--', { priority: 6 });
const hebrew = morse.decode('.. ––– . –––', { dash: '–', dot: '.', priority: 7 });
const japanese = morse.encode('NEWS', { priority: 10, dash: '-', dot: '・', separator: ' ' });
const characters = morse.characters({ dash: '–', dot: '•' });
const arabicAudio = morse.audio('البراق', {
wpm: 18,
unit: 0.1,
fwUnit: 0.1,
volume: 100,
oscillator: {
type: 'sine',
frequency: 500,
onended: function () {
console.log('ended');
}
}
});
const oscillator = arabicAudio.oscillator;
const context = arabicAudio.context;
const gainNode = arabicAudio.gainNode;
arabicAudio.play();
arabicAudio.stop();
Contributions
morse-code-translator has been developed
with extensive feedback and contributions from numerous developers.
Special thanks to Chris Jones, who added many great features.
References
Please consider referencing the website of this project, if you find this package useful for your work.
<a href="https://morsecodetranslator.com">Morse Code Translator</a>
License
The MIT License (MIT). Please see License File for more information.