NeoFaker.Text (neo_faker v0.15.0)

Copy Markdown View Source

Functions for generating random text.

Provides utilities to generate single characters, multi-character strings, emojis, and words from common word lists. All character generators support type filtering (alphabet, digits, or mixed alphanumeric).

Summary

Functions

Generates a single random character.

Generates a string of random characters.

Generates a random emoji.

Generates a random word from a common English word list.

Generates multiple random words.

Functions

character(opts \\ [])

(since 0.8.0)
@spec character(keyword()) :: String.t()

Generates a single random character.

Returns a single character from the alphanumeric set by default.

Options

  • :type (an atom below, or nil) - the character pool to draw from. Defaults to nil (the full alphanumeric set).
    • :alphabet_lower - lowercase letters only.
    • :alphabet_upper - uppercase letters only.
    • :alphabet - any letter (lower or upper).
    • :digit - a digit (0–9).

Examples

iex> NeoFaker.Text.character()
"a"

iex> NeoFaker.Text.character(type: :digit)
"0"

iex> NeoFaker.Text.character(type: :alphabet_lower)
"z"

iex> NeoFaker.Text.character(type: :alphabet_upper)
"A"

iex> NeoFaker.Text.character(type: :alphabet)
"X"

characters(number \\ 11, opts \\ [])

(since 0.8.0)
@spec characters(pos_integer(), keyword()) :: String.t()

Generates a string of random characters.

Calls character/1 number times and joins the results into a single string. number defaults to 11.

Options

  • :type (see character/1's :type option) - the character pool to draw from. Defaults to nil (the full alphanumeric set).

Examples

iex> NeoFaker.Text.characters()
"XfELJU1mRMg"

iex> NeoFaker.Text.characters(20, type: :alphabet_upper)
"BVAJHRGSCEVJFNYSWCJE"

iex> NeoFaker.Text.characters(5, type: :digit)
"74392"

iex> NeoFaker.Text.characters(10, type: :alphabet_lower)
"xyzabcdefg"

emoji(opts \\ [])

(since 0.8.0)
@spec emoji(keyword()) :: String.t()

Generates a random emoji.

Returns a random emoji from the specified category, or from all categories by default.

Options

  • :category (an atom below) - the emoji category. Defaults to :all.
    • :all - any category.
    • :activities - activities.
    • :animals_and_nature - animals and nature.
    • :food_and_drink - food and drink.
    • :objects - objects.
    • :people_and_body - people and body.
    • :smileys_and_emotion - smileys and emotion.
    • :symbols - symbols.
    • :travel_and_places - travel and places.

Examples

iex> NeoFaker.Text.emoji()
"✨"

iex> NeoFaker.Text.emoji(category: :activities)
"🎉"

iex> NeoFaker.Text.emoji(category: :smileys_and_emotion)
"😀"

iex> NeoFaker.Text.emoji(category: :animals_and_nature)
"🐶"

word()

(since 0.8.0)
@spec word() :: String.t()

Generates a random word from a common English word list.

Examples

iex> NeoFaker.Text.word()
"computer"

words(count \\ 5)

(since 0.8.0)
@spec words(pos_integer()) :: [String.t()]

Generates multiple random words.

Returns a list of words. count sets how many are generated and defaults to 5. Join them yourself with Enum.join/2 if you need a single string.

Examples

iex> NeoFaker.Text.words(3)
["computer", "elixir", "phoenix"]