The type of data to generate. Can be 'custom' or any other string representing a predefined schema type.
The number of data items to generate.
Whether to add a unique ID (key
) to each item.
Whether to add an index to each item.
Optional
schema: anyAn optional custom schema object to use when type
is 'custom'.
An array of generated data items, or a single data item if amount
is 1.
const dataGenerator = new AioDataGenerator();
// Generate 5 user data items with predefined 'user' schema
const users = dataGenerator.generateData('user', 5, true, true);
// Generate 3 custom data items with a custom schema
const customSchema = { name: 'string', age: 'number' };
const customData = dataGenerator.generateData('custom', 3, true, true, customSchema);
// Generate a single summary data item
const summary = dataGenerator.generateData('summary', 1, false, false, 'summary');
Retrieves a predefined schema object based on the provided type
.
This method retrieves a schema object from the predefined schemas using the provided type
.
If the type is found, it calls the function within the schema object and returns the result.
Otherwise, it logs an error message and returns an empty object.
The type of schema to retrieve.
The schema object retrieved from the predefined schemas or an empty object if the type is not found.
Sets the schema to be used for data generation.
This method determines which schema to use based on the provided type
.
If the type is 'custom', it uses the provided schema
or an empty object if no schema is provided.
Otherwise, it retrieves a predefined schema using the getSchema
method.
The type of schema to use. Can be 'custom' or any other string representing a predefined schema type.
Optional
schema: anyAn optional custom schema object to use when type
is 'custom'.
The schema object that will be used for data generation.
Generates data based on the specified type, amount, and schema. This method generates a specified amount of data items based on the provided
type
andschema
. If thetype
is 'custom', it uses the providedschema
to generate data. Otherwise, it uses a predefined schema retrieved bysetSchema
. It can also add a unique ID (key
) and an index to each item ifcreateId
andcreateIndex
are true, respectively.