Current section
Files
Jump to
Current section
Files
src/flwr_oauth2@helpers.erl
-module(flwr_oauth2@helpers).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/flwr_oauth2/helpers.gleam").
-export([add_if_present/2, unwrap_both/1, encode_redirect_uri/1, generate_random_string/2]).
-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(" Helper functions\n").
-file("src/flwr_oauth2/helpers.gleam", 10).
?DOC(" Appends the value if present a given list\n").
-spec add_if_present(list(FGB), gleam@option:option(FGB)) -> list(FGB).
add_if_present(D, Value) ->
_pipe = [Value],
_pipe@1 = gleam@option:values(_pipe),
lists:append(_pipe@1, D).
-file("src/flwr_oauth2/helpers.gleam", 16).
-spec unwrap_both({ok, FGF} | {error, FGF}) -> FGF.
unwrap_both(Res) ->
case Res of
{ok, Res@1} ->
Res@1;
{error, Res@2} ->
Res@2
end.
-file("src/flwr_oauth2/helpers.gleam", 23).
-spec encode_redirect_uri(gleam@option:option(gleam@uri:uri())) -> gleam@option:option({binary(),
binary()}).
encode_redirect_uri(Value) ->
_pipe = Value,
_pipe@1 = gleam@option:map(_pipe, fun gleam@uri:to_string/1),
gleam@option:map(_pipe@1, fun(X) -> {<<"redirect_uri"/utf8>>, X} end).
-file("src/flwr_oauth2/helpers.gleam", 58).
-spec concat_strings(binary(), binary()) -> binary().
concat_strings(Left, Right) ->
<<Left/binary, Right/binary>>.
-file("src/flwr_oauth2/helpers.gleam", 39).
-spec generate_random_string_rec(binary(), integer(), integer(), binary()) -> binary().
generate_random_string_rec(Generated, Index, Length, Chars) ->
case Index =:= Length of
true ->
Generated;
false ->
_pipe = Chars,
_pipe@1 = string:length(_pipe),
_pipe@2 = gleam@int:random(_pipe@1),
_pipe@3 = gleam@string:slice(Chars, _pipe@2, 1),
_pipe@4 = concat_strings(Generated, _pipe@3),
generate_random_string_rec(_pipe@4, Index + 1, Length, Chars)
end.
-file("src/flwr_oauth2/helpers.gleam", 32).
?DOC(" Generates a random string from a given list of characters with a given length\n").
-spec generate_random_string(binary(), integer()) -> binary().
generate_random_string(Chars, Length) ->
generate_random_string_rec(<<""/utf8>>, 0, Length, Chars).