DataWeave Mock Data Generators Library icon

DataWeave Mock Data Generators Library

(0 reviews)

DataGenerators

mocks::DataGenerators

This module condenses functions to generate random data in commonly used formats.

Index

Functions

NameDescription
randomAddressReturns a random address comprised of a door number (from 1 to 10000) and a street name.
randomAgeReturns a random age ranging from base to top.
randomCityReturns a random city name.
randomCountryReturns a random country name.
randomCreditCardNumberReturns a random credit card number based on the criteria outlined
in Credit Card Number Generator & Validator.
randomDescriptionReturns random text up to a given length.
If length is negative, "" is returned.
randomEmailAddressReturns a random email address.
randomFirstNameReturns a random first name.
randomFullNameReturns a random full name, based on the combination of randomFirstName and randomLastName.
randomIdReturns a random identifier with the given length.
Returns "" if length is less than 1.
randomLastNameReturns a random last name.
randomPhoneNumberReturns a random phone number in the US format.
randomPriceReturns a random price.
randomRateReturns a random percentage rate.
randomSSNReturns a random social security number (SSN) based on the criteria outlined in
Wikipedia.
randomUrlReturns a random URL, represented as a baseUrl (optional) and an additional randomized path.
randomUserNameReturns a random user name.
randomZipCodeReturns 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
NameTypeDescription
baseNumberMinimum value for the generated age.
topNumberMaximum 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
NameTypeDescription
lengthNumberThe 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
NameTypeDescription
lengthNumberLength 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
NameTypeDescription
baseNumberFloor value that represents the minimum for all values generated. Default: 0.
maxNumberCeiling 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
NameTypeDescription
baseNumberMinimum range value. Default: 0.
topNumberMaximum 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
NameTypeDescription
baseUrlStringThe 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"


Reviews

TypeDataWeave Library
OrganizationMuleSoft
Published by
MuleSoft Organization
Published onMar 23, 2022
Asset overview

Asset versions for 1.0.x

Asset versions
VersionActions
1.0.0