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=1, casing="lower", exclude=["item"])

Example return values:

  • R

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=1, casing="lower", exclude=["item"])

Example return values:

  • s

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:

  • 0b0

string.counterString

Generates a counterstring for a random length between min and max (or fixed length when only one value is provided). Defaults to min=1 and max=25 when omitted.

ArgTypeRequiredDescription
minintegernoMinimum counterstring length (integer). If max is omitted and min is provided, min is also used as max. Defaults to 1 when omitted. Non-integer values throw an exception.
maxintegernoMaximum counterstring length (integer). If less than min, values are swapped. Defaults to 25 when omitted. Non-integer values throw an exception.
delimiterstringnoDelimiter character used between position markers. Defaults to "*".

Examples:

string.counterString()
string.counterString(15)
string.counterString(min=5, max=12)
string.counterString(min=12, max=12, delimiter="#")

Example return values:

  • *3*5*7*9*12*15*
  • #3#5#7#9#12#

string.fromCharacters

Generates a string from the given characters.

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

Examples:

string.fromCharacters("ABC123", 6)
string.fromCharacters(characters=["A", "B", "C"], length=4)

Example return values:

  • A1B2
  • CB2A

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:

  • 0x1

string.nanoid

Generates a Nano ID.

ArgTypeRequiredDescription
lengthnumbernoExact number of characters to generate.

Examples:

string.nanoid()
string.nanoid(length=1)

Example return values:

  • KLm49ferlh-eUmJpZdSIO

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=1, allowLeadingZeros=true, exclude=["item"])

Example return values:

  • 7

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:

  • 0o6

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=1)

Example return values:

  • \Fw;0e:G.H

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=1)

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:

  • 01KQADM2A0728G4D2HKCPWKS6N

string.uuid

Returns a UUID v4 (Universally Unique Identifier).

No parameters.

Examples:

string.uuid()

Example return values:

  • 0628ae51-7b6c-4d33-9f24-dae19fb245df