-module(telega@internal@utils). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/telega/internal/utils.gleam"). -export([normalize_url/1, normalize_webhook_path/1, random_string/1, seconds_to_milliseconds/1, current_time_ms/0, json_object_filter_nulls/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", 6). ?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", 14). ?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", 34). ?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, <>, Alphabet_length ) end. -file("src/telega/internal/utils.gleam", 30). ?DOC(false). -spec random_string(integer()) -> binary(). random_string(Length) -> do_random_string( Length, <<""/utf8>>, string:length( <<"useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"/utf8>> ) ). -file("src/telega/internal/utils.gleam", 45). ?DOC(false). -spec seconds_to_milliseconds(float()) -> float(). seconds_to_milliseconds(Time) -> Time * 1000.0. -file("src/telega/internal/utils.gleam", 52). ?DOC(false). -spec current_time_ms() -> integer(). current_time_ms() -> erlang:system_time() div 1000000. -file("src/telega/internal/utils.gleam", 56). ?DOC(false). -spec json_object_filter_nulls(list({binary(), gleam@json:json()})) -> gleam@json:json(). json_object_filter_nulls(Entries) -> Null = gleam@json:null(), _pipe = Entries, _pipe@1 = gleam@list:filter( _pipe, fun(Entry) -> {_, Value} = Entry, Value /= Null end ), gleam@json:object(_pipe@1).