morsify
Morse code encoder and decoder with no dependencies supports Latin, Cyrillic, Greek, Hebrew,
Arabic, Persian, Japanese, and Korean characters with audio generation functionality using the Web Audio API.
Installation
npm
$ npm install morsify --save
yarn
$ yarn add morsify
Usage
var morsify = require('morsify');
var encoded = morsify.encode('SOS');
var decoded = morsify.decode('.../---/...');
var audio = morsify.audio('SOS'), oscillator = audio.oscillator;
audio.play();
audio.stop();
Or alternatively, you can also use the library directly with including the source file.
<script src="https://rawgit.com/ozdemirburak/morsify/master/index.js"></script>
<script>
var encoded = morsify.encode('SOS');
var decoded = morsify.decode('.../---/...');
var audio = morsify.audio('SOS');
var oscillator = audio.oscillator;
var context = audio.context;
audio.play();
audio.stop();
</script>
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.
What priority option does is, gives direction to the plugin to start to 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
var cyrillic = morsify.encode('Ленинград', { priority: 5 })
var greek = morsify.decode('.../.-/--./.-/.--./.--', { priority: 6 })
var hebrew = morsify.decode('––– –... ––– –. ––. .. .–.. –––', { dash: '–', dot: '.', space: ' ', priority: 7 })
var arabicAudio = morsify.audio('البُراق', {
unit: 0.1,
oscillator: {
type: 'sine',
frequency: 500,
onended: function () {
console.log('ended');
},
}
});
var oscillator = arabicAudio.oscillator;
var context = arabicAudio.context;
arabicAudio.play();
arabicAudio.stop();
Contributing and Known Issues
Contributions are welcome.
Currently, as a major drawback, Chinese characters are missing. Someone with the knowledge of
Chinese telegraph code can help to implement it. Also someone who is proficient in Thai can help
to include Thai alphabet.
License
The MIT License (MIT). Please see License File for more information.