automake
v0.1.4
Published
Making a various file format and make fake data eaily in stream in Nodejs, automake can easily help you making fake data with different file format easily. And cause this module is using stream so you could create really large fake data!!!
Downloads
172
Readme
automake
Making a various file format and make fake data eaily in stream in Nodejs, automake
can easily help you making fake data with different file format easily. And cause this module is using stream so you could create really large fake data!!!
Usage
A sample example of making a csv file using automake
, first of all, creating a write stream and make header, body, footer and send a finish callback. You can also setup your customized callback to each header, body and footer functions.
An easy sample
var fs = require('fs');
var am = require('automake')
// creating a write stream
var wb = fs.createWriteStream('./test/body_test.csv');
var am_stream = am
.wstream(wb)
.head('name, city, ip, people', function() {
console.log('done making header')
})
.times(100, '{{Name.firstName}}, {{Address.city}}, {{Internet.ip}}, {{Image.imageUrl}}', function() {
console.log('done a record');
})
.foot(function() {
console.log('done making footer');
})
.error(function() {
console.log('occor some error')
})
.finish(function() {
cb();
})
For automaticlly build random data, I've build up this module using https://github.com/Marak/Faker.js , thanks for the powerful module, you can use all of the Faker.js
functions in generating random data. https://github.com/Marak/Faker.js#api (API of Faker.js)
For a sample usage
var am_stream = am
.wstream(wb)
.once('{{Name.firstName}}, {{Address.city}}, {{Internet.ip}}, {{Image.imageUrl}}')
.foot()
.finish(function() {
console.log('finished build fake data');
})
Making Fake data easily
in once()
, .times()
you can use schema {{one of faker.js API, without () in the end}}
, automake
module will parse {{}}
to a particular fake data via faker.js
.
for example
.once('{{Name.firstName}}, {{Address.city}}, {{Internet.ip}}, {{Image.imageUrl}}')
// compile to
// Leonora, Port Rocio, 193.102.170.120, http://lorempixel.com/640/480
.times(10, '{{Name.firstName}}, {{Address.city}}, {{Internet.ip}}, {{Image.imageUrl}}')
// compile to
// Alec, Imogeneport, 161.163.49.107, http://lorempixel.com/640/480
// Maverick, New Dahlia, 180.199.13.252, http://lorempixel.com/640/480
// Ubaldo, South Darrick, 159.2.89.75, http://lorempixel.com/640/480
// Derrick, Lake Alizatown, 18.247.94.61, http://lorempixel.com/640/480
// Coralie, Lake Maiaton, 154.107.166.62, http://lorempixel.com/640/480
// Caleigh, Jacobihaven, 215.88.155.74, http://lorempixel.com/640/480
// Tianna, Samantaport, 141.205.130.144, http://lorempixel.com/640/480
// Nestor, Nadermouth, 92.18.147.49, http://lorempixel.com/640/480
// Trisha, South Leopold, 213.149.47.50, http://lorempixel.com/640/480
// Zachery, Spinkaville, 222.217.24.133, http://lorempixel.com/640/480
// Coralie, North Wilburn, 158.129.20.221, http://lorempixel.com/640/480
Chaining methods
.head(template, [encoding], [callbak])
- template (string)
- encoding (string): like the encoding settings in writeable stream. http://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback
- callback (function): callback function settings in writeable http://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback
.once(template, [encoding], [callback])
- template (string): automake module will automatically parse
{{}}
according to faker.js module - encoding (string): same as
.head
method - callback (function): same as
.head
method
.times(times, template, {encoding: [encoding], join: [string]}, [callback])
- times (number): How many times do you want to loop.
- template (string): automake module will automatically parse
{{}}
according to faker.js module - options (object): you can setup encoding and joining templates by a specific string
- callback (function)
.foot([string], [encoding], [callback])
Same as .head
method, but string is also optional.
.error(callback)
You can make a callback, while the stream prompt error
see more: http://nodejs.org/api/stream.html#stream_event_error_1
.finish(callback)
Make a callback while finished, **using this method you have to call ** .foot
before calling this method
see more: http://nodejs.org/api/stream.html#stream_event_finish
Examples
Here are some examples of files that genereated from automake
https://github.com/chilijung/allfake
License
MIT