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

morse-key-converter

v1.0.0

Published

morse key to text converter and vice versa

Downloads

6

Readme

npm version CDNJS Build status Gitpod Ready-to-Code code coverage install size npm bundle size npm downloads gitter chat

Table of Contents

Features

  • Converts a text or string to Morse code

  • Converts a morse code string to its corresponding text

  • Can convert Latin and extended Latin alphabet with accented vowels, vowels with umlauts, numbers and punctuation symbols.

Browser Support

| Chrome | Firefox | Edge | |---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------| | Latest ✔ | Latest ✔ | Latest ✔ |

Installing

Read the followings subtitles.

Package manager

Using npm:


$ npm install morse-key-converter

Using bower:


$ bower install morse-key-converter

Using yarn:


$ yarn add morse-key-converter

Using pnpm:


$ pnpm add morse-key-converter

Once the package is installed, you can import the library using the CommonJS require approach:


const MorseConverter = require('morse-key-converter');

For cases where something went wrong when trying to import a module into a custom or legacy environment,

you can try importing the module package directly:


const MorseConverter = require('morse-key-converter/src/index');

Run test file

once the package is installed, if you want to test the package's default test file, enter the following command:

$ cd node_modules/morse-key-converter
$ npm run start test

and if all is well you will observe the following :

$ npm run start-test

> [email protected] start-test D:\User\Documents\DIGITALHARBOR\06WEBFrontendTechnologies\parte4\1221WS\morse-key-converter
> node test.js

===========ALPHABETICO=============
Input text compare with expected...
Encoded successful
Text decoded compare with input...
Decoded successful
===========NUMERIC=============
Input text compare with expected...
Encoded successful
Text decoded compare with input...
Decoded successful
===========PUNCTUATION=============
Input text compare with expected...
Encoded successful
Text decoded compare with input...
Decoded successful
Input text compare with expected...
Encoded successful
Text decoded compare with input...
Decoded successful
===========LATIN EXTENDED ENCODE=============
Input text compare with expected...
Encoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Encoded successful
===========LATIN EXTENDED DECODE=============
Input text compare with expected...
Decoded successful
Input text compare with expected...
Decoded successful
Input text compare with expected...
Decoded successful
Input text compare with expected...
Decoded successful
Input text compare with expected...
Decoded successful
Input text compare with expected...
Decoded successful
Input text compare with expected...
Decoded successful
===========CUSTOM TEST=============
Input text compare with expected...
Encoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Decoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Decoded successful
Input text compare with expected...
Encoded successful
Input text compare with expected...
Decoded successful

Example

Note CommonJS usage

The first step would be to import the MorseConverter class and instantiate it as shown below:


const MorseConverter = require('morse-key-converter');

// MorseConverter is a nodejs class so the first thing to do is to instantiate it using new as in the following example:

const morseConverter = new MorseConverter()


Available methods

Second step, use available methods.

The following methods are available : encodeText(inputString) //returns the string entered as a parameter encoded in Morse code. decodeMorseText(inputString) //returns the string entered as a parameter decoded into its corresponding Latin alphabet meaning.

Example of invocation :

//using the above variable containing the instantiated class
let textEncoded = morseConverter.encodeText('Hello world'); // output .... . .-.. .-.. --- / .-- --- .-. .-.. -..
let textEncoded = morseConverter.decodeMorseText('.... . .-.. .-.. --- / .-- --- .-. .-.. -..');// output HELLO WORLD

Encode example

The following is an example of converting some text to morse code:


const MorseConverter = require('morse-key-converter');
const morseConverter = new MorseConverter()

let textEncoded = morseConverter.encodeText('ABCDEFGHIJKLMNÑOPQRSTUVWXYZ');
console.log(textEncoded)

//output => .- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --.-- --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..

Decode example

The following is an example of converting some Morse code text into natural language:


const MorseConverter = require('morse-key-converter');
const morseConverter = new MorseConverter()

let textEncoded = morseConverter.decodeMorseText('.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --.-- --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..');
console.log(textEncoded)

