DataWeave Mock Data Generators Library
DataGenerators
mocks::DataGenerators
This module condenses functions to generate random data in commonly used formats.
Index
Functions
Name | Description |
---|---|
randomAddress | Returns a random address comprised of a door number (from 1 to 10000) and a street name. |
randomAge | Returns a random age ranging from base to top . |
randomCity | Returns a random city name. |
randomCountry | Returns a random country name. |
randomCreditCardNumber | Returns a random credit card number based on the criteria outlined in Credit Card Number Generator & Validator. |
randomDescription | Returns random text up to a given length .If length is negative, "" is returned. |
randomEmailAddress | Returns a random email address. |
randomFirstName | Returns a random first name. |
randomFullName | Returns a random full name, based on the combination of randomFirstName and randomLastName . |
randomId | Returns a random identifier with the given length .Returns "" if length is less than 1. |
randomLastName | Returns a random last name. |
randomPhoneNumber | Returns a random phone number in the US format. |
randomPrice | Returns a random price. |
randomRate | Returns a random percentage rate. |
randomSSN | Returns a random social security number (SSN) based on the criteria outlined in Wikipedia. |
randomUrl | Returns a random URL, represented as a baseUrl (optional) and an additional randomized path. |
randomUserName | Returns a random user name. |
randomZipCode | Returns a random zip code consisting of a Number between 10000 and 20000. |
Functions
randomAddress ββ
randomAddress(): String
Returns a random address comprised of a door number (from 1 to 10000) and a street name.
Example
This example shows a possible result of randomAddress
.
Source
%dw 2.0
output application/json
import randomAddress from mocks::DataGenerators
---
randomAddress()
Output
"5008 BRIARLAKE AVE"
randomAge ββ
randomAge(base: Number, top: Number = 100): Number
Returns a random age ranging from base
to top
.
Defaults to base
if top
is less than base
.
Parameters
Name | Type | Description |
---|---|---|
base | Number | Minimum value for the generated age. |
top | Number | Maximum value for the generated age. Default: 100 . |
Example
This example shows how the randomAge
function behaves when generating a teenager age.
Source
%dw 2.0
output application/json
import randomAge from from mocks::DataGeneratores
---
randomAge(13, 19)
Output
15
randomAge(base: Null, top: Any = null): Null
Helper function that enables randomAge
to work with a null
value.
randomAge(base: Any, top: Null): Null
Helper function that enables randomAge
to work with a null
value.
randomCity ββ
randomCity(): String
Returns a random city name.
Example
This example shows a possible result of randomCity
.
Source
%dw 2.0
output application/json
import randomCity from mocks::DataGenerators
---
randomCity()
Output
"TΔlcher"
randomCountry ββ
randomCountry(): String
Returns a random country name.
Example
This example shows a possible result of randomCountry
.
Source
%dw 2.0
output application/json
import randomCountry from mocks::DataGenerators
---
randomCountry()
Output
"Saudi Arabia"
randomCreditCardNumber ββ
randomCreditCardNumber(): Number
Returns a random credit card number based on the criteria outlined
in Credit Card Number Generator & Validator.
Example
This example shows a possible result of randomCreditCardNumber
.
Source
%dw 2.0
output application/json
import randomCreditCardNumber from mocks::DataGenerators
---
randomCreditCardNumber() as String
Output
"371694040638537"
randomDescription ββ
randomDescription(length: Number): String
Returns random text up to a given length
.
If length
is negative, ""
is returned.
Parameters
Name | Type | Description |
---|---|---|
length | Number | The maximum length of the text to return. |
Example
This example shows how the randomDescription
function behaves with different inputs.
Source
%dw 2.0
output application/json
import randomDescription from mocks::DataGenerators
---
randomDescription(20)
Output
// Yes, this was randomly generated
"dataweave is great"
randomDescription(length: Null): Null
Helper function that enables randomDescription
to work with a null
value.
randomEmailAddress ββ
randomEmailAddress(): String
Returns a random email address.
Example
This example shows a possible result of randomEmailAddress
.
Source
%dw 2.0
output application/json
import randomEmailAddress from mocks::DataGenerators
---
randomEmailAddress()
Output
"guerrinha349@anonymous.to"
randomFirstName ββ
randomFirstName(): String
Returns a random first name.
Example
This example shows a possible result of randomFirstName
.
Source
%dw 2.0
output application/json
import randomFirstName from mocks::DataGenerators
---
randomFirstName()
Output
"Teodosi"
randomFullName ββ
randomFullName(): String
Returns a random full name, based on the combination of randomFirstName
and randomLastName
.
Example
This example shows a possible result of randomFullName
.
Source
%dw 2.0
output application/json
import randomFullName from mocks::DataGenerators
---
randomFullName()
Output
"Arielle Sajan"
randomId ββ
randomId(length: Number): String
Returns a random identifier with the given length
.
Returns ""
if length
is less than 1.
Parameters
Name | Type | Description |
---|---|---|
length | Number | Length of the desired output. |
Example
This example shows how the randomId
function behaves with different inputs.
Source
%dw 2.0
output application/json
import randomId from mocks::DataGenerators
---
randomId(50)
Output
"e7be08ef6bd54c25babef14a8011156d43f57be5fbfe448dbe"
randomId(length: Null): Null
Helper function that enables randomId
to work with a null
value.
randomLastName ββ
randomLastName(): String
Returns a random last name.
Example
This example shows a possible result of randomLastName
.
Source
%dw 2.0
output application/json
import randomLastName from mocks::DataGenerators
---
randomLastName()
Output
"Gagliardi"
randomPhoneNumber ββ
randomPhoneNumber(): String
Returns a random phone number in the US format.
Example
This example shows a possible result of randomPhoneNumber
.
Source
%dw 2.0
output application/json
import randomPhoneNumber from mocks::DataGenerators
---
randomPhoneNumber()
Output
"656-541-1908"
randomPrice ββ
randomPrice(base: Number = 0, max: Number): Number
Returns a random price.
Parameters
Name | Type | Description |
---|---|---|
base | Number | Floor value that represents the minimum for all values generated. Default: 0 . |
max | Number | Ceiling value that represents the maximum for all values generated. |
Example
This example shows how the randomPrice
function behaves with different inputs.
Source
%dw 2.0
output application/json
import randomPrice from mocks::DataGenerators
---
randomPrice(10,1000)
Output
677.87
randomPrice(base: Null, max: Any = null): Null
Helper function that enables randomPrice
to work with a null
value.
randomPrice(base: Any, max: Null): Null
Helper function that enables randomPrice
to work with a null
value.
randomRate ββ
randomRate(base: Number = 0, top: Number = 100): String
Returns a random percentage rate.
Parameters
Name | Type | Description |
---|---|---|
base | Number | Minimum range value. Default: 0 . |
top | Number | Maximum range value. Default: 100 . |
Example
This example shows how the randomRate
function behaves when setting only a minimun value.
Source
%dw 2.0
output application/json
import randomRate from from mocks::DataGenerators
---
randomRate(45)
Output
"68%"
randomRate(base: Null, top: Any = null): Null
Helper function that enables randomRate
to work with a null
value.
randomRate(base: Any, top: Null): Null
Helper function that enables randomRate
to work with a null
value.
randomSSN ββ
randomSSN(): String
Returns a random social security number (SSN) based on the criteria outlined in
Wikipedia.
Example
This example shows a possible result of randomSSN
.
Source
%dw 2.0
output application/json
import randomSSN from mocks::DataGenerators
---
randomSSN()
Output
"232-48-5235"
randomUrl ββ
randomUrl(baseUrl: String = "http://acme.com/");: String
Returns a random URL, represented as a baseUrl
(optional) and an additional randomized path.
Parameters
Name | Type | Description |
---|---|---|
baseUrl | String | The base URL used to generate the URLs. Default: "http://acme.com/" |
Example
This example shows a possible result of randomUrl
.
Source
%dw 2.0
output application/json
---
randomUrl()
Output
"http://acme.com/c9c2c24/06816/27068f""
randomUrl(baseUrl: Null): Null
Helper function that enables randomUrl
to work with a null
value.
randomUserName ββ
randomUserName(): String
Returns a random user name.
Example
This example shows a possible result of randomUserName
.
Source
%dw 2.0
output application/json
import randomUserName from mocks::DataGenerators
---
randomUserName()
Output
"khalfaoui260"
randomZipCode ββ
randomZipCode(): Number
Returns a random zip code consisting of a Number between 10000 and 20000.
Example
This example shows a possible result of randomZipCode
.
Source
%dw 2.0
output application/json
import randomZipCode from mocks::DataGenerators
---
randomZipCode() as String
Output
"17727"