MCPcopy Create free account
hub / github.com/cryptii/cryptii / encodeCharacter

Method encodeCharacter

src/Encoder/MorseCode.js:352–369  ·  view source on GitHub ↗

* Encodes given character to its morse code representation. * @protected * @param {string} char Character to be encoded. * @param {string} shortMark * @param {string} longerMark * @param {string} spaceMark * @return {?string} Morse code representation or null, if not defined.

(char, shortMark, longerMark, spaceMark)

Source from the content-addressed store, hash-verified

350 * @return {?string} Morse code representation or null, if not defined.
351 */
352 static encodeCharacter (char, shortMark, longerMark, spaceMark) {
353 // Handle space
354 if (StringUtil.isWhitespace(char)) {
355 return spaceMark
356 }
357
358 // Find char in alphabet
359 const index = alphabet.indexOf(char)
360 if (index === -1) {
361 // Char is not defined
362 return null
363 }
364
365 // Translate marks
366 const code = codeAlphabet[index]
367 return MorseCodeEncoder.translateMarks(
368 code, ['.', '-'], [shortMark, longerMark])
369 }
370
371 /**
372 * Decodes given code to its character representation.

Callers 1

performEncodeMethod · 0.80

Calls 3

isWhitespaceMethod · 0.80
indexOfMethod · 0.80
translateMarksMethod · 0.80

Tested by

no test coverage detected