Skip to main content

string Domain

The string domain maps domain keywords to underlying faker implementations.

Faker Documentation

Methods

string.alpha

Generating a string consisting of letters in the English alphabet.

ArgTypeRequiredDescription
lengthnumbernoDesired length of the generated value.
casingstringnoThe casing of the characters.
excludearraynoAn array with characters which should be excluded in the generated string.

Examples:

string.alpha()
string.alpha(length=5, casing="lower", exclude=["a"])

Example return values:

  • "S"
  • "u"

string.alphanumeric

Generating a string consisting of alpha characters and digits.

ArgTypeRequiredDescription
lengthnumbernoDesired length of the generated value.
casingstringnoThe casing of the characters.
excludearraynoAn array of characters and digits which should be excluded in the generated string.

Examples:

string.alphanumeric()
string.alphanumeric(length=5, casing="lower", exclude=["a", "1"])

Example return values:

  • "D"
  • "K"

string.binary

Returns a binary string.

ArgTypeRequiredDescription
lengthnumbernoThe length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
prefixstringnoPrefix for the generated number.

Examples:

string.binary()
string.binary(length=1, prefix="#")

Example return values:

  • "0b1"

string.fromCharacters

Generates a string from the given characters.

ArgTypeRequiredDescription
charactersstring|arrayyesCharacter set (string or array) used when generating output.
lengthnumbernoDesired length of the generated value.

Examples:

string.fromCharacters("sample")
string.fromCharacters(characters="abcdef", length=3)

Example return values:

  • "m"
  • "l"

string.hexadecimal

Returns a hexadecimal string.

ArgTypeRequiredDescription
casingstringnoCasing of the generated number.
lengthnumbernoThe length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
prefixstringnoPrefix for the generated number.

Examples:

string.hexadecimal()
string.hexadecimal(casing="lower", length=1, prefix="#")

Example return values:

  • "0xd"
  • "0xB"

string.nanoid

Generates a Nano ID.

ArgTypeRequiredDescription
lengthnumbernoExact number of characters to generate.

Examples:

string.nanoid()
string.nanoid(length=10)

Example return values:

  • "bt_JjqxXXh9GHz1MALPW2"
  • "mjTRAlIjzdQ5Tg9rjv57R"

string.numeric

Generates a given length string of digits.

ArgTypeRequiredDescription
lengthnumbernoDesired length of the generated value.
allowLeadingZerosbooleannoWhether leading zeros are allowed or not.
excludearraynoAn array of digits which should be excluded in the generated string.

Examples:

string.numeric()
string.numeric(length=5, allowLeadingZeros=true, exclude=["0"])

Example return values:

  • "4"
  • "0"

string.octal

Returns an octal string.

ArgTypeRequiredDescription
lengthnumbernoThe length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
prefixstringnoPrefix for the generated number.

Examples:

string.octal()
string.octal(length=1, prefix="#")

Example return values:

  • "0o1"
  • "0o3"

string.sample

Returns a string containing UTF-16 chars between 33 and 125 (! to }).

ArgTypeRequiredDescription
lengthnumbernoExact number of characters to generate.

Examples:

string.sample()
string.sample(length=10)

Example return values:

  • "R4A;9BcLzj"
  • "XARt%ku=7"`

string.symbol

Returns a string containing only special characters from the following list:

ArgTypeRequiredDescription
lengthnumbernoExact number of characters to generate.

Examples:

string.symbol()
string.symbol(length=3)

Example return values:

  • "/"
  • "_"

string.ulid

Returns a ULID (Universally Unique Lexicographically Sortable Identifier).

ArgTypeRequiredDescription
refDatenumbernoThe date to use as reference point for the newly generated ULID encoded timestamp. The encoded timestamp is represented by the first 10 characters of the result.

Examples:

string.ulid()
string.ulid(refDate=1)

Example return values:

  • "01KRXH5AE8V36069S9HB6G3CKY"
  • "01KRXH5AE8FNGNXFP3JBW5NJXW"

string.uuid

Returns a UUID v4 (Universally Unique Identifier).

No arguments.

Examples:

string.uuid()

Example return values:

  • "522928a9-04aa-4ec4-948a-5bbbfe882f64"
  • "bd37a9cb-1f37-4d4a-aa6f-9681735bd00a"