Data Types

Data Types

Mockingbird provides a wide range of different Data Types for generating mock data. Most of these Data types come from faker.js (opens in a new tab).

All faker.js types are supported, and can be referenced in Mockingbird using the fully qualified name of the type, meaning both the module name and the type name, separated by a dot (.). For example, to use the faker.js type buildingNumber (opens in a new tab) you should use address.buildingNumber.

On top of faker.js types, Mockingbird also has some custom Data Types. These are types that aren't provided by faker.js but can be very useful. You can find the definitions of all the custom Data Types here (opens in a new tab).

Contributions to add new custom Data Types are welcome!

Mockingbird custom Data Types

This section documents the custom Data Types that are added on top of Faker.js. For documentation about Faker.js types, please see the Faker.js docs (opens in a new tab).

Note that all Mockingbird custom Data Types have the prefix mockingbird, e.g. mockingbird.osName.

pick

Takes an array of values, each loop of the generator picks a random item from the array. Values in the array can be any standard JSON types, e.g. numbers, strings, etc.

Parameters

  • values: an array of values

Returns

123

Example usage

"some_values": {
    "type": "mockingbird.pick",
    "params": [
        {
            "values": [
                123,
                456
            ]
        }
    ]
}

pickWeighted

Similar to values, but with a weighted random. An additional parameters allows you to set the weighted frequency of each item, giving you control over the random distribution.

Parameters

  • values: an array of values
  • weights: an array of numbers

Returns

123

Example usage

"values_weighted": {
    "type": "mockingbird.pickWeighted",
    "params": [
        {
            "values": [
                123,
                456,
                789
            ],
            "weights": [
                90,
                7,
                3
            ]
        }
    ]
}

pickType

Generates an a array of a given type and then pops value on each generation.

Parameters

  • type: a string, the type to generate, any of the faker's Datatype module types, e.g array, bigInt, boolean, datetime, float, hexadecimal, json, number, string, uuid.

  • length: a number, the length of the array to generate

Returns

123

datetimeNow

Take the current times and formats it into an ISO Date Time string (using toISOString()) with precision up to seconds.

Parameters

None

Returns

"2023-04-06T17:31:57"

Example usage

"my_datetime": {
    "type": "mockingbird.datetimeNow"
}

datetimeRecent

Uses Faker.js date.recent() (opens in a new tab) and formats it into an ISO Date Time string (using toISOString()) with precision up to seconds.

Parameters

None

Returns

"2023-04-06T17:31:57"

Example usage

"my_datetime": {
    "type": "mockingbird.datetimeRecent"
}

datetimeBetween

Uses Faker.js date.between (opens in a new tab) to generate a time between two boundaries, formats it as an ISO Date Time string (using toISOString()) with precision up to seconds.

Parameters

  • start: date string, start time boundary
  • end: date string, end time boundary

Returns

"2023-04-06T17:31:57"

Example usage

"date_between_boundaries": {
    "type": "mockingbird.datetimeBetween",
    "params": [
        {
            "start": "2020-01-01T00:00:00.000Z", 
            "end": "2030-01-01T00:00:00.000Z"
        }
    ]
}

timestampNow

Take the current time and formats it into an ISO Date Time string (using toISOString()) with precision to nanoseconds.

Parameters

None

Returns

2023-04-06T17:31:57.342Z

Example usage

"my_timestamp": {
    "type": "mockingbird.timestampNow"
}

browserName

A random browser name, from one of: "Chrome", "Firefox", "IE", "Opera".

Parameters

None

Returns

"Chrome"

Example usage

"my_browser": {
    "type": "mockingbird.browserName"
}

browserEngineName

A random browser engine name, from one of: "Blink", "Gecko", "Trident".

Parameters

None

Returns

"Blink"

Example usage

"my_browser_engine": {
    "type": "mockingbird.browserEngineName"
}

osName

A random operating system name, from one of: "Linux", "Windows", "Mac OS".

Parameters

None

Returns

"Mac OS"

Example usage

"my_operating_system": {
    "type": "mockingbird.osName"
}

searchEngineName

A random search engine name, from one of: "https://www.google.co.uk/ (opens in a new tab)", "https://www.bing.com/ (opens in a new tab)", "https://duckduckgo.com/ (opens in a new tab)", "https://yandex.com/ (opens in a new tab)", "https://yahoo.com (opens in a new tab)".

Parameters

None

Returns

"https://yahoo.com"

Example usage

"my_search_engine": {
    "type": "mockingbird.searchEngineName"
}

sequentialArray

Picks a value from an array sequentially, looping back to the start of the array when the end is reached.

Parameters

  • values: an array of values
  • iterations: number of iterations to return current value for

Returns

"state1"