Morsify is a Morse code encoder and decoder with no dependencies. Currently, 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 morsify --save
yarn
$ yarn add morsify
Usage
const morsify = require('morsify');
const encoded = morsify.encode('SOS');
const decoded = morsify.decode('... --- ...');
const characters = morsify.characters();
const audio = morsify.audio('SOS');
audio.play();
audio.stop();
Alternatively, you can use the library directly with including the source file.
<script src="https://rawgit.com/ozdemirburak/morsify/master/dist/morsify.min.js"></script>
<script>
var encoded = morsify.encode('SOS');
var decoded = morsify.decode('... --- ...');
var characters = morsify.characters();
var audio = morsify.audio('SOS');
var oscillator = audio.oscillator;
var context = audio.context;
var gainNode = audio.gainNode;
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.
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 = morsify.encode('Ленинград', { priority: 5 });
const greek = morsify.decode('... .- --. .- .--. .--', { priority: 6 });
const hebrew = morsify.decode('.. ––– . –––', { dash: '–', dot: '.', priority: 7 });
const japanese = morsify.encode('NEWS', { priority: 10, dash: '-', dot: '・', separator: ' ' });
const characters = morsify.characters({ dash: '–', dot: '•' });
const arabicAudio = morsify.audio('البراق', {
unit: 0.1,
fwUnit: 0.1,
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();
Contributing and Known Issues
Contributions are welcome.
Generating Minified Files
Install node and npm and run the commands below.
$ npm install --global gulp-cli
$ npm install
$ gulp
License
The MIT License (MIT). Please see License File for more information.