Morse code encoder / decoder.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
example.js
morse-node.js
morse-node.min.js
package.json

README.md

Morse Node

A very tiny, dependency-free Morse code encoder and decoder. Currently supports the ITU standard.

Install

npm install morse-node

Getting Started

Setup API

 var morse = require('morse-node').create("ITU");

Encoding

  • All alphanumeric characters are accepted, available symbols includes everything inside the brackets [ . , ? ' ! / ( ) & : ; = + - _ " $ @ ].
var msg = morse.encode('The quick brown fox jumped over the lazy dog.');

Decoding

  • Letters are seperated by a single space.
  • Words are seperated by a forward slash " / ".
var msg = morse.decode("- .... ./--.- ..- .. -.-. -.-/-... .-. --- .-- -./..-. --- -..-/.--- ..- -- .--. . -../--- ...- . .-./- .... ./.-.. .- --.. -.--/-.. --- --. .-.-.-");

isValid

  • Check validity of a string by using the isValid function.
  • Encoding and decoding functions do not make this check and will attempt to translate your string regardless of undefined characters.

Example

example.js

var morse = require('morse-node').create();

var encoded = morse.encode('Pack my box with five dozen liquor jugs!');
console.log(encoded);

var decoded = morse.decode(encoded);
console.log(decoded);

console.log(morse.isValid(encoded, "morse"));
console.log(morse.isValid(encoded += "asdf", "morse"));
console.log(morse.isValid(decoded, "chars"));
console.log(morse.isValid(decoded += "~", "chars"));

Output

.--. .- -.-. -.- / -- -.-- / -... --- -..- / .-- .. - .... / ..-. .. ...- . / -.. --- --.. . -. / .-.. .. --.- ..- --- .-. / .--- ..- --. ... -.-.--
pack my box with five dozen liquor jugs!
true
false
true
false

Author

Calvin Nichols