Skip to content

Commit

Permalink
Merge branch 'main' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
salif committed Aug 23, 2024
2 parents 2e5b030 + d976964 commit 836c65a
Show file tree
Hide file tree
Showing 20 changed files with 374 additions and 377 deletions.
Empty file added .nojekyll
Empty file.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021,2024 Salif Mehmed
Copyright 2021,2024 Salif Mehmed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
62 changes: 43 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@

## Links

* [Homepage](https://salif.github.io/morse-code-translator/)
* [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)

## Usage
## Gleam library

### Installation

```sh
gleam add morse_code_translator
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() {
Expand All @@ -28,7 +33,7 @@ pub fn main() {
output_space: None,
output_separator: None,
is_uppercase: None,
language_num: None,
language: None,
)
let demo_decode_options =
Expand All @@ -38,35 +43,35 @@ pub fn main() {
input_space: None,
input_separator: None,
to_uppercase: None,
language_num: None,
language: None,
)
let demo_encode: Result(String, mct.MorseCodeError) =
mct.encode(" Test ", demo_encode_options, None)
io.debug(demo_encode)
// Ok("/ - . ... - /")
" Test "
|> mct.encode(demo_encode_options, None)
|> result.map(io.println)
// "/ - . ... - /"
let demo_decode: Result(String, mct.MorseCodeError) =
mct.decode("/ - . ... - /", demo_decode_options, None)
io.debug(demo_decode)
// Ok(" test ")
"/ - . ... - /"
|> 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.debug
|> io.println
// "demo"
"_.. . __ ___"
|> mct.decode_to_string(
mct.DecodeOptions(
..demo_decode_options,
input_dash: Some("_"),
language_num: Some(mct.language_num_cyrillic),
language: Some(mct.language_cyrillic),
),
None,
)
|> io.debug
|> io.println
// "демо"
let demo_convert_options =
Expand All @@ -83,20 +88,39 @@ pub fn main() {
"-.. . -- ---"
|> mct.convert(demo_convert_options)
|> io.debug
// Ok("100 0 11 111")
|> result.map(io.println)
// "100 0 11 111"
"="
|> mct.convert_to_string(demo_convert_options)
|> io.debug
|> io.println
// "Invalid morse code symbol: ="
}
```

### Version 2.2.0

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

Further documentation can be found at <https://hexdocs.pm/morse_code_translator>.

## Web tool

### 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.

### Manually set page language

Use <a href="javascript:(function(){window.set_page_language(window.prompt('Enter language code')??'');})()">this bookmarklet</a>, save it as bookmark, then open it at the web page.


## Development

```sh
# just format
just build
just serve
```
Empty file added build/dev/javascript/gleam.lock
Empty file.
4 changes: 0 additions & 4 deletions build/dev/javascript/gleam_stdlib/gleam/dict.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ export function upsert(dict, key, fun) {
return ((_capture) => { return insert(dict, key, _capture); })(_pipe$3);
}

export function update(dict, key, fun) {
return upsert(dict, key, fun);
}

function do_fold(loop$list, loop$initial, loop$fun) {
while (true) {
let list = loop$list;
Expand Down
18 changes: 6 additions & 12 deletions build/dev/javascript/gleam_stdlib/gleam/dynamic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import * as $dict from "../gleam/dict.mjs";
import * as $int from "../gleam/int.mjs";
import * as $list from "../gleam/list.mjs";
import * as $option from "../gleam/option.mjs";
import { Some } from "../gleam/option.mjs";
import * as $result from "../gleam/result.mjs";
import * as $string_builder from "../gleam/string_builder.mjs";
import {
identity as do_from,
identity as do_unsafe_coerce,
identity as from,
decode_bit_array,
classify_dynamic as do_classify,
decode_int,
Expand All @@ -30,6 +30,8 @@ import {
decode_string,
} from "../gleam_stdlib.mjs";

export { from };

export class DecodeError extends $CustomType {
constructor(expected, found, path) {
super();
Expand All @@ -39,14 +41,6 @@ export class DecodeError extends $CustomType {
}
}

export function from(a) {
return do_from(a);
}

export function unsafe_coerce(a) {
return do_unsafe_coerce(a);
}

export function dynamic(value) {
return new Ok(value);
}
Expand Down Expand Up @@ -255,8 +249,8 @@ export function optional_field(name, inner_type) {
return new Ok(new $option.None());
} else {
let dynamic_inner = maybe_inner[0];
let _pipe = dynamic_inner;
let _pipe$1 = decode_optional(_pipe, inner_type);
let _pipe = inner_type(dynamic_inner);
let _pipe$1 = $result.map(_pipe, (var0) => { return new Some(var0); });
return map_errors(
_pipe$1,
(_capture) => { return push_path(_capture, name); },
Expand Down
8 changes: 8 additions & 0 deletions build/dev/javascript/gleam_stdlib/gleam/float.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ export function product(numbers) {
}
}

export function modulo(dividend, divisor) {
if (divisor === 0.0) {
return new Error(undefined);
} else {
return new Ok(dividend - (floor(divideFloat(dividend, divisor)) * divisor));
}
}

export function divide(a, b) {
if (b === 0.0) {
return new Error(undefined);
Expand Down
20 changes: 5 additions & 15 deletions build/dev/javascript/gleam_stdlib/gleam/int.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
Ok,
Error,
toList,
prepend as listPrepend,
CustomType as $CustomType,
remainderInt,
divideInt,
} from "../gleam.mjs";
import { Ok, Error, toList, prepend as listPrepend, remainderInt, divideInt } from "../gleam.mjs";
import * as $float from "../gleam/float.mjs";
import * as $order from "../gleam/order.mjs";
import {
Expand All @@ -32,8 +24,6 @@ export {
bitwise_shift_right,
};

export class InvalidBase extends $CustomType {}

export function absolute_value(x) {
let $ = x >= 0;
if ($) {
Expand Down Expand Up @@ -65,7 +55,7 @@ export function to_base_string(x, base) {
if ($) {
return new Ok(do_to_base_string(x, base));
} else {
return new Error(new InvalidBase());
return new Error(undefined);
}
}

Expand Down Expand Up @@ -213,7 +203,7 @@ function do_digits(loop$x, loop$base, loop$acc) {
export function digits(x, base) {
let $ = base < 2;
if ($) {
return new Error(new InvalidBase());
return new Error(undefined);
} else {
return new Ok(do_digits(x, base, toList([])));
}
Expand All @@ -228,7 +218,7 @@ function do_undigits(loop$numbers, loop$base, loop$acc) {
return new Ok(acc);
} else if (numbers.atLeastLength(1) && (numbers.head >= base)) {
let digit = numbers.head;
return new Error(new InvalidBase());
return new Error(undefined);
} else {
let digit = numbers.head;
let rest = numbers.tail;
Expand All @@ -242,7 +232,7 @@ function do_undigits(loop$numbers, loop$base, loop$acc) {
export function undigits(numbers, base) {
let $ = base < 2;
if ($) {
return new Error(new InvalidBase());
return new Error(undefined);
} else {
return do_undigits(numbers, base, 0);
}
Expand Down
20 changes: 0 additions & 20 deletions build/dev/javascript/gleam_stdlib/gleam/order.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,6 @@ export function compare(a, b) {
}
}

export function max(a, b) {
if (a instanceof Gt) {
return new Gt();
} else if (a instanceof Eq && b instanceof Lt) {
return new Eq();
} else {
return b;
}
}

export function min(a, b) {
if (a instanceof Lt) {
return new Lt();
} else if (a instanceof Eq && b instanceof Gt) {
return new Eq();
} else {
return b;
}
}

export function reverse(orderer) {
return (a, b) => { return orderer(b, a); };
}
Expand Down
52 changes: 19 additions & 33 deletions build/dev/javascript/gleam_stdlib/gleam/uri.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -332,45 +332,31 @@ export function origin(uri) {
let scheme = uri.scheme;
let host = uri.host;
let port = uri.port;
if (scheme instanceof Some &&
if (host instanceof Some &&
scheme instanceof Some &&
scheme[0] === "https" &&
(isEqual(port, new Some(443)))) {
let origin$1 = new Uri(
scheme,
new None(),
host,
new None(),
"",
new None(),
new None(),
);
return new Ok(to_string(origin$1));
} else if (scheme instanceof Some &&
let h = host[0];
return new Ok($string.concat(toList(["https://", h])));
} else if (host instanceof Some &&
scheme instanceof Some &&
scheme[0] === "http" &&
(isEqual(port, new Some(80)))) {
let origin$1 = new Uri(
scheme,
new None(),
host,
new None(),
"",
new None(),
new None(),
);
return new Ok(to_string(origin$1));
} else if (scheme instanceof Some &&
let h = host[0];
return new Ok($string.concat(toList(["http://", h])));
} else if (host instanceof Some &&
scheme instanceof Some &&
((scheme[0] === "http") || (scheme[0] === "https"))) {
let h = host[0];
let s = scheme[0];
let origin$1 = new Uri(
scheme,
new None(),
host,
port,
"",
new None(),
new None(),
);
return new Ok(to_string(origin$1));
if (port instanceof Some) {
let p = port[0];
return new Ok(
$string.concat(toList([s, "://", h, ":", $int.to_string(p)])),
);
} else {
return new Ok($string.concat(toList([s, "://", h])));
}
} else {
return new Error(undefined);
}
Expand Down
Loading

0 comments on commit 836c65a

Please sign in to comment.