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

@easy-cipher/morse

v1.1.0

Published

[![npm](https://img.shields.io/npm/v/@easy-cipher/morse.svg)](https://www.npmjs.com/package/@easy-cipher/morse) [![npm bundle size (minified + gzip)](https://badgen.net/bundlephobia/minzip/@easy-cipher/morse)](https://bundlephobia.com/result?p=@easy-ciphe

Downloads

3

Readme

morse

npm npm bundle size (minified + gzip) no external dependencies

morse package is morse code mapping package built on the core which is package responsible for mapping strings, thus the implementation of the package has to be compatible with core API. The idea behind this package was to give customization to almost everything in the library, therefore almost any piece of code depends of constants (More on it later on).

Basic usage

Without any customizations, morse can be used as is.

const sentence = 'friday is best day of the week';
const { encode } = morse();

const result = encode(sentence);
// Returns ..-. .-. .. -.. .- -.-- / .. ... / -... . ... - / -.. .- -.-- / --- ..-. / - .... . / .-- . . -.-

Decoding the cipher is also a piece of cake

const cipher =
  '..-. .-. .. -.. .- -.-- / .. ... / -... . ... - / -.. .- -.-- / --- ..-. / - .... . / .-- . . -.-';
const { decode } = morse();

const result = decode(cipher);
// Returns 'friday is best day of the week'

Caveat

Keep in mind that every time you call morse, all mappings are created dynamically, so instead of calling it over and over again. Call it once, and save encode and decode somewhere.

encode & decode

encode & decode functions comes from the core package.

Customization

morse has a extend method on configuration object. The extend has to return an Record<string, string> and will be merged with default international mappings for morse code. The extend function goal was to provide a quick way to add some characters to morse code or overwrite existing ones. If you wanna pre-define the whole layout, see the core package.

const sentence = 'hello from the ÄÖÜ';
const cipher =
  '.... . .-.. .-.. --- / ..-. .-. --- -- / - .... . / .-.- ---. ..--';
const { encode, decode } = morse({
  extend: () => ({
      Ä: '.-.-',
      Ö: '---.',
      Ü: '..--',
  }),
});

encode(sentence);
// Returns '.... . .-.. .-.. --- / ..-. .-. --- -- / - .... . / .-.- ---. ..--'

decode(cipher);
// Returns 'hello from the ÄÖÜ'

But that's not the end of it. morse also takes three additinal configuration arguments (outside of core package configuratoin arguments).

dot, dash & partsOfLetterSeparator

The morse library supprots dot, dash and partsOfLettersSeparator constants. dot is a character used to represnt dot symbol in Morse code. By the default the character is ., dash by default is - and there is no separator between parts of letters. However you can customize it to your needs.

const { morse } = require('@easy-cipher/morse');

const sentence = 'friday is best day of the week';
const cipher =
  'acacbca acbca aca bcaca acb bcacbcb / aca acaca / bcacaca a acaca b / bcaca acb bcacbcb / bcbcb acacbca / b acacaca a / acbcb a a bcacb';
const { encode, decode } = morse({
  dot: 'a',
  dash: 'b',
  partsOfLetterSeparator: 'c',
});

encode(sentence);
// Returns acacbca acbca aca bcaca acb bcacbcb / aca acaca / bcacaca a acaca b / bcaca acb bcacbcb / bcbcb acacbca / b acacaca a / acbcb a a bcacb

decode(cipher);
// Returns 'friday is best day of the week'

I don't know if it's most useful feature of the world, but for sure it's a funny one. You can also control the separator between the letters and words. More on that in core package docs.

If you're using custom characters and additionaly you extend the mappings, there's a ready utility in extend function parameters.

const sentence = 'hello from the ÄÖÜ';
const cipher =
  'acacaca a acbcaca acbcaca bcbcb / acacbca acbca bcbcb bcb / b acacaca a / acbcacb bcbcbca acacbcb';
const { encode, decode } = morse({
  dot: 'a',
  dash: 'b',
  partsOfLetterSeparator: 'c',
  extend: ({ dot, dash, buildCipher }) => ({
    Ä: buildCipher(dot, dash, dot, dash),
    Ö: buildCipher(dash, dash, dash, dot),
    Ü: buildCipher(dot, dot, dash, dash),
  }),
});

encode(sentence);
// Returns acacbca acbca aca bcaca acb bcacbcb / aca acaca / bcacaca a acaca b / bcaca acb bcacbcb / bcbcb acacbca / b acacaca a / acbcb a a bcacb

decode(cipher);
// Returns 'hello from the ÄÖÜ'

Caveat

If you wanna also encode upper-case letters, you have to convert it to lowercase (The defualt mappings cover just lowercase letters).

const sentence = 'Friday IS best day of the WEEK';
const { encode } = morse();

const result = encode(sentence.toLocaleLowerCase());
// Returns ..-. .-. .. -.. .- -.-- / .. ... / -... . ... - / -.. .- -.-- / --- ..-. / - .... . / .-- . . -.-

Currently support for unicode characters may be difficult, because of using split Array method.

Other customizations

Other customizations are available and are described in the core package in deep.