Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/salif/morse-code-translator

[Mirror] Morse Code Translator
https://github.com/salif/morse-code-translator

gleam gleam-lang gleam-language hacktoberfest hacktoberfest-accepted hacktoberfest2024 morse-code morse-code-converter morse-code-translator morsecode morsecode-encoder-decoder morsecode-translator

Last synced: 7 days ago
JSON representation

[Mirror] Morse Code Translator

Awesome Lists containing this project

README

        

# Morse Code Translator

[![Package Version](https://img.shields.io/hexpm/v/morse_code_translator)](https://hex.pm/packages/morse_code_translator)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/morse_code_translator/)

## Links

* [Web tool](https://salif.github.io/morse-code-translator/)
* [Source code](https://codeberg.org/salif/morse-code-translator)
* [Discussions (Github)](https://github.com/salif/morse-code-translator/discussions)

## Gleam library

### Installation

```sh
gleam add morse_code_translator@2
```

### Usage

```gleam
import gleam/io
import gleam/option.{None, Some}
import gleam/result
import morse_code_translator as mct

pub fn main() {
let demo_encode_options =
mct.EncodeOptions(
output_dot: None,
output_dash: None,
output_space: None,
output_separator: None,
is_uppercase: None,
language: None,
)

let demo_decode_options =
mct.DecodeOptions(
input_dot: None,
input_dash: None,
input_space: None,
input_separator: None,
to_uppercase: None,
language: None,
skip_invalid_symbols: None,
)

" Test "
|> mct.encode(demo_encode_options, None)
|> result.map(io.println)
// "/ - . ... - /"

"/ - . ... - /"
|> mct.decode(demo_decode_options, None)
|> result.map(io.println)
// " test "

"demo"
|> mct.encode_to_string(demo_encode_options, None)
|> mct.decode_to_string(demo_decode_options, None)
|> io.println
// "demo"

"_.. . __ ___"
|> mct.decode_to_string(
mct.DecodeOptions(
..demo_decode_options,
input_dash: Some("_"),
language: Some(mct.language_cyrillic),
),
None,
)
|> io.println
// "демо"

let demo_convert_options =
mct.ConvertOptions(
input_dot: mct.default_dot,
output_dot: "0",
input_dash: mct.default_dash,
output_dash: "1",
input_space: mct.default_space,
output_space: mct.default_space,
input_separator: mct.default_separator,
output_separator: mct.default_separator,
)

"-.. . -- ---"
|> mct.convert(demo_convert_options)
|> result.map(io.println)
// "100 0 11 111"

"="
|> mct.convert_to_string(demo_convert_options)
|> io.println
// "Invalid morse code symbol: ="
}
```

Further documentation can be found at .

### Version 2.2.0

Version `2.2.0` contains backward incompatible changes.
If you are using `EncodeOptions` and `DecodeOptions`, change `language_num` to `language`.

## Web tool

### Manually set page language

Use this bookmarklet, save it as a bookmark, then open it while on the web page:

```javascript
javascript:(function(){window.mct.set_page_language(window.prompt('Enter language code')??'');})()
```

### Contributing

#### Add new page language

Open `index.html` and find all occurrences of `set_page_language`, `data-lo=`
and `dataset.lo =`, then add translations and send a pull request.

## Development

```sh
# just format
just build
just serve
```