In addition to Handlebars' built-in helpers, Mockoon offers the following helpers:
Strings | Dates | Misc | |
---|---|---|---|
includes | stringify | now | newline |
substr | concat | dateTimeShift | base64 |
lowercase | indexOf | date | base64Decode |
uppercase | parseInt | time | objectId |
split | dateFormat | setVar |
Faker.js aliases | ||
---|---|---|
int | street | hexColor |
float | city | guid |
boolean | country | ipv4 |
title | countryCode | ipv6 |
firstName | zipcode | lorem |
lastName | postcode | |
company | lat | |
domain | long | |
tld | phone | |
email | color |
repeat
Repeat the block content a random number of times if two arguments are provided, or a fixed amount of time if only one argument is provided. Set the comma
parameter to false
(default to true
) to prevent the insertion of new lines and commas by the helper.
Parameters/arguments | Type | Description |
---|---|---|
[0] | number | Minimum items |
1 | number | Maximum items |
[comma=true] | boolean | Add trailing comma |
Examples
Copytest <!-- result: test, test, test, test, test -->
switch
Select some content depending on a variable. Behaves like a regular switch.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any | Value against which the switch matches the cases |
Examples
Copy"John" "Jack" "Peter"
data
Get the stringified value at a given path
from a data bucket selected by ID or name. This helper is designed to retrieve data to be served in a response. To reuse the retrieved data with other helpers (each
, if
, etc.), use the dataRaw
helper below.
path
takes the following form key.0.key.5.key
and is based on the object-path library. Properties containing dots are supported by escaping the dots: key.key\.with\.dot
.path
is omitted ({{data 'ID'}}
).Arguments (ordered) | Type | Description |
---|---|---|
0 | string | ID or name of the daa bucket |
1 | string | Path to the data bucket property |
Examples
Copy
dataRaw
Get the raw value (array, object, etc.) at a given path
from a data bucket selected by ID or name. This "raw" helper is designed to work with other helpers (each
, if
, etc.). To directly use the retrieved data in the response, use data buckets direct linking or the data
helper above.
path
takes the following form key.0.key.5.key
and is based on the object-path library. Properties containing dots are supported by escaping the dots: key.key\.with\.dot
.path
is omitted ({{dataRaw 'ID'}}
).Arguments (ordered) | Type | Description |
---|---|---|
0 | string | ID or name of the daa bucket |
1 | string | Path to the data bucket property |
Examples
Copyvalue value
array
Create an array from the given items. This helper is mostly used with the following helpers: oneOf
, someOf
.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any | Value used to populate the array |
Examples
Copy
oneOf
Select a random item in the array passed in parameters.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any[] | Array of values |
Examples
Copyresult: item2
someOf
Return a random number of items from the array passed in parameters, concatenated as a string. Use it with triple curly braces to get a JSON representation.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any[] | Array of values |
1 | number | Minimum number of items |
2 | number | Maximum number of items |
[3 = false] | boolean | Get result as an array |
Examples
Copyresult: item1,item2 <!-- Use triple curly braces to avoid character escaping --> result: item1,item2
join
Return a new string by concatenating all the elements in an array.
Arguments (ordered) | Type | Description |
---|---|---|
0 | [] | Array of values |
1 | string | Separator |
Examples
Copyresult: item1#item2#item3
slice
Return a copy of a portion of an array from start to end indexes (not included).
Arguments (ordered) | Type | Description |
---|---|---|
0 | [] | Array of values |
1 | number | Start index |
2 | number | End index |
Examples
Copyresult: ['item1', 'item2']
len
Return an array or string length.
Arguments (ordered) | Type | Description |
---|---|---|
0 | [] | string | Array or string |
Examples
Copyresult: 3 result: 5
add
Add the numbers passed as parameters to each others. Unrecognized strings passed as arguments will be ignored.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any[] | Value of the operandes (can process numbers and strings) |
Examples
Copyresult: '2' result: '2' result: '2'
subtract
Subtract the numbers passed as parameters to the first parameter. Unrecognized strings passed as arguments will be ignored.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any[] | Value of the operandes (can process numbers and strings) |
Examples
Copyresult: '1' result: '1' result: '1'
multiply
Multiply the numbers passed as parameters to each others. Unrecognized strings passed as arguments will be ignored.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any[] | Value of the operandes (can process numbers and strings) |
Examples
Copyresult: '6' result: '6' result: '6'
divide
Divide the first parameter by the other numbers passed as parameters. Unrecognized strings passed as arguments will be ignored.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any[] | Value of the operandes (can process numbers and strings) |
Examples
Copyresult: '2' result: '2' result: '2'
modulo
Compute the modulo of the first parameter by the second.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First value (can process numbers and strings) |
1 | number | Second value (can process numbers and strings) |
Examples
Copyresult: '1' result: '1' result: '1'
ceil
Ceil the value of the number passed as parameter.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Value to ceil (can process numbers and strings) |
Examples
Copyresult: '2' result: '2'
floor
Floor the value of the number passed as parameter.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Value to floor (can process numbers and strings) |
Examples
Copyresult: '2' result: '2'
eq
Verify if two numbers are equal. Returns a boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First number |
1 | number | Second number |
Examples
Copytrue Result: true
gt
Verify if the first number is greater than the second number. Returns a boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First number |
1 | number | Second number |
Examples
Copytrue Result: true
gte
Verify if the first number is greater than or equal to the second number. Returns a boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First number |
1 | number | Second number |
Examples
Copytrue Result: true
lt
Verify if the first number is lower than the second number. Returns a boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First number |
1 | number | Second number |
Examples
Copytrue Result: true
lte
Verify if the first number is lower than or equal to the second number. Returns a boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First number |
1 | number | Second number |
Examples
Copytrue Result: true
toFixed
Format a number using fixed-point notation.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | A number |
1 | number | Number of digits |
Examples
CopyResult: 1.11
round
Return the value of a number rounded to the nearest integer.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | A number to round |
Examples
CopyResult: 0
newline
Add a newline \n
.
Examples
Copy
base64
Encode the parameter as base64. This can be used as an inline helper or block helper (see examples below).
Arguments (ordered) | Type | Description |
---|---|---|
[0] | any | Value to encode (optional when used as a block helper) |
Examples
Copyfirstname,lastname,countryCode ,,
base64Decode
Decode a base64 string. This can be used as an inline helper or block helper (see examples below).
Arguments (ordered) | Type | Description |
---|---|---|
[0] | string | Base64 string to decode (optional when used as a block helper) |
Examples
Copy
objectId
Create a valid ObjectId. It can generates the ObjectId based on the specified time (in seconds) or from a 12 byte string that will act as a seed. Syntax is based on bson-objectid package.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | number | Seed |
Examples
Copy
setVar
Set a variable to be used later in the template. The value can be the result of another helper. To use it elsewhere in the template, refer to the variable with its name prefixed with an @
: {{@varname}}
. The variable can also be used as a helper parameter: {{#repeat @varname}}...{{/repeat}}
.
Variables declared in a block helper will be scoped to the block and unavailable outside.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Variable name |
1 | any | Variable value |
Examples
Copyusage: ... declare a variable in a block helper:
includes
Search whether a string can be found in another string and returns the appropriate boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any | Data to search into |
1 | any | Data to search |
Examples
Copyresult: true
substr
Return a portion of a string starting at the specified index and extending for a given number of characters afterwards.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any | Starting index |
[1 = max length] | any | Length |
Examples
Copyresult: 'data'
lowercase
Return the first string parameter lowercased.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | String to lowercase |
Examples
Copyresult: 'abcd'
uppercase
Return the first string parameter uppercased.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | String to uppercase |
Examples
Copyresult: 'ABCD'
split
Split a string and return an array containing the multiples substrings. This helper can be used within handlebars' iterative helpers such as each
. (Default separator is " ")
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Data to split |
1 | string | Separator |
Examples
Copyitem, result: item1,item2,item3,item4 , result: This,is,my,string,
stringify
Return objects and arrays as a formatted JSON string indented with two spaces.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any | Object or array |
Examples
Considering an entering body:
Copy{ "prop1": "123", "prop2": { "data": "test" } }
Copy
Copy{ "data": "test" }
concat
Concatenate multiple strings/numbers together. This helper can concatenate results from other helpers, or be used as a parameter of another helper (see examples below).
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any | Values to concatenate |
Examples
Copy...
indexOf
Return the index of the searched 'data' inside the string. A last parameter (number) can be passed to start the search at a specific index.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any | Data to search into |
1 | any | Data to search |
[2 = 0] | number | Search starting index |
Examples
Copyresult: 5
parseInt
Parse a number from a string.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | String to parse |
Examples
Copy
now
Display the current time in the chosen format. Format syntax is based on date-fns package (v2) and is optional (default to ISO string).
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Date format |
Examples
Copy
dateTimeShift
Shift a date by adding the number of years
, months
, etc. passed as parameters. The date
and format
parameters are optional. The helper will return the current date and time as an ISO string if omitted (yyyy-MM-ddTHH:mm:ss.SSSxxx
).
Parameters (named) | Type | Description |
---|---|---|
date | string | Date to shift |
[format = 'yyyy-MM-ddTHH:mm:ss.SSSxxx'] | string | Format of the shifted date |
[years = 0] | number | Years to shift |
[months = 0] | number | Months to shift |
[days = 0] | number | Days to shift |
[hours = 0] | number | Hours to shift |
[minutes = 0] | number | Minutes to shift |
[seconds = 0] | number | Seconds to shift |
Examples
Copy
date
Return a random formatted date (using date-fns package format) between a minimum and a maximum. Uses faker 'date.between'
to generate the random date.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Starting date |
1 | string | Ending date |
2 | string | Date format |
Examples
Copy
time
Return a random formatted time (using date-fns package format) between a minimum and a maximum. Uses faker 'date.between'
to generate the random time.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Starting time |
1 | number | Ending time |
2 | string | Time format |
Examples
Copy
dateFormat
Return a formatted date (using date-fns package format).
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Date to format |
1 | string | Output format |
Examples
Copy
int
Return a random integer. Alias of faker 'datatype.number
.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Minimum |
1 | number | Maximum |
Examples
Copy
float
Return a random float. Alias of faker 'datatype.number
with precision = 10.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Minimum |
1 | number | Maximum |
Examples
Copy
boolean
Return a random boolean. Alias of faker 'datatype.boolean'
.
Examples
Copy
title
Return a random title. Alias of faker 'name.title'
.
Examples:
Copy
firstName
Return a random first name. Alias of faker 'name.firstName'
.
Examples:
Copy
lastName
Return a random last name. Alias of faker 'name.lastName'
.
Examples:
Copy
company
Return a random company name. Alias of faker 'company.companyName'
.
Examples:
Copy
domain
Return a random domain name. Alias of faker 'internet.domainName'
.
Examples:
Copy
tld
Return a random top level domain. Alias of faker 'internet.domainSuffix'
.
Examples:
Copy
email
Return a random email address. Alias of faker 'internet.email'
.
Examples:
Copy
street
Return a random address. Alias of faker 'address.streetAddress'
.
Examples:
Copy
city
Return a random city name. Alias of faker 'address.city'
.
Examples:
Copy
country
Return a random country name. Alias of faker 'address.country'
.
Examples:
Copy
countryCode
Return a random country code. Alias of faker 'address.countryCode'
.
Examples:
Copy
zipcode
Return a random zip code. Alias of faker 'address.zipCode'
.
Examples:
Copy
postcode
Return a random zip code. Alias of faker 'address.zipCode'
.
Examples:
Copy
lat
Return a random latitude. Alias of faker 'address.latitude'
.
Examples:
Copy
long
Return a random longitude. Alias of faker 'address.longitude'
.
Examples:
Copy
phone
Return a random phone number. Alias of faker 'phone.phoneNumber'
.
Examples:
Copy
color
Return a random color. Alias of faker 'commerce.color'
.
Examples:
Copy
hexColor
Return a random hexadecimal color code.
Examples:
Copy
guid
Return a random GUID. Alias of faker 'datatype.uuid'
.
Examples:
Copy
ipv4
Return a random IP v4. Alias of faker 'internet.ip'
.
Examples:
Copy
ipv6
Return a random IP v6. Alias of faker 'internet.ipv6'
.
Examples:
Copy
lorem
Return random lorem ipsum text. Alias of faker 'lorem.sentence'
.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Number of words |
Examples:
Copy