Generating a string consisting of letters in the English alphabet.
Optional
options: Either the length of the string to generate or the optional options object.
Optional
casing?: CasingThe casing of the characters.
Optional
exclude?: string | readonly LiteralUnion<AlphaChar, string>[]An array with characters which should be excluded in the generated string.
Optional
length?: number | { max: number; min: number }The length of the string to generate either as a fixed length or as a length range.
faker.string.alpha() // 'b'
faker.string.alpha(10) // 'fEcAaCVbaR'
faker.string.alpha({ length: { min: 5, max: 10 } }) // 'HcVrCf'
faker.string.alpha({ casing: 'lower' }) // 'r'
faker.string.alpha({ exclude: ['W'] }) // 'Z'
faker.string.alpha({ length: 5, casing: 'upper', exclude: ['A'] }) // 'DTCIC'
Generating a string consisting of alpha characters and digits.
Optional
options: Either the length of the string to generate or the optional options object.
Optional
casing?: CasingThe casing of the characters.
Optional
exclude?: string | readonly LiteralUnion<AlphaNumericChar, string>[]An array of characters and digits which should be excluded in the generated string.
Optional
length?: number | { max: number; min: number }The length of the string to generate either as a fixed length or as a length range.
faker.string.alphanumeric() // '2'
faker.string.alphanumeric(5) // '3e5V7'
faker.string.alphanumeric({ length: { min: 5, max: 10 } }) // 'muaApG'
faker.string.alphanumeric({ casing: 'upper' }) // 'A'
faker.string.alphanumeric({ exclude: ['W'] }) // 'r'
faker.string.alphanumeric({ length: 5, exclude: ["a"] }) // 'x1Z7f'
Returns a binary string.
Optional
options: { length?: number | { max: number; min: number }; prefix?: string }The optional options object.
Optional
length?: number | { max: number; min: number }The length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
Optional
prefix?: stringPrefix for the generated number.
Generates a string from the given characters.
The characters to use for the string. Can be a string or an array of characters. If it is an array, then each element is treated as a single character even if it is a string with multiple characters.
Optional
length: number | { max: number; min: number }The length of the string to generate either as a fixed length or as a length range. Defaults to 1
.
The maximum length of the string to generate.
The minimum length of the string to generate.
Returns a hexadecimal string.
Optional
options: {The optional options object.
Optional
casing?: CasingCasing of the generated number.
Optional
length?: number | { max: number; min: number }The length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
Optional
prefix?: stringPrefix for the generated number.
faker.string.hexadecimal() // '0xB'
faker.string.hexadecimal({ length: 10 }) // '0xaE13d044cB'
faker.string.hexadecimal({ length: { min: 5, max: 10 } }) // '0x7dEf7FCD'
faker.string.hexadecimal({ prefix: '0x' }) // '0xE'
faker.string.hexadecimal({ casing: 'lower' }) // '0xf'
faker.string.hexadecimal({ length: 10, prefix: '#' }) // '#f12a974eB1'
faker.string.hexadecimal({ length: 10, casing: 'upper' }) // '0xE3F38014FB'
faker.string.hexadecimal({ casing: 'lower', prefix: '' }) // 'd'
faker.string.hexadecimal({ length: 10, casing: 'mixed', prefix: '0x' }) // '0xAdE330a4D1'
Generates a Nano ID.
Optional
length: number | { max: number; min: number }The length of the string to generate either as a fixed length or as a length range. Defaults to 21
.
The maximum length of the Nano ID to generate.
The minimum length of the Nano ID to generate.
Generates a given length string of digits.
Optional
options: Either the length of the string to generate or the optional options object.
Optional
allowLeadingZeros?: booleanWhether leading zeros are allowed or not.
Optional
exclude?: string | readonly LiteralUnion<NumericChar, string>[]An array of digits which should be excluded in the generated string.
Optional
length?: number | { max: number; min: number }The length of the string to generate either as a fixed length or as a length range.
faker.string.numeric() // '2'
faker.string.numeric(5) // '31507'
faker.string.numeric(42) // '06434563150765416546479875435481513188548'
faker.string.numeric({ length: { min: 5, max: 10 } }) // '197089478'
faker.string.numeric({ length: 42, allowLeadingZeros: false }) // '72564846278453876543517840713421451546115'
faker.string.numeric({ length: 6, exclude: ['0'] }) // '943228'
Returns an octal string.
Optional
options: { length?: number | { max: number; min: number }; prefix?: string }The optional options object.
Optional
length?: number | { max: number; min: number }The length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
Optional
prefix?: stringPrefix for the generated number.
Returns a string containing UTF-16 chars between 33 and 125 (!
to }
).
Optional
length: number | { max: number; min: number }The length of the string (excluding the prefix) to generate either as a fixed length or as a length range. Defaults to 10
.
The maximum length of the string to generate.
The minimum length of the string to generate.
Returns a string containing only special characters from the following list:
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
Optional
length: number | { max: number; min: number }The length of the string to generate either as a fixed length or as a length range. Defaults to 1
.
The maximum length of the string to generate.
The minimum length of the string to generate.
Returns a ULID (Universally Unique Lexicographically Sortable Identifier).
Optional
options: { refDate?: string | number | Date }The optional options object.
Optional
refDate?: string | number | DateThe 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.
Returns a UUID v4 (Universally Unique Identifier).
Module to generate string related entries.
Overview
For a string containing just A-Z characters, use
alpha()
. To add digits too, usealphanumeric()
. If you only want punctuation marks/symbols, usesymbol()
. For a full set of ASCII characters, usesample()
. For a custom set of characters, usefromCharacters()
.For strings of base-ten digits, use
numeric()
. For other bases, usebinary()
,octal()
, orhexadecimal()
).You can generate standard ID strings using
uuid()
ornanoid()
.Related modules
faker.internet.emoji()
.faker.helpers
module includes a number of string related methods.