textToMorse function

String textToMorse(
  1. String text
)

Converts English text to Morse code. Throws an ArgumentError if any unsupported character is detected.

Implementation

String textToMorse(String text) {
  final result = text.toUpperCase().split('').map((char) {
    if (!_morseCodeMap.containsKey(char)) {
      throw ArgumentError('Unsupported character: $char');
    }
    return _morseCodeMap[char] ?? '';
  }).join(' ');
  return result;
}