//output => ABCDEFGHIJKLMNÑOPQRSTUVWXYZ

And that's how our package works.

Resources

the alphabet used for the conversion is as follows:

const latin = {
  "A": ".-",
  "B": "-...",
  "C": "-.-.",
  "D": "-..",
  "E": ".",
  "F": "..-.",
  "G": "--.",
  "H": "....",
  "I": "..",
  "J": ".---",
  "K": "-.-",
  "L": ".-..",
  "M": "--",
  "N": "-.",
  "Ñ": "--.--",
  "O": "---",
  "P": ".--.",
  "Q": "--.-",
  "R": ".-.",
  "S": "...",
  "T": "-",
  "U": "..-",
  "V": "...-",
  "W": ".--",
  "X": "-..-",
  "Y": "-.--",
  "Z": "--..",
  "1": ".----",
  "2": "..---",
  "3": "...--",
  "4": "....-",
  "5": ".....",
  "6": "-....",
  "7": "--...",
  "8": "---..",
  "9": "----.",
  "0": "-----",
  ".": ".-.-.-",
  ",": "--..--",
  "?": "..--..",
  "'": ".----.",
  "!": "-.-.--",
  "/": "-..-.",
  "(": "-.--.",
  ")": "-.--.-",
  "&": ".-...",
  ":": "---...",
  ";": "-.-.-.",
  "=": "-...-",
  "+": ".-.-.",
  "-": "-....-",
  "_": "..--.-",
  "\"": ".-..-.",
  "$": "...-..-",
  "@": ".--.-.",
  "¿": "..-.-",
  "¡": "--...-",
  " ": "/"
}

const latinExtended = {
  'Ã': '.--.-',
  'Á': '.--.-',
  'Å': '.--.-',
  'À': '.--.-',
  'Â': '.--.-',
  'Ä': '.-.-',
  'Ą': '.-.-',
  'Æ': '.-.-',
  'Ç': '-.-..',
  'Ć': '-.-..',
  'Ĉ': '-.-..',
  'Č': '-.-..',
  'Ę': '..-..',
  'Ð': '..--.',
  'È': '.-..-',
  'Ë': '..-..',
  'É': '..-..',
  'Ê': '..-..',
  'Ğ': '--.-.',
  'Ĝ': '--.-.',
  'Ĥ': '----',
  'İ': '.-..-',
  'Ï': '-..--',
  'Ì': '.---.',
  'Ĵ': '.---.',
  'Ł': '.-..-',
  'Ń': '--.--',
  'Ñ': '--.--',
  'Ó': '---.',
  'Ò': '---.',
  'Ö': '---.',
  'Ô': '---.',
  'Ø': '---.',
  'Ś': '...-...',
  'Ş': '.--..',
  'Ș': '----',
  'Š': '----',
  'Ŝ': '...-.',
  'ß': '...',
  'Þ': '.--..',
  'Ü': '..--',
  'Ý': '..--',
  'Ù': '..--',
  'Ŭ': '..--',
  'Ž': '--..-',
  'Ź': '--..-.',
  'Ż': '--..-'
}

Because the extended Latin can be handled in different ways the following JSON was used to decode this can be easily updated: Reference link : https://ham.stackexchange.com/questions/1379/international-characters-in-morse-code

const toDecodeLatinExtended = {
  '.--.-': 'Ã',
  '.-.-': 'Ä',
  '-.-..': 'Ç',
  '..-..': 'Ę',
  '..--.': 'Ð',
  '.-..-': 'È',
  "--.-.": "Ğ",
  "----": "Ĥ",
  "-..--": "Ï",
  ".---.": "Ì",
  "---.": "Ó",
  "...-.": "Ŝ",
  ".--..": "Ş",
  "..--": "Ü",
  "--..-": "Ž",
  "--..-.": "Ź",
}

Credits

The library is based on the following web pages:

  • https://morsedecoder.com/
  • https://ham.stackexchange.com/questions/1379/international-characters-in-morse-code

License

[ISC]