Datatype

Module to generate various primitive values and data types.

Array

Returns an array with random strings and numbers.

Parameters

NameTypeDefaultDescription
lengthnumber10

Size of the returned array.

Returns: number | string[]

faker.datatype.array(length: number = 10): (string | number)[]
faker.datatype.array() // => ["XcoYpSoHZ]",43758,89177,96366,38344,79172,"RM...
faker.datatype.array() // [ 94099, 85352, 'Hz%T.C\\l;8', '|#gmtw3otS', '2>:rJ|3$&d', 56864, 'Ss2-p0RXSI', 51084, 2039, 'mNEU[.r0Vf' ]
faker.datatype.array(3) // [ 61845, 'SK7H$W3:d*', 'm[%7N8*GVK' ]

Big Int

Returns a BigInt number.

Parameters

NameTypeDefaultDescription
options?bigint | boolean | number | string | { ... }

Maximum value or options object.

options.max?bigint | boolean | number | stringmin + 999999999999999n

Upper bound for generated bigint.

options.min?bigint | boolean | number | string0n

Lower bound for generated bigint.

Returns: bigint

faker.datatype.bigInt(options?: bigint | boolean | number | string | {
  max: bigint | boolean | number | string,
  min: bigint | boolean | number | string
}): bigint
faker.datatype.bigInt() // 55422n
faker.datatype.bigInt(100n) // 52n
faker.datatype.bigInt({ min: 1000000n }) // 431433n
faker.datatype.bigInt({ max: 100n }) // 42n
faker.datatype.bigInt({ min: 10n, max: 100n }) // 36n

Boolean

Returns the boolean value true or false.

Returns: boolean

faker.datatype.boolean(): boolean
faker.datatype.boolean() // => true
faker.datatype.boolean() // false

Datetime

Returns a Date object using a random number of milliseconds since the Unix Epoch (1 January 1970 UTC).

Parameters

NameTypeDefaultDescription
optionsnumber | { ... }{}

Max number of milliseconds since unix epoch or options object.

options.max?number4102444800000

Upper bound for milliseconds since base date. When not provided or larger than 8640000000000000, 2100-01-01 is considered as maximum generated date.

options.min?number631152000000

Lower bound for milliseconds since base date. When not provided or smaller than -8640000000000000, 1990-01-01 is considered as minimum generated date.

Returns: Date

faker.datatype.datetime(options: number | {
  max: number,
  min: number
} = {}): Date
faker.datatype.datetime() // => "2050-05-15T16:19:19.092Z"
faker.datatype.datetime() // '2089-04-17T18:03:24.956Z'
faker.datatype.datetime(1893456000000) // '2022-03-28T07:00:56.876Z'
faker.datatype.datetime({ min: 1577836800000, max: 1893456000000 }) // '2021-09-12T07:13:00.255Z'

Float

Returns a single random floating-point number for the given precision or range and precision.

Parameters

NameTypeDefaultDescription
options?number | { ... }

Precision or options object.

options.max?number99999

Upper bound for generated number.

options.min?number0

Lower bound for generated number.

options.precision?number0.01

Precision of the generated number.

Returns: number

faker.datatype.float(options?: number | {
  max: number,
  min: number,
  precision: number
}): number
faker.datatype.float() // => 54880.8
faker.datatype.float() // 51696.36
faker.datatype.float(0.1) // 52023.2
faker.datatype.float({ min: 1000000 }) // 212859.76
faker.datatype.float({ max: 100 }) // 28.11
faker.datatype.float({ precision: 0.1 }) // 84055.3
faker.datatype.float({ min: 10, max: 100, precision: 0.001 }) // 57.315

Hexadecimal

Returns a hexadecimal number.

Parameters

NameTypeDefaultDescription
lengthnumber1

Length of the generated number.

Returns: string

faker.datatype.hexadecimal(length: number = 1): string
faker.datatype.hexadecimal() // => "0xc"
faker.datatype.hexadecimal() // '0xb'
faker.datatype.hexadecimal(10) // '0xaE13F044fb'

Json

Returns a string representing JSON object with 7 pre-defined properties.

Returns: string

faker.datatype.json(): string
faker.datatype.json() // => "{\"foo\":\"XcoYpSoHZ]\",\"bar\":43758,\"bike\"...
faker.datatype.json() // `{"foo":"mxz.v8ISij","bar":29154,"bike":8658,"a":"GxTlw$nuC:","b":40693,"name":"%'<FTou{7X","prop":"X(bd4iT>77"}`

Number

Returns a single random number between zero and the given max value or the given range with the specified precision. The bounds are inclusive.

Parameters

NameTypeDefaultDescription
optionsnumber | { ... }99999

Maximum value or options object.

options.max?numbermin + 99999

Upper bound for generated number.

options.min?number0

Lower bound for generated number.

options.precision?number1

Precision of the generated number.

Returns: number

faker.datatype.number(options: number | {
  max: number,
  min: number,
  precision: number
} = 99999): number
faker.datatype.number() // => 54881
faker.datatype.number() // 55422
faker.datatype.number(100) // 52
faker.datatype.number({ min: 1000000 }) // 431433
faker.datatype.number({ max: 100 }) // 42
faker.datatype.number({ precision: 0.01 }) // 64246.18
faker.datatype.number({ min: 10, max: 100, precision: 0.01 }) // 36.94

String

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

Parameters

NameTypeDefaultDescription
lengthnumber10

Length of the generated string. Max length is 2^20.

Returns: string

faker.datatype.string(length: number = 10): string
faker.datatype.string() // => "TXcoYpSoHZ"
faker.datatype.string() // 'Zo!.:*e>wR'
faker.datatype.string(5) // '6Bye8'

Uuid

Returns a UUID v4 (Universally Unique Identifier).

Returns: string

faker.datatype.uuid(): string
faker.datatype.uuid() // => "89bd9d8d-69a6-474e-8f46-7cc8796ed151"
faker.datatype.uuid() // '4136cd0b-d90b-4af7-b485-5d1ded8db252'