Random

Generates random values of different kinds.

Alpha

Generating a string consisting of letters in the English alphabet.

Parameters

NameTypeDefaultDescription
optionsnumber | { ... }{}

Either the number of characters or an options instance.

options.bannedChars?readonly LiteralUnion<AlphaChar, string>[] | string[]

An array with characters to exclude.

options.casing?Casing'lower'

The casing of the characters.

options.count?number1

The number of characters to generate.

options.upcase?boolean

Missing

Returns: string

faker.random.alpha(options: number | {
  bannedChars: readonly LiteralUnion<AlphaChar, string>[] | string,
  casing: Casing,
  count: number,
  upcase: boolean
} = {}): string
faker.random.alpha() // => "o"
faker.random.alpha() // 'b'
faker.random.alpha(10) // 'qccrabobaf'
faker.random.alpha({ count: 5, casing: 'upper', bannedChars: ['A'] }) // 'DTCIC'

Alpha Numeric

Generating a string consisting of alpha characters and digits.

Parameters

NameTypeDefaultDescription
countnumber1

The number of characters and digits to generate.

options{ ... }{}

The options to use.

options.bannedChars?readonly LiteralUnion<AlphaNumericChar, string>[] | string[]

An array of characters and digits which should be banned in the generated string.

options.casing?Casing'lower'

The casing of the characters.

Returns: string

faker.random.alphaNumeric(count: number = 1, options: {
  bannedChars: readonly LiteralUnion<AlphaNumericChar, string>[] | string,
  casing: Casing
} = {}): string
faker.random.alphaNumeric() // => "j"
faker.random.alphaNumeric() // '2'
faker.random.alphaNumeric(5) // '3e5v7'
faker.random.alphaNumeric(5, { bannedChars: ["a"] }) // 'xszlm'

Locale

Returns a random locale, that is available in this faker instance. You can use the returned locale with faker.setLocale(result).

Returns: string

faker.random.locale(): string
faker.random.locale() // => "hu"
faker.random.locale() // 'el'

Numeric

Generates a given length string of digits.

Parameters

NameTypeDefaultDescription
lengthnumber1

The number of digits to generate.

options{ ... }{}

The options to use.

options.allowLeadingZeros?booleanfalse

If true, leading zeros will be allowed.

options.bannedDigits?readonly LiteralUnion<NumericChar, string>[] | string[]

An array of digits which should be banned in the generated string.

Returns: string

faker.random.numeric(length: number = 1, options: {
  allowLeadingZeros: boolean,
  bannedDigits: readonly LiteralUnion<NumericChar, string>[] | string
} = {}): string
faker.random.numeric() // => "5"
faker.random.numeric() // '2'
faker.random.numeric(5) // '31507'
faker.random.numeric(42) // '56434563150765416546479875435481513188548'
faker.random.numeric(42, { allowLeadingZeros: true }) // '00564846278453876543517840713421451546115'
faker.random.numeric(6, { bannedDigits: ['0'] }) // '943228'

Word

Returns random word.

Returns: string

faker.random.word(): string
faker.random.word() // => "Montenegro"
faker.random.word() // 'Seamless'

Words

Returns string with set of random words.

Parameters

NameTypeDefaultDescription
count?number

Number of words. Defaults to a random value between 1 and 3.

Returns: string

faker.random.words(count?: number): string
faker.random.words() // => "Account Loan"
faker.random.words() // 'neural'
faker.random.words(5) // 'copy Handcrafted bus client-server Point'