npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

morjs

v1.1.0

Published

Library for encoding/decoding Morse code messages

Downloads

18

Readme

                            __
  ___ ___     ___   _ __   /\_\    ____
/' __` __`\  / __`\/\`'__\ \/\ \  /',__\
/\ \/\ \/\ \/\ \L\ \ \ \/__ \ \ \/\__, `\
\ \_\ \_\ \_\ \____/\ \_\\_\_\ \ \/\____/
 \/_/\/_/\/_/\/___/  \/_//_/\ \_\ \/___/
                           \ \____/
                            \/___/

mor.js is a pure JavaScript library for encoding/decoding Morse code messages that supports extensible characters and encoding output.

Build Status Dependency Status Built with Grunt

Install

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.

Usage

The API has been completely redesigned to simplify encoding and decoding Morse code messages by simply passing a string to the encode and 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 optional themselves):

| Option | Description | Default | | ------ | -------------------------------------------- | ------------ | | mode | Mode to be used to encode/decode the message | "comptact" |

encode(message[, options])

Encodes the message parameter using the Morse code.

console.log(morjs.encode('SOS', {mode: 'simple'})); // "... --- ..."

decode(message[, options])

Decodes the encoded Morse code message parameter.

console.log(morjs.decode('... --- ...', {mode: 'simple'})); // "SOS"

Customization

defaults

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.

morjs.defaults.mode = 'simple';

console.log(morjs.encode('SOS')); // "... --- ..."

chars

A simple map of Unicode characters and their corresponding patterns, which are used when encoding and decoding messages. A pattern is a series of "S" and "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:

morjs.chars['\u039B'] = 'LLLLLSSSSS';

console.log(morjs.encode('\u039B', {mode: 'simple'})); // "-----....."

modes

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 RegExp special characters.

Here's a list of the built in modes:

  • classic
  • classicEntities
  • compact (default)
  • compactEntities
  • simple

Adding a new mode is as simple as the following:

morjs.modes.foo = {
  charSpacer:   '',
  letterSpacer: ' ',
  longString:   'F',
  shortString:  'O',
  wordSpacer:   '   '
};

var options = {mode: 'foo'};

console.log(morjs.encode('SOS', options));         // "OOO FFF OOO"
console.log(morjs.decode('OOO FFF OOO', options)); // "SOS"

Miscellaneous

noConflict()

Returns morjs in a no-conflict state, reallocating the morjs global variable name to its previous owner, where possible.

This is really just intended for use within a browser.

<script src="/path/to/conflict-lib.js"></script>
<script src="/path/to/mor.min.js"></script>
<script>
  var morjsNC = morjs.noConflict();
  // Conflicting lib works again and use morjsNC for this library onwards...
</script>

VERSION

The current version of morjs.

console.log(morjs.VERSION); // "1.1.0"

Bugs

If you have any problems with this library or would like to see changes currently in development you can do so here.

Contributors

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!

A list of mor.js contributors can be found in AUTHORS.md.

License

Copyright (c) 2014 Alasdair Mercer

See LICENSE.md for more information on our MIT license.