#morse
A simple Morse code library for node
For use as a CLI:
npm install -g morse
For use as a library:
npm install morse
$ morse -h
Usage: morse [options] string
Options:
-d, --decode Decode a string of Morse code [boolean]
-h, --help Show this text
$ morse hello > hello.txt
$ morse -d "`cat hello.txt`"
HELLO
var morse = require('morse');
var encoded = morse.encode('Hello, world.');
// .... . .-.. .-.. --- --..-- ....... .-- --- .-. .-.. -.. .-.-.-
morse.decode(encoded);
// HELLO, WORLD.
var encoded = morse.encode([ 'hello', 'world' ]);
// [ '.... . .-.. .-.. ---', '.-- --- .-. .-.. -..' ]
morse.decode(encoded);
// [ 'HELLO', 'WORLD' ]
Encodes and returns a given string or array
Decodes and returns a string or array
dichotomic
defaults to false. If passed true, it will use a tree-based approach to decode the string or array. If false, a basic iteration of the map is used.
The dichotomic approach looks like this:
The implementation does not include spaces right now, so it fails its test. However, it is otherwise accurate.
morse.decode(
morse.encode('Hello, world.'),
true
);
// HELLO,5WORLD.
An object containing letter: morse
translations contained in map.js
A tree-modeled object contained in tree.js
MIT