Coder Social home page Coder Social logo

morse's Introduction

#morse

A simple Morse code library for node

Samuel F.B. Morse

install

For use as a CLI:

npm install -g morse

For use as a library:

npm install morse

example usage as a CLI

$ 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

example usage as a library

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' ]

methods

morse.encode(obj)

Encodes and returns a given string or array

morse.decode(obj, dichotomic)

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.

attributes

morse.map

An object containing letter: morse translations contained in map.js

morse.tree

A tree-modeled object contained in tree.js

license

MIT

morse's People

Contributors

ecto avatar ryanseys avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.