View Source Namor (Namor v1.0.3)
A subdomain-safe name generator. Check out the README to get started.
Link to this section Summary
Functions
Generates a random name from a Namor dictionary.
Generates a random name from a custom dictionary.
Get Namor's dictionaries.
Get Namor's reserved word list.
Checks whether a value exists in Namor's list of reserved words.
Checks whether a value exists in a provided list of reserved words.
Checks whether a given value is a valid subdomain.
Appends a salt to a value.
Link to this section Types
@type dictionary_type() :: :default | :rugged
@type salt_type() :: :numbers | :letters | :mixed
Link to this section Functions
@spec generate( words: integer(), salt: integer(), salt_type: salt_type(), separator: binary(), dictionary: dictionary_type() ) :: {:ok, binary()} | {:error, atom()}
Generates a random name from a Namor dictionary.
Returns {:ok, name}
for a successfully generated name, or
{:error, reason}
if something goes wrong. See Custom Dictionaries
for instructions on how to use a custom dictionary.
options
Options
:words
- Number of words to generate. Must be <=4. Defaults to2
.:salt
- Length of the salt to append. Must be >=0. Defaults to0
.:salt_type
- Whether the salt should contain numbers, letters, or both. Defaults to:mixed
.:separator
- String to use as a separator between words. Defaults to-
.:dictionary
- Namor dictionary to use. Defaults to:default
.
error-reasons
Error Reasons
:dict_not_found
- Could not find the specified dictionary.
example
Example
iex> require Namor
Namor
iex> Namor.generate(words: 3, dictionary: :rugged)
{:ok, "savage-whiskey-stain"}
@spec generate( [ words: integer(), salt: integer(), salt_type: salt_type(), separator: binary() ], Namor.Dictionary.t() ) :: {:ok, binary()}
Generates a random name from a custom dictionary.
Returns {:ok, name}
for a successfully generated name. Takes the
same options as generate/1
with the exception of :dictionary
.
@spec get_dictionaries() :: %{required(binary()) => Namor.Dictionary.t()}
Get Namor's dictionaries.
@spec get_reserved() :: [binary()]
Get Namor's reserved word list.
Checks whether a value exists in Namor's list of reserved words.
See reserved?/2
for more info. See Custom Dictionaries
for instructions on how to use a custom reserved word list.
Checks whether a value exists in a provided list of reserved words.
Before checking, the value is stripped of all special characters.
So for example, log-in
will still return true if ["login"]
is
passed to reserved
.
Checks whether a given value is a valid subdomain.
Valid subdomains contain no special characters other than -
, and
are 63 characters or less.
Appends a salt to a value.
If you want to use a custom charlist for the salt, use
Namor.Helpers.get_salt/2
instead.