Current section
Files
Jump to
Current section
Files
src/telega@internal@utils.erl
-module(telega@internal@utils).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/telega/internal/utils.gleam").
-export([normalize_url/1, normalize_webhook_path/1, random_string/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-file("src/telega/internal/utils.gleam", 4).
?DOC(false).
-spec normalize_url(binary()) -> binary().
normalize_url(Url) ->
Url@1 = gleam@string:trim(Url),
case gleam_stdlib:string_ends_with(Url@1, <<"/"/utf8>>) of
true ->
gleam@string:drop_end(Url@1, 1);
_ ->
Url@1
end.
-file("src/telega/internal/utils.gleam", 12).
?DOC(false).
-spec normalize_webhook_path(binary()) -> binary().
normalize_webhook_path(Webhook_path) ->
Webhook_path@1 = gleam@string:trim(Webhook_path),
Webhook_path@2 = case gleam_stdlib:string_ends_with(
Webhook_path@1,
<<"/"/utf8>>
) of
true ->
gleam@string:drop_end(Webhook_path@1, 1);
_ ->
Webhook_path@1
end,
case gleam_stdlib:string_starts_with(Webhook_path@2, <<"/"/utf8>>) of
true ->
gleam@string:drop_start(Webhook_path@2, 1);
_ ->
Webhook_path@2
end.
-file("src/telega/internal/utils.gleam", 32).
?DOC(false).
-spec do_random_string(integer(), binary(), integer()) -> binary().
do_random_string(N, Acc, Alphabet_length) ->
case N of
0 ->
Acc;
_ ->
Index = gleam@int:random(Alphabet_length),
Char = gleam@string:slice(
<<"useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"/utf8>>,
Index,
1
),
do_random_string(
N - 1,
<<Acc/binary, Char/binary>>,
Alphabet_length
)
end.
-file("src/telega/internal/utils.gleam", 28).
?DOC(false).
-spec random_string(integer()) -> binary().
random_string(Length) ->
do_random_string(
Length,
<<""/utf8>>,
string:length(
<<"useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"/utf8>>
)
).