Collection of data generators to create complex data structures and any number of records
npm install mockdata-generatorGenerator
=========
A library of mock data object generator. Allows developers and users to define
real life looking mock data.
Javascript
/**
* This will get the constructor of the main class
* The constructor accepts a configuration object with these properties
* 'name': An optional name of the object
* 'metadata': An array of descriptions for each of the attributes of the object
**/
"use strict";
var Generator,
meta,
gen,
pretty,
value;
Generator = require('./index.js').Generator;
pretty = require('js-object-pretty-print').pretty;
meta = {
'name': 'Mockdata test set',
'metadata': [
{
'attributeName': 'creditCards',
'dataType': 'Array',
'metadata': [
{
'attributeName': 'ccNumber',
'dataType': 'Pattern',
'pattern': '####-####-####-####'
},
{
'attributeName': 'cvv',
'dataType': 'Pattern',
'pattern': '###'
},
{
'attributeName': 'expiration',
'dataType': 'Date',
'min': 30,
'max': 1000
},
{
'attributeName': 'limit',
'dataType': 'OneOfList',
'list': [500, 1000, 2000, 5000, 10000],
'mode': 'shuffle'
}
],
'min': 2,
'max': 5
},
{
'attributeName': 'balance',
'dataType': 'Currency',
'min': 50,
'max': 1000
},
{
'attributeName': 'txDate',
'dataType': 'Date',
'min': 10,
'max': 30
},
{
'attributeName': 'id',
'dataType': 'Guid',
'prefix': 'test'
},
{
'attributeName': 'branches',
'dataType': 'Integer',
'min': 10,
'max': 30
},
{
'attributeName': 'description',
'dataType': 'Ipsum',
'paragraphNum': 1,
'wordMin': 10,
'wordMax': 30
},
{
'attributeName': 'accountOwner',
'dataType': 'Name',
'order': 'fl'
},
{
'attributeName': 'beneficiaryContact',
'dataType': 'Name',
'order': 'lf'
},
{
'attributeName': 'averageTxPerDay',
'dataType': 'Number',
'min': 5,
'max': 20
},
{
'attributeName': 'beneficiary',
'dataType': 'OneOfList',
'listName': 'ListBase.Beneficiaries',
'mode': 'sequence',
'index': 0
},
{
'attributeName': 'clothesCategory',
'dataType': 'OneOfList',
'list': ['Accessories', 'Blouses', 'Cardigans', 'Dresses', 'Skirts'],
'mode': 'shuffle'
},
{
'attributeName': 'accountNumber',
'dataType': 'Pattern',
'pattern': '###-AA-###-aaa-####'
},
{
'attributeName': 'accountName',
'dataType': 'String',
'min': 6,
'max': 30
}
]
};
gen = new Generator(meta);
value = gen.getValue(10);
process.stdout.write(pretty(value));
`
Available dataTypes
mockdata-generator provides a way to generate data in the following dataTypes
* Address
* Array
* Bank
* Currency
* Date
* Guid
* Integer
* Ipsum
* Name
* Number
* Object
* One Of List
* Pattern
* String
$3
The base clase for all the other generators. It implements several attributes and methods. Base is not used to generate data and it provides all the common functionality for the other data types
Attribute | Default | Description
---------------| ----------- | ---------------
attributeName | n/a |Identifies the attribute inside the object. It must be unique for the object
dataType | | The data type of the attribute. Any of the names in the dataType list above
min | 0 | The minimum value of a range. Not all the data types require a min
max | 1 | The maximum value of a range. Not all the data types require a max
$3
Generates a random address in the United States. It uses preloaded lists of street names, cities, and states. It generates a random street number
a random zip code in the format #####-####. The result is an object like
`
{
street: "10th",
town: "Oakland",
state: "Massachusetts",
stateAbbr: "MA",
streetNumber: 2548,
streetType: "Street",
streetPosition: undefined,
zipCode: "31494-4275",
formatted: "2548 10th Street, Oakland, 31494-4275 Massachusetts"
}
`
The constructor uses the following attribute:
Attribute | Default | Description
---------------| ----------- | ---------------
addressTemplate | {streetNumber} {street} {streetPosition}{streetType}, {town}, {zipCode} {state} | Allows to define how the address is formatted
$3
Generates a number of object values in the range of (min, max).
Attribute | Default | Description
---------------| ----------- | ---------------
metadata | n/a | An array of metadata descriptors for the attributes in each object
min | 1 | The minimum number of values to generate
max | 1 | The maximum number of values to generate
$3
Generates an object that describes a bank. The result is an object like
`
{
name: "FirstFed Financial Corp.",
address: "1951 Jefferson Street",
city: "Los Angeles",
state: "CA",
aba: "48871-322"
}
`
$3
Generates a random numeric value in the (min, max) range, assign one of the listed currencies and generates an object with three attributes: currency, value and formatted value, for instance
`
{
currency: 'MXN',
value: 943.9473666250706,
formatted: '943.95 MXN'
}
`
Attribute | Default | Description
---------------| ----------- | ---------------
currencyCode | ['AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'HKD', 'JPY', 'MXN', 'NZD', 'PHP', 'SEK', 'SGD', 'THB', 'USD', 'ZAR'] | A list of the currencies to select.
decimalPlaces | 2 | Number of decimal places
decimalSeparator | "." | Character to separate decimal fractions
thousandsSeparator | "," | Character to separate thousands
min | 0 | The minimum value in range
max | 500 | The maximum value in range
$3
Generates a random date in the range of (min, max) days. To create a date in the past the range can be negative. For instance (-60, 0) will generate a date in the last 60 days. The result is an object like this:
`
expiration: {
value: "Thu Jun 09 2016 14:33:26 GMT-0700 (Pacific Daylight Time)",
formatted: "Thu, Jun 09, 2016 2:33:26 PM PDT",
days: 666
}
``