This is a package which helps user to create a random dataset for any customized schema (Internally this package uses chance.js
).
Chance is a generator of random strings, numbers etc. It helps reduce some mmonotony particulary while writing any automated tests or anywhere else you need anything random everytime.
Generating data on the customized schema was a challenge earlier, But is no longer now :). In this package, we are going to see how you can generate a dataSet providing schema of your choice.!
Simply customized your schema specifying your kinds (types). Types can be email, natural number, paragraph etc.. (find list of supported kinds at the end of this article.).
Random data is an integral part of any testing or statistical modeling. They play an increasing important role in the system. And having control over the modelling/structuring of data would be cherry on the cake.
So lets control the structuring of data by passing any variations of fields, arrays and objects in just one file. Below is the test schema.json
for reference.
{
"email": {
"kind": "email",
"params": {
"domain": "test.com"
}
},
"age": {
"kind": "age",
"params": {
"type": "adult"
}
},
"company": {
"type": "object",
"fields": {
"companyName": {
"kind": "company"
},
"companyAddress": {
"kind": "address"
},
"companyDetails": {
"type": "object",
"fields": {
"companyId": {
"kind": "fbid"
},
"employeeCount": {
"kind": "natural",
"params": {
"min": 1,
"max": 20
}
},
"subjects": {
"type": "array",
"count": 2,
"fields": {
"subjectName": {
"kind": "word"
},
"marks": {
"kind": "natural",
"params": {
"min": 1,
"max": 100
}
}
}
}
}
}
}
},
"firstName": {
"kind": "first"
},
"lastName": {
"kind": "last"
},
"subjects": {
"type": "array",
"count": 6,
"fields": {
"subjectName": {
"kind": "word"
},
"marks": {
"kind": "natural",
"params": {
"min": 1,
"max": 100
}
}
}
}
}
You must be wondering what's this params
parameter, these are optional parameters which chance.js
uses for configuring you're kinds. Take the example of an email kind, it accepts domain parameter as params.
NOTE: By the way, this is just a sample schema.json
, you can create your own using any combination of arrays or objects, which ever way you want it!
- Install easy-breezy-data-generator from npm:
npm install easy-breezy-data-generator
- Import the package and schema, in whichever file you need it.
const DataGenerator = require('easy-breezy-data-generator');
const schema = require('./schema.json');
- Finally initialize and generate the random dataSet
const dataGenerator = new DataGenerator(schema);
console.log(JSON.stringify(dataGenerator.generateData()));
Below are some most used kinds. Also don't forget to checkout, all the different kinds provided by [chance.js] (https://chancejs.com/)
.
- bool
- falsy
- character
- floating
- integer
- letter
- natural
- prime
- string
- paragraph
- sentence
- syllable
- word
- age
- birthday
- cf
- cpf
- first
- gender
- last
- name
- prefix
- ssn
- suffix
- animal
- android_id
- apple_token
- bb_pin
- wp7_anid
- wp8_anid2
- avatar
- color
- company
- domain
- fbid
- google_analytics
- hashtag
- ip
- ipv6
- klout
- profession
- tld
- url
- address
- altitude
- areacode
- city
- coordinates
- country
- depth
- geohash
- latitude
- locale
- longitude
- phone
- postal
- postcode
- province
- state
- street
- zip
- ampm
- date
- hammertime
- hour
- millisecond
- minute
- month
- second
- timestamp
- timezone
- weekday
- year
- cc
- cc_type
- currency
- currency_pair
- dollar
- euro
- exp
- exp_month
- exp_year
- capitalize
- mixin
- pad
- pick
- pickone
- pickset
- set
- shuffle
- coin
- dice
- guid
- hash
- hidden
- n
- normal
- radio
- rpg
- tv
- unique
- weighted