morse-node

0.1.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i morse-node

Weekly Downloads

68

Version

0.1.1

License

BSD

Last publish

Collaborators

  • calvindn