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, add_many_if_present/2, wrap_tuple/2, 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(FFS), gleam@option:option(FFS)) -> list(FFS).
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, FFW} | {error, FFW}) -> FFW.
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 add_many_if_present(list(FFZ), gleam@option:option(list(FFZ))) -> list(FFZ).
add_many_if_present(D, Value) ->
_pipe = Value,
_pipe@1 = gleam@option:unwrap(_pipe, []),
lists:append(_pipe@1, D).
-file("src/flwr_oauth2/helpers.gleam", 29).
-spec wrap_tuple(FGE, FGF) -> {FGE, FGF}.
wrap_tuple(Name, Value) ->
{Name, Value}.
-file("src/flwr_oauth2/helpers.gleam", 33).
-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(_capture) -> wrap_tuple(<<"redirect_uri"/utf8>>, _capture) end
).
-file("src/flwr_oauth2/helpers.gleam", 65).
-spec concat_strings(binary(), binary()) -> binary().
concat_strings(Left, Right) ->
<<Left/binary, Right/binary>>.
-file("src/flwr_oauth2/helpers.gleam", 46).
-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", 42).
?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).