Fab.String (fab v1.2.2)
Functions for generating random strings.
Summary
Functions
Returns a random string consisting of letters from the English alphabet.
Returns a random string consisting of numbers and letters from the English alphabet.
Returns a random string consisting of symbols, numbers and letters from the English alphabet.
Returns a random string from the given characters.
Returns a random string consisting of numbers.
Returns a random string consisting of ASCII symbol characters.
Types
@type case_t() :: {:case, :lower | :mixed | :upper}
@type exclude_t() :: {:exclude, [String.t()]}
@type max_t() :: {:max, pos_integer()}
@type min_t() :: {:min, pos_integer()}
Functions
Returns a random string consisting of letters from the English alphabet.
Options
:case
- Case of the characters. Can be:lower
,:mixed
or:upper
. Defaults to:mixed
.:exclude
- List of characters to exclude from the result:min
- Minimum number of characters to generate:max
- Maximum number of characters to generate
Examples
iex> Fab.String.alpha()
"b"
iex> Fab.String.alpha(5)
"beTko"
iex> Fab.String.alpha(case: :lower)
"b"
iex> Fab.String.alpha(case: :upper)
"B"
iex> Fab.String.alpha(exclude: ["j"])
"h"
iex> Fab.String.alpha(min: 5, max: 10)
"beTkoB"
Returns a random string consisting of numbers and letters from the English alphabet.
Options
:case
- Case of the characters. Can be:lower
,:mixed
or:upper
. Defaults to:mixed
.:exclude
- List of characters to exclude from the result:min
- Minimum number of characters to generate:max
- Maximum number of characters to generate
Examples
iex> Fab.String.alphanumeric()
"c"
iex> Fab.String.alphanumeric(5)
"cuCMf"
iex> Fab.String.alphanumeric(case: :lower)
"6"
iex> Fab.String.alphanumeric(case: :upper)
"6"
iex> Fab.String.alphanumeric(exclude: ["q"])
"Z"
iex> Fab.String.alphanumeric(min: 5, max: 10)
"cuCMf7jVfe"
Returns a random string consisting of symbols, numbers and letters from the English alphabet.
Options
:case
- Case of the characters. Can be:lower
,:mixed
or:upper
. Defaults to:mixed
.:exclude
- List of characters to exclude from the result:min
- Minimum number of characters to generate:max
- Maximum number of characters to generate
Examples
iex> Fab.String.any()
"`"
iex> Fab.String.any(5)
"`>9k@"
iex> Fab.String.any(case: :lower)
"9"
iex> Fab.String.any(case: :upper)
"9"
iex> Fab.String.any(exclude: ["&"])
"u"
iex> Fab.String.any(min: 5, max: 10)
"`>9k@*5'b"
@spec from_characters( String.t() | [String.t()], non_neg_integer() | [max_t() | min_t()] ) :: String.t()
Returns a random string from the given characters.
Options
:min
- Minimum number of characters to generate:max
- Maximum number of characters to generate
Examples
iex> Fab.String.from_characters(["a", "b", "c"])
"a"
iex> Fab.String.from_characters("abc")
"a"
iex> Fab.String.from_characters("abc", 5)
"abbba"
iex> Fab.String.from_characters("abc", min: 5, max: 10)
"abbbaca"
@spec numeric(non_neg_integer() | [exclude_t() | max_t() | min_t()]) :: String.t()
Returns a random string consisting of numbers.
Options
:exclude
- List of characters to exclude from the result:min
- Minimum number of characters to generate:max
- Maximum number of characters to generate
Examples
iex> Fab.String.numeric()
"4"
iex> Fab.String.numeric(5)
"40427"
iex> Fab.String.numeric(exclude: ["1"])
"6"
iex> Fab.String.numeric(min: 5, max: 10)
"4042773592"
@spec symbol(non_neg_integer() | [exclude_t() | max_t() | min_t()]) :: String.t()
Returns a random string consisting of ASCII symbol characters.
Symbols
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
Options
:exclude
- List of characters to exclude from the result:min
- Minimum number of characters to generate:max
- Maximum number of characters to generate
Examples
iex> Fab.String.symbol()
"}"
iex> Fab.String.symbol(5)
"}&$^!"
iex> Fab.String.symbol(exclude: ["!"])
"("
iex> Fab.String.symbol(min: 5, max: 10)
"}&$^!]?)`"