morse_codec 1.0.5 copy "morse_codec: ^1.0.5" to clipboard
morse_codec: ^1.0.5 copied to clipboard

This package provides efficient converters to transform text into Morse code and vice versa, supporting letters, digits, and common punctuation marks.

Morse Codec #

License

A lightweight Dart package for encoding and decoding Morse code. This package provides efficient converters to transform text into Morse code and vice versa, supporting letters, digits, and common punctuation marks.

Table of Contents #

Installation #

Run the command line:

dart pub add morse_codec

Usage #

Basic Text Encoding #

Convert text to Morse code:

import "package:morse_codec/morse_codec.dart";

void main() {
  const text = "Hello World!";

  // Convert text to Morse code
  final morseCode = const MorseEncoder().convertText(text);

  print(morseCode);
  // Output: .... . .-.. .-.. --- / .-- --- .-. .-.. -.. -.-.--
}

Explanation:

  • . represents a dot (dit)
  • - represents a dash (dah)
  • Space separates individual characters
  • / separates words

Basic Text Decoding #

Convert Morse code back to text:

import "package:morse_codec/morse_codec.dart";

void main() {
  const morseCode = ".... . .-.. .-.. ---";

  // Convert Morse code to text
  final text = const MorseDecoder().convertText(morseCode);

  print(text);
  // Output: HELLO
}

Advanced Usage #

Working with Character Codes Directly

If you need fine-grained control over the conversion process:

import "package:morse_codec/morse_codec.dart";

void main() {
  // Work directly with character codes
  const charCodes = [83, 79, 83]; // "SOS"

  final morseCharCodes = const MorseEncoder().convert(charCodes).toList();

  print("Raw Morse codes: $morseCharCodes");
  // Converts to: [46, 46, 46, 32, 45, 45, 45, 32, 46, 46, 46]
  // Which displays as: "... --- ..."
}

Supported Characters #

Letters (A-Z) & Digits (0-9) #

  • Case-insensitive encoding (input is converted to uppercase)
  • All 26 letters supported
  • All 10 digits supported
Letter Morse Letter Morse Letter Morse Digit Morse
A .- K -.- U ..- 0 -----
B -... L .-.. V ...- 1 .----
C -.-. M -- W .-- 2 ..---
D -.. N -. X -..- 3 ...--
E . O --- Y -.-- 4 ....-
F ..-. P .--. Z --.. 5 .....
G --. Q --.- 6 -....
H .... R .-. 7 --...
I .. S ... 8 ---..
J .--- T - 9 ----.

Punctuation & Symbols #

  • 18 Symbols
Name Symbol Morse
Exclamation mark ! -.-.--
Question mark ? ..--..
Period . .-.-.-
Comma , --..--
Apostrophe ' .----.
Exclamation ! -.-.--
Slash / -..-.
Left parenthesis ( -.--.
Right parenthesis ) -.--.-
Ampersand & .-...
Colon : ---...
Semicolon ; -.-.-.
Plus + .-.-.
Minus - -....-
Equals = -...-
At symbol @ .--.-.
Dollar sign $ ...-..-
Quote " .-..-.

Unknown Characters #

The encoder and decoder work in different ways, see the following examples:

import "package:morse_codec/morse_codec.dart";

void main() {
  // Using an unsupported emoji
  final result = const MorseEncoder().convertText("Hi 😊");

  print("Result: $result");
  // .... .. /
  // Unknown characters will not be encoded

  // Using an unsupported emoji
  final result = const MorseDecoder().convertText(". .......... -");

  print("Result: $result");
  // E�T
  // Invalid Morse codes will be decoded as unknown characters
}

Performance #

The morse_codec package is designed for high performance:

  • Time Complexity: O(n) for both encoding and decoding, where n is the number of characters
  • Space Complexity: O(n) for the output, with minimal overhead
  • Memory Efficient: Uses lazy evaluation with iterables instead of eager list allocation

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request to the repository.

Development Setup #

# Clone the repository
git clone https://github.com/Gorniaky/dart_morse_codec.git
cd dart_morse_codec

# Install dependencies
dart pub get

# Run tests
dart test

# Run analysis
dart analyze

# Format code
dart format .

Testing #

The package includes a comprehensive test suite. Run tests with:

dart test

License #

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Changelog #

See CHANGELOG.md for version history and release notes.

Additional Resources #


Built with ❤️ for Dart developers

0
likes
160
points
12
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

This package provides efficient converters to transform text into Morse code and vice versa, supporting letters, digits, and common punctuation marks.

Repository (GitHub)
View/report issues

Topics

#codec #convert #decoder #encoder #morse

License

Apache-2.0 (license)

More

Packages that depend on morse_codec