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

Method validateCodeMarkSettingValue

src/Encoder/MorseCode.js:257–282  ·  view source on GitHub ↗

* Validates code mark setting value. * Makes sure they can be differentiated from each other. * @protected * @param {mixed} rawValue * @param {Setting} setting * @return {boolean} Returns true, if value is valid.

(rawValue, setting)

Source from the content-addressed store, hash-verified

255 * @return {boolean} Returns true, if value is valid.
256 */
257 validateCodeMarkSettingValue (rawValue, setting) {
258 const mark = setting.filterValue(rawValue)
259
260 // Because morse code letters are separated by whitespaces they
261 // are not allowed inside morse code marks
262 if (mark.match(/\s/) !== null) {
263 return {
264 key: 'morseCodeMarkWhitespaceNotAllowed',
265 message: 'Whitespaces are not allowed inside morse code marks'
266 }
267 }
268
269 const equalSettingName =
270 ['shortMark', 'longerMark', 'spaceMark']
271 .filter(name => name !== setting.getName())
272 .find(name => mark.isEqualTo(this.getSettingValue(name)))
273
274 if (equalSettingName !== undefined) {
275 return {
276 key: 'morseCodeMarkNotUnique',
277 message: 'Morse code marks need to be different from each other'
278 }
279 }
280
281 return true
282 }
283
284 /**
285 * Validates timing mark setting value.

Callers

nothing calls this directly

Calls 5

matchMethod · 0.80
isEqualToMethod · 0.80
getSettingValueMethod · 0.80
filterValueMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected