Home Reference Source Repository
import MorseMessage from 'morse-pro/src/morse-pro-message.js'
public class | source

MorseMessage

Direct Subclass:

MorseCW

Class for conveniently translating to and from Morse code. Deals with error handling. Works out if the input is Morse code or not.

Example:

import MorseMessage from 'morse-pro-message';
import MorseCWWave from 'morse-pro-cw-wave';
let morseCWWave = new MorseCWWave();
let morseMessage = new MorseMessage(morseCWWave);
let output;
try {
    output = morseMessage.translate("abc");
catch (ex) {
    // output will be best attempt at translation
    // to understand the detail of where the error is, look at morseMessage.errors or display getErrorString()
}
if (morseMessage.inputWasMorse) {
    // do something
}
// get the Morse code waveform
let wave = morseMessage.wave;

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

errors: *

public
public
public

morse: *

public
public
public
public

text: *

public
public get

timings: *

public get

wave: *

Method Summary

Public Methods
public

cleanText(): *

public

getInputErrorString(prefix: String, suffix: String, escapeMap: Map): *

public

getMorseErrorString(prefix: *, suffix: *): *

public

getOutputErrorString(prefix: *, suffix: *, escapeMap: {}): *

public

getTextErrorString(prefix: *, suffix: *, escapeMap: {}): *

public

loadMorse(input: *): *

public

loadText(input: *): *

public

translate(input: string, isMorse: boolean): *

Translate to or from Morse.

Private Methods
private

Public Constructors

public constructor() source

Public Members

public errors: * source

public hasError: * source

public inputWasMorse: * source

public morse: * source

public morseCWWave: * source

public morseTokens: * source

public rawInput: * source

public text: * source

public textTokens: * source

public get timings: * source

public get wave: * source

Public Methods

public cleanText(): * source

Return:

*

public getInputErrorString(prefix: String, suffix: String, escapeMap: Map): * source

Params:

NameTypeAttributeDescription
prefix String

this is placed before each input token that had an error

suffix String

this is placed after each input token that had an error

escapeMap Map

any token matching a key in this map is replaced by the value (e.g. {'>': '>', '<': '<'})

Return:

*

public getMorseErrorString(prefix: *, suffix: *): * source

Params:

NameTypeAttributeDescription
prefix *
suffix *

Return:

*

public getOutputErrorString(prefix: *, suffix: *, escapeMap: {}): * source

Params:

NameTypeAttributeDescription
prefix *
suffix *
escapeMap {}
  • optional
  • default: {}

Return:

*

public getTextErrorString(prefix: *, suffix: *, escapeMap: {}): * source

Params:

NameTypeAttributeDescription
prefix *
suffix *
escapeMap {}
  • optional
  • default: {}

Return:

*

public loadMorse(input: *): * source

Params:

NameTypeAttributeDescription
input *

Return:

*

public loadText(input: *): * source

Params:

NameTypeAttributeDescription
input *

Return:

*

public translate(input: string, isMorse: boolean): * source

Translate to or from Morse.

Params:

NameTypeAttributeDescription
input string

alphanumeric text or morse code to translate

isMorse boolean

whether the input is Morse code or not (if not set then the looksLikeMorse method will be used)

Return:

*

Throw:

*

Error if there was something untranslatable

Private Methods

private _completeFields(d: *) source

Params:

NameTypeAttributeDescription
d *