Library for encoding/decoding Morse code messages
__ ___ ___ ___ _ __ /\_\ ____ /' __` __`\ / __`\/\`'__\ \/\ \ /',__\ /\ \/\ \/\ \/\ \L\ \ \ \/__ \ \ \/\__, `\ \ \_\ \_\ \_\ \____/\ \_\\_\_\ \ \/\____/ \/_/\/_/\/_/\/___/ \/_//_/\ \_\ \/___/ \ \____/ \/___/
Install using the package manager for your desired environment(s):
# for node.js:$ npm install morjs# OR; for the browser:$ bower install morjs
This library has no dependencies on any other library.
The API has been completely redesigned to simplify encoding and decoding Morse code messages by simply passing a
string to the
decode functions respectively.
It's important to note that some characters are encoded to the same Morse code sequence (mainly outside of the normal alphabet). This also means that, when decoding such messages, the original character is not guaranteed to be matched unless it's the first using that sequence. This is not a limitation of this library but of the Morse code language itself which did not guarantee uniqueness.
Both of which also accept an optional
options parameter which can currently contain the following (all of which are
|mode||Mode to be used to encode/decode the message||
message parameter using the Morse code.
console.logmorjsencode'SOS' mode: 'simple'; // "... --- ..."
Decodes the encoded Morse code
console.logmorjsdecode'... --- ...' mode: 'simple'; // "SOS"
This is a hash of default values to be applied to the optional
options parameter and exposed to allow you to override
any of them.
morjsdefaultsmode = 'simple';console.logmorjsencode'SOS'; // "... --- ..."
A simple map of Unicode characters and their corresponding patterns, which are used when encoding and decoding
messages. A pattern is a series of
"L" characters representing short and long respectively.
The characters are too many to list here but you can find them easily in the source code or when inspecting this value.
Adding support for a new character couldn't be easier. In the following example support for the lambda character is added using a made-up pattern:
morjschars'\u039B' = 'LLLLLSSSSS';console.logmorjsencode'\u039B' mode: 'simple'; // "-----....."
Modes are key to parsing both encoded and decoded messages as they contain strings used to find and replace patterns in
the message. Some of these strings are used to build regular expressions, so it's recommended to familiarized yourself
with the usage of modes before creating any custom ones, just so you know on which you need to escape any
Here's a list of the built in modes:
Adding a new mode is as simple as the following:
morjsmodesfoo =charSpacer: ''letterSpacer: ' 'longString: 'F'shortString: 'O'wordSpacer: ' ';var options = mode: 'foo';console.logmorjsencode'SOS' options; // "OOO FFF OOO"console.logmorjsdecode'OOO FFF OOO' options; // "SOS"
morjs in a no-conflict state, reallocating the
morjs global variable name to its previous owner, where
This is really just intended for use within a browser.
The current version of
console.logmorjsVERSION; // "1.1.0"
If you have any problems with this library or would like to see changes currently in development you can do so here.
If you want to contribute, you're a legend! Information on how you can do so can be found in CONTRIBUTING.md. We want your suggestions and pull requests!
Copyright (c) 2014 Alasdair Mercer
See LICENSE.md for more information on our MIT license.