Skip to content

Instantly share code, notes, and snippets.

@panacholn
Last active June 6, 2018 04:27
Show Gist options
  • Save panacholn/50d339c59964364293b674adba139bb3 to your computer and use it in GitHub Desktop.
Save panacholn/50d339c59964364293b674adba139bb3 to your computer and use it in GitHub Desktop.
//generator.js
// import chance instance
const chance = require('chance').Chance()
// customer object data
let customerid = 0
const createCustomer = () => {
customerid++
return {
id: customerid,
firstname: chance.first(), // random firstname
lastname: chance.last(), // random lastname
birthday: chance.birthday({ string: true }), // random birthday
gender: chance.gender(), // random gender
avatar: chance.avatar({ protocol: 'https', fileExtension: 'jpg' }), // random avatar url
}
}
// company object data
let companyid = 0
const createCompany = () => {
companyid++
return {
id: companyid,
companyName: chance.company(), // random company name
email: chance.email(), // random email
website: chance.url(), // random url
tel: chance.phone(), // random mobile phone
address: chance.address(), // random address
}
}
// create mixin for use in other files
// usage: chance.customerProfile()
chance.mixin({
customerProfile: createCustomer,
companyProfile: createCompany,
})
// export generate customers and companies
module.exports = {
customers: (n) => chance.n(chance.customerProfile, n), // create n customer profiles
companies: (n) => chance.n(chance.companyProfile, n), // create n companie profiles
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment