-module(roundabout@internal@name). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/roundabout/internal/name.gleam"). -export([new/1, unsafe/1, type_name/1, parameter_name/1, is_root/1]). -export_type([as_name/0, name/0]). -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). -type as_name() :: as_type_name | as_parameter_name. -opaque name() :: {name, binary()}. -file("src/roundabout/internal/name.gleam", 13). ?DOC(false). -spec new(binary()) -> {ok, name()} | {error, binary()}. new(Name) -> Re@1 = case gleam@regexp:from_string(<<"^[a-zA-Z][a-zA-Z0-9 _-]*$"/utf8>>) of {ok, Re} -> Re; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"roundabout/internal/name"/utf8>>, function => <<"new"/utf8>>, line => 14, value => _assert_fail, start => 187, 'end' => 254, pattern_start => 198, pattern_end => 204}) end, Candidate = justin:kebab_case(Name), case gleam@regexp:check(Re@1, Candidate) of true -> {ok, {name, Candidate}}; false -> {error, <<"Invalid name "/utf8, Name/binary>>} end. -file("src/roundabout/internal/name.gleam", 24). ?DOC(false). -spec unsafe(binary()) -> name(). unsafe(Value) -> {name, Value}. -file("src/roundabout/internal/name.gleam", 28). ?DOC(false). -spec type_name(name()) -> binary(). type_name(Input) -> justin:pascal_case(erlang:element(2, Input)). -file("src/roundabout/internal/name.gleam", 32). ?DOC(false). -spec parameter_name(name()) -> binary(). parameter_name(Input) -> justin:snake_case(erlang:element(2, Input)). -file("src/roundabout/internal/name.gleam", 36). ?DOC(false). -spec is_root(name()) -> boolean(). is_root(Input) -> erlang:element(2, Input) =:= <<""/utf8>>.