View Source Namor.Helpers (Namor v1.0.3)
Supporting functions for dictionaries and name generation.
Link to this section Summary
Functions
Reads word lists from a base folder and returns a parsed dictionary map.
Returns a word pattern for adjectives, nouns, and verbs in the proper order.
Generates a random salt from a character list that can be appended to a name for uniqueness.
Link to this section Functions
@spec get_dict!(binary() | atom(), binary()) :: Namor.Dictionary.t() | [binary()]
Reads word lists from a base folder and returns a parsed dictionary map.
A dictionary folder is expected to be a directory containing three files:
adjectives.txt
, nouns.txt
, and verbs.txt
. Each file should
have one word per line with no duplicate words.
If the dictionary name is set to a string, it will only attempt
to read the one file and return a single list instead of a map.
Raises a File.Error
exception if any of the dictionary files
are not found.
┌── reserved.txt
├── foobar/
│ ┌── adjectives.txt
│ ├── nouns.txt
│ └── verbs.txt
iex> Namor.Helpers.get_dict("reserved.txt")
["foo", "bar"]
iex> Namor.Helpers.get_dict(:foobar)
%{adjectives: ["foo"], nouns: ["bar"], verbs: ["baz"]}
If not provided, base_path
will fallback to Namor's internal dictionary
path.
Returns a word pattern for adjectives, nouns, and verbs in the proper order.
Only supports patterns with a size up to 4.
iex> Namor.Helpers.get_pattern(4)
[:adjectives, :nouns, :nouns, :verbs]
Generates a random salt from a character list that can be appended to a name for uniqueness.