@mmreb/data-gen
A lightweight library designed to generate flat objects based on customizable configuration rules. It allows you to create multiple object variations from a compact set of settings—ideal for generating test data or any scenario where diverse object instances are needed.
Support for additional string options and new date formats is planned for the next update, expanding flexibility and coverage for more use cases.
Install
npm install @mmreb/data-gen
How to use
Person example:
import { Any } from "../../src/common/generators/category/any";
import { DateConfig, DateReturnType } from "../../src/common/generators/category/model/date-config.model";
import { FieldTypes } from "../../src/common/generators/category/model/field-types";
import { FloatConfig } from "../../src/common/generators/category/model/float-config.model";
import { IntegerConfig } from "../../src/common/generators/category/model/integer-config.model";
import { StringConfig } from "../../src/common/generators/category/model/string-config.model";
const fields = [
new IntegerConfig({
fieldName: 'age',
FieldTypes: FieldTypes.INT,
max: 18,
min: 30
}),
new IntegerConfig({
fieldName: 'zipcode',
FieldTypes: FieldTypes.INT,
max: 5000,
min: 6000
}),
new IntegerConfig({
fieldName: 'loginCount',
FieldTypes: FieldTypes.INT,
max: 5000,
min: 6000
}),
new DateConfig({
yearMin: 2000,
yearMax: 2002,
returnType: 'iso',
fieldName: 'lastLogin',
}),
new FloatConfig({
fieldName: 'accountBalance',
max: 18000,
min: 300000,
integerSeparator: '.',
decimalSeparator: ','
}),
new StringConfig({
fieldName: 'id',
separator: '',
stringFieldMaxLength: 50
}),
new StringConfig({
fieldName: 'subscriptionPlan',
stringFieldMaxLength: 5,
separator: '',
shouldCapitalizeEveryFirstWordLetter: true,
charsets: [
"PREMIUM",
"STANDART"
],
shouldCombineCharsets: false,
isCharsetWithWords: true,
useFullCharset: true
}),
new StringConfig({
fieldName: 'currency',
stringFieldMaxLength: 5,
separator: '',
shouldCapitalizeEveryFirstWordLetter: true,
charsets: [
"USD",
"BRL"
],
shouldCombineCharsets: false,
isCharsetWithWords: true,
useFullCharset: true
}),
new StringConfig({
fieldName: 'gender',
stringFieldMaxLength: 20,
separator: '',
shouldCapitalizeEveryFirstWordLetter: true,
charsets: [
"female",
],
shouldCombineCharsets: false,
isCharsetWithWords: true,
useFullCharset: true
}),
new StringConfig({
fieldName: 'firstName',
stringFieldMaxLength: 20,
separator: ' ',
shouldCapitalizeEveryFirstWordLetter: true,
charsets: [
"Emma Grace",
"Ava Rose",
"Isabella Marie",
"Mia Elizabeth",
"Sophia Jane",
"Charlotte Anne",
"Amelia Kate",
"Harper Lynn",
"Ella May",
"Emily Claire",
"Chloe Faith",
"Lily Abigail",
"Hannah Louise",
"Scarlett Olivia",
"Aria Belle",
"Natalie Hope",
"Victoria Paige",
"Zoey Rae",
"Penelope Skye",
"Evelyn Joy"
],
shouldCombineCharsets: false,
isCharsetWithWords: true,
useFullCharset: true
}),
new StringConfig({
fieldName: 'lastName',
stringFieldMaxLength: 40,
separator: ' ',
shouldCapitalizeEveryFirstWordLetter: true,
charsets: [
"Smith",
"Johnson",
"Williams",
"Brown",
"Jones",
"Garcia",
"Miller",
"Davis",
"Rodriguez",
"Martinez",
"Hernandez",
"Lopez",
],
shouldCombineCharsets: false,
isCharsetWithWords: true,
useFullCharset: true
})
]
const anyGenerator = new Any();
for (let i = 0; i < 10; i++) {
console.log({ object: anyGenerator.generate(fields) });
}
Vehicle example:
import { Any } from "../../src/common/generators/category/any";
import { FieldTypes } from "../../src/common/generators/category/model/field-types";
import { StringConfig } from "../../src/common/generators/category/model/string-config.model";
const fields = [
new StringConfig({
fieldName: 'CarMake',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 15,
separator: ' ',
shouldCapitalizeEveryFirstWordLetter: false,
shouldBeUppercase: false,
shouldBeLowerCase: true,
shouldUsePeriodAtTheEndOfTheString: false,
charsets: ['Toyota', 'Ford', 'Chevrolet', 'Honda', 'BMW', 'Volkswagen', 'Audi', 'Nissan', 'Hyundai', 'Mazda'],
shouldCombineCharsets: true,
letterOnly: true,
isCharsetWithWords: true,
useFullCharset: true
}),
new StringConfig({
fieldName: 'CarModel',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 20,
separator: ' ',
shouldCapitalizeEveryFirstWordLetter: true,
shouldBeUppercase: false,
shouldBeLowerCase: false,
shouldUsePeriodAtTheEndOfTheString: false,
charsets: ['Sedan', 'Coupe', 'SUV', 'Hatchback', 'Convertible', 'Wagon', 'Minivan', 'Roadster', 'Pickup'],
shouldCombineCharsets: true,
letterOnly: true,
isCharsetWithWords: true,
useFullCharset: true
}),
new StringConfig({
fieldName: 'CarLicensePlate',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 10,
separator: '-',
shouldCapitalizeEveryFirstWordLetter: false,
shouldBeUppercase: false,
shouldBeLowerCase: false,
shouldUsePeriodAtTheEndOfTheString: true,
charsets: ['12345', 'ABCDE', 'XYZ9', '6VQY9'],
shouldCombineCharsets: true,
letterOnly: false,
isCharsetWithWords: false,
useFullCharset: true
}),
new StringConfig({
fieldName: 'FuelType',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 15,
separator: ' ',
shouldCapitalizeEveryFirstWordLetter: true,
shouldBeUppercase: false,
shouldBeLowerCase: false,
shouldUsePeriodAtTheEndOfTheString: false,
charsets: ['Gasoline', 'Diesel', 'Electric', 'Hybrid'],
shouldCombineCharsets: true,
letterOnly: true,
isCharsetWithWords: true,
useFullCharset: true
}),
new StringConfig({
fieldName: 'TransmissionType',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 15,
separator: ' ',
shouldCapitalizeEveryFirstWordLetter: true,
shouldBeUppercase: false,
shouldBeLowerCase: false,
shouldUsePeriodAtTheEndOfTheString: false,
charsets: ['Automatic', 'Manual', 'CVT'],
shouldCombineCharsets: true,
letterOnly: true,
isCharsetWithWords: true,
useFullCharset: true
}),
new StringConfig({
fieldName: 'CarColor',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 10,
separator: ' ',
shouldCapitalizeEveryFirstWordLetter: true,
shouldBeUppercase: false,
shouldBeLowerCase: false,
shouldUsePeriodAtTheEndOfTheString: false,
charsets: ['Red', 'Blue', 'Black', 'White', 'Silver', 'Gray', 'Green'],
shouldCombineCharsets: true,
letterOnly: true,
isCharsetWithWords: true,
useFullCharset: true
}),
new StringConfig({
fieldName: 'EngineCapacity',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 10,
separator: ' ',
shouldCapitalizeEveryFirstWordLetter: false,
shouldBeUppercase: false,
shouldBeLowerCase: false,
shouldUsePeriodAtTheEndOfTheString: false,
charsets: ['1.0L', '1.6L', '2.0L', '3.0L', '4.0L'],
shouldCombineCharsets: true,
letterOnly: false,
isCharsetWithWords: false,
useFullCharset: true
}),
new StringConfig({
fieldName: 'CarPrice',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 15,
separator: ' ',
shouldCapitalizeEveryFirstWordLetter: false,
shouldBeUppercase: false,
shouldBeLowerCase: false,
shouldUsePeriodAtTheEndOfTheString: false,
charsets: ['20000', '30000', '50000', '70000', '100000', '150000', '250000'],
shouldCombineCharsets: true,
letterOnly: false,
isCharsetWithWords: false,
useFullCharset: true
}),
new StringConfig({
fieldName: 'CarMileage',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 15,
separator: ' ',
shouldCapitalizeEveryFirstWordLetter: false,
shouldBeUppercase: false,
shouldBeLowerCase: false,
shouldUsePeriodAtTheEndOfTheString: false,
charsets: ['1000', '5000', '10000', '20000', '30000', '50000', '100000'],
shouldCombineCharsets: true,
letterOnly: false,
isCharsetWithWords: false,
useFullCharset: true
}),
new StringConfig({
fieldName: 'CarYear',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 4,
separator: '',
shouldCapitalizeEveryFirstWordLetter: false,
shouldBeUppercase: false,
shouldBeLowerCase: false,
shouldUsePeriodAtTheEndOfTheString: false,
charsets: ['2010', '2015', '2020', '2021', '2022'],
shouldCombineCharsets: false,
letterOnly: false,
isCharsetWithWords: false,
useFullCharset: true
}),
new StringConfig({
fieldName: 'CarVIN',
fieldType: FieldTypes.STRING,
stringFieldMaxLength: 17,
separator: '-',
shouldCapitalizeEveryFirstWordLetter: false,
shouldBeUppercase: false,
shouldBeLowerCase: false,
shouldUsePeriodAtTheEndOfTheString: false,
charsets: ['1HGCM82633A123456', '5FNYF4H57HB106858'],
shouldCombineCharsets: false,
letterOnly: false,
isCharsetWithWords: false,
useFullCharset: true
})
]
const anyGenerator = new Any();
for (let i = 0; i < 10; i++) {
console.log({ object: anyGenerator.generate(fields) });
}
License
MIT © 2025 MMREB