Morse Code

version MIT License PRs Welcome

Watch on GitHub Star on GitHub

Usage

First, add this library as a dependency in the pubspec.yaml file:

dependencies:
  morse: ^0.1.4+1

Import the Morse class into your Dart file as follows:

import 'package:morse/morse.dart';

For this example we're going to use the following string of morse code:

final String encodedMessage = '.... . .-.. .-.. --- / .-- --- .-. .-.. -..';

There are two ways to decode morse code. Either provide the encoded string as an argument to the constructor and call the decode method.

final Morse morse = new Morse(encodedMessage);
String decodedMessage = morse.decode();

// Or combine the two, for more compact code:
String decodedMessage =  new Morse(encodedMessage).decode();

Or provide the encoded string as an argument to the decode method.

final Morse morse = new Morse();
String decodedMessage = morse.decode(encodedMessage);

// Or again combine the two, for more compact code:
String decodedMessage =  new Morse().decode(encodedMessage);

You can also use the encode method to convert text to morse code.

final String message = 'Hello World';
final Morse morse = new Morse(message);
String encodedMessage = morse.encode();

// Or combine the two, for more compact code:
String encodedMessage =  new Morse(message).encode();

Contributing

Feel free to open a pull request with any suggestions!

Libraries

morse