A simplified way to generate masive mock data based on a schema, you can use the awesome fake/random data generators like (FakerJs, ChanceJs, CasualJs and RandExpJs)
When using the function type in the generator as part of an array in the schema, currently the iteration index is provided, but the target length of the final array is unknown to the consumer. For example (from the README):
var group = {
users: [{
function: function(index) { // index is provided
return this.faker.random.arrayElement(this.db.user).username + index.toString() // index is used
},
length: 10,
fixedLength: false
}]
};
let length = fieldArrayCalcLength(fieldConfig, na.length, this)
let array = Array.from(new Array(length)).map((el, index) => this.generateField(fieldConfig, index))
I propose that length be included in the invocation:
let length = fieldArrayCalcLength(fieldConfig, na.length, this)
let array = Array.from(new Array(length)).map((el, index) => this.generateField(fieldConfig, index, length))
I'm not in a position to provide a PR right now, hence the formal feature request. I can provide a PR later if desired.
Additionally, I was considering making the array available to the generator function as it was being built, but cannot determine an elegant implementation at this time.
When using the
function
type in the generator as part of an array in the schema, currently the iteration index is provided, but the target length of the final array is unknown to the consumer. For example (from the README):This capability exists due to: https://github.com/danibram/mocker-data-generator/blob/v2.0.2/src/lib/Schema.ts#L72-L74
I propose that
length
be included in the invocation:I'm not in a position to provide a PR right now, hence the formal feature request. I can provide a PR later if desired.
Additionally, I was considering making the array available to the generator
function
as it was being built, but cannot determine an elegant implementation at this time.