Datatype
Module to generate various primitive values and data types.
Array
Returns an array with random strings and numbers.
Parameters
Name | Type | Default | Description |
---|---|---|---|
length | number | 10 | 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
Name | Type | Default | Description |
---|---|---|---|
value? | bigint | boolean | number | string | When provided, this method simply converts it to |
Returns: bigint
faker.datatype.bigInt(value?: bigint | boolean | number | string): bigint
faker.datatype.bigInt() // 8507209999914928n
faker.datatype.bigInt('156') // 156n
faker.datatype.bigInt(30) // 30n
faker.datatype.bigInt(3000n) // 3000n
faker.datatype.bigInt(true) // 1n
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
Name | Type | Default | Description |
---|---|---|---|
options? | number | { ... } | Max number of milliseconds since unix epoch or options object | |
options.max? | number | Upper bound for milliseconds since base date.
When not provided or larger than | |
options.min? | number | 633880849813 | Lower bound for milliseconds since base date.
When not provided or smaller than |
Returns: Date
faker.datatype.datetime(options?: number | {
max: number,
min: number
}): Date
faker.datatype.datetime() // => "2050-05-15T16:19:19.092Z"
Float
Returns a single random floating-point number for the given precision or range and precision.
Parameters
Name | Type | Default | Description |
---|---|---|---|
options? | number | { ... } | Precision or options object. | |
options.max? | number | 99999 | Upper bound for generated number. |
options.min? | number | 0 | Lower bound for generated number. |
options.precision? | number | 0.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
Hexa Decimal
Deprecated
This method is deprecated and will be removed in a future version.
Returns a hexadecimal number.
Parameters
Name | Type | Default | Description |
---|---|---|---|
length | number | 1 | 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'
See Also
Hexadecimal
Returns a hexadecimal number.
Parameters
Name | Type | Default | Description |
---|---|---|---|
length | number | 1 | 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
Name | Type | Default | Description |
---|---|---|---|
options | number | { ... } | 99999 | Maximum value or options object. |
options.max? | number | min + 99999 | Upper bound for generated number. |
options.min? | number | 0 | Lower bound for generated number. |
options.precision? | number | 1 | 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
Name | Type | Default | Description |
---|---|---|---|
length | number | 10 | Length of the generated string. Max length is |
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'