madoka is a tool to generate json data.
There is provided an online editor to edit json template.editor
npm install madoka
# install mocha first
sudo npm install mocha -g
# install dependence
npm install
# run test
npm test
var path = require('path'),
madoka = require('madoka');
var template = [
'{{ repeat(5,7) }}',
{
_id: '{{ objectId() }}',
index: '{{ index() + 1 }}',
guid: '{{ guid() }}',
isActive: '{{ bool() }}',
selfIntroduction: function(faker) {
return 'My name is ' + this.name + '. Generate before name is parsed';
},
balance: '{{floating(1000, 4000, 2, "$0,0.00")}}',
picture: '{{ image.image() }}',
age: '{{ integer(20, 40) }}',
eyeColor: '{{ random("blue", "brown", "green") }}',
name: '{{ firstName() }} {{ lastName() }}',
compay: '{{ company().toUpperCase() }}',
phone: '{{ phone() }}',
address: '{{ state() }}, {{ city() }}, {{ street() }}, {{ faker.address.zipCode() }}',
registered: '{{date(new Date(2014, 0, 1), new Date(), "YYYY-MM-dd hh:mm:ss Z")}}',
tags: [
'{{ repeat(7) }}',
'{{ lorem(1, "words") }}'
],
greeting: function(faker) {
return 'Hello, ' + this.name + ' You have ' + faker.integer(10, 100) + ' unread message';
}
}
];
console.time('build');
for(var i = 1; i < 4; i++) {
madoka.save(template, path.join(__dirname, 'build/users/' + i + '.json'));
}
console.timeEnd('build');
Generate json data.
template
: data template
var template = '{{ firstName() }}';
console.log( madoka.generate(template) );
Generate json data and save to specified path.
template
: data templatepath
: path to save file
Generate fake data.
Instance of faker.js , you can use all the methods faker.js provided.
returns random item from passed arguments list.
Random integer in specified range. Can be negative.
min
: Minimum number in the range.max
: Maximum number in the range.format
: Number format. For more info visit http://adamwdraper.github.io/Numeral-js/
Random float in specified range.
min
: Minimum number in the range.max
: Maximum number in the range.fixed
: Number of decimalsformat
: Number format. For more info visit http://adamwdraper.github.io/Numeral-js/
Random boolean value.
Random globally unique identifier.
MongoDB's globally unique identifier for objects.
Random date in specified range.
min
: Minimum date in the range. Default is new Date(1970, 0, 1).max
: Maximum date in the range. Default is new Date().format
: Date format. For more info visit http://github.com/hogart/datef
Random Lorem Ipsum text.
count
: Number of generated units. Default is 1.units
: Units type. Can be words, sentences, or paragraphs. Default is sentences.
Random person name of both genders if no gender is specified.
gender
: male | female
Return a last name.
Random phone number.
- format: Format string which contains # letters. Default is "###########".
faker.js image object.
- image()
- imageUrl(width, height, category)
- avatar()
- abstract(width, height)
- animals(width, height)
- business(width, height)
- cats(width, height)
- city(width, height)
- food(width, height)
- nightlife(width, height)
- fashion(width, height)
- people(width, height)
- nature(width, height)
- sports(width, height)
- technics(width, height)
- transport(width, height)
Returns a placeholder image link. visit http://dummyimage.com.
width
: Image width, default is 640.height
: Image height, default is 480.options
: Image options.
// default options
{
width: 640,
height: 480,
// array or string, background color.
bgColor: ['CCC', 'FF9C5B', 'FAD089', 'FF9C5B', 'ED303C', '3B8183'],
// array or string,text color
fgColor: ['333', 'FFF'],
format: 'png',
text: ''
}