@drichdev/genata 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +304 -0
- package/dist/examples.d.ts +49 -0
- package/dist/examples.d.ts.map +1 -0
- package/dist/examples.js +224 -0
- package/dist/generators/base.d.ts +65 -0
- package/dist/generators/base.d.ts.map +1 -0
- package/dist/generators/base.js +199 -0
- package/dist/generators/batch.d.ts +12 -0
- package/dist/generators/batch.d.ts.map +1 -0
- package/dist/generators/batch.js +61 -0
- package/dist/generators/field.d.ts +10 -0
- package/dist/generators/field.d.ts.map +1 -0
- package/dist/generators/field.js +78 -0
- package/dist/generators/index.d.ts +7 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +19 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -0
- package/dist/types/index.d.ts +24 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/utils/faker.d.ts +18 -0
- package/dist/utils/faker.d.ts.map +1 -0
- package/dist/utils/faker.js +42 -0
- package/dist/validators/index.d.ts +16 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/index.js +87 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Genata
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# Genata - Generate Realistic Fake Data
|
|
2
|
+
|
|
3
|
+
A lightweight, secure, and TypeScript-first library for generating realistic fake data for testing, development, and documentation.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
- **Simple API**: `genata.email()`, `genata.firstName()`, etc.
|
|
8
|
+
- **Batch Generation**: Generate multiple records at once
|
|
9
|
+
- **Seeding Support**: Reproducible data with seed values
|
|
10
|
+
- **Type-Safe**: Full TypeScript support with strict typing
|
|
11
|
+
- **Secure**: Input validation and sanitization built-in
|
|
12
|
+
- **No Dependencies**: Only depends on @faker-js/faker
|
|
13
|
+
- **25+ Data Types**: From emails to credit cards
|
|
14
|
+
|
|
15
|
+
## 📦 Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install genata
|
|
19
|
+
# or
|
|
20
|
+
yarn add genata
|
|
21
|
+
# or
|
|
22
|
+
pnpm add genata
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 🎯 Quick Start
|
|
26
|
+
|
|
27
|
+
### Basic Usage
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
import genata from "genata";
|
|
31
|
+
|
|
32
|
+
// Generate single values
|
|
33
|
+
const email = genata.email();
|
|
34
|
+
const firstName = genata.firstName();
|
|
35
|
+
const phone = genata.phone();
|
|
36
|
+
|
|
37
|
+
// Generate with options
|
|
38
|
+
const password = genata.password({ length: 20 });
|
|
39
|
+
const randomInt = genata.datatype.integer({ min: 1, max: 100 });
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Using Generators by Category
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
// Person generators
|
|
46
|
+
genata.person.firstName();
|
|
47
|
+
genata.person.lastName();
|
|
48
|
+
genata.person.fullName();
|
|
49
|
+
genata.person.email();
|
|
50
|
+
genata.person.username();
|
|
51
|
+
genata.person.password();
|
|
52
|
+
genata.person.phone();
|
|
53
|
+
|
|
54
|
+
// Location generators
|
|
55
|
+
genata.location.address();
|
|
56
|
+
genata.location.city();
|
|
57
|
+
genata.location.country();
|
|
58
|
+
genata.location.zipCode();
|
|
59
|
+
|
|
60
|
+
// Internet generators
|
|
61
|
+
genata.internet.url();
|
|
62
|
+
genata.internet.ipv4();
|
|
63
|
+
genata.internet.ipv6();
|
|
64
|
+
genata.internet.creditCard();
|
|
65
|
+
|
|
66
|
+
// Company generators
|
|
67
|
+
genata.company.company();
|
|
68
|
+
genata.company.jobTitle();
|
|
69
|
+
|
|
70
|
+
// Date generators
|
|
71
|
+
genata.date.date();
|
|
72
|
+
genata.date.dateTime();
|
|
73
|
+
genata.date.futureDate();
|
|
74
|
+
|
|
75
|
+
// Data type generators
|
|
76
|
+
genata.datatype.uuid();
|
|
77
|
+
genata.datatype.boolean();
|
|
78
|
+
genata.datatype.integer({ min: 0, max: 100 });
|
|
79
|
+
genata.datatype.float({ min: 0, max: 100, decimals: 2 });
|
|
80
|
+
genata.datatype.color();
|
|
81
|
+
genata.datatype.hex({ length: 16 });
|
|
82
|
+
|
|
83
|
+
// Text generators
|
|
84
|
+
genata.text.sentence();
|
|
85
|
+
genata.text.paragraph({ sentences: 5 });
|
|
86
|
+
genata.text.word();
|
|
87
|
+
genata.text.slug();
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Batch Generation
|
|
91
|
+
|
|
92
|
+
Generate multiple records at once:
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
const fields = [
|
|
96
|
+
{ name: "id", type: "id_increment" },
|
|
97
|
+
{ name: "email", type: "email" },
|
|
98
|
+
{ name: "firstName", type: "first_name" },
|
|
99
|
+
{ name: "lastName", type: "last_name" },
|
|
100
|
+
{ name: "phone", type: "phone" },
|
|
101
|
+
{ name: "createdAt", type: "datetime" },
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
// Generate 100 records (default)
|
|
105
|
+
const users = genata.generateBatch(fields);
|
|
106
|
+
|
|
107
|
+
// Generate 1000 records
|
|
108
|
+
const largeDataset = genata.generateBatch(fields, { count: 1000 });
|
|
109
|
+
|
|
110
|
+
// With progress tracking
|
|
111
|
+
const data = genata.generateBatchWithProgress(fields, {
|
|
112
|
+
count: 10000,
|
|
113
|
+
onProgress: (progress) => console.log(`${progress}% complete`),
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Seeding for Reproducible Data
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
// Set a seed for reproducible results
|
|
121
|
+
genata.setSeed(12345);
|
|
122
|
+
|
|
123
|
+
const email1 = genata.email(); // Always the same value
|
|
124
|
+
const email2 = genata.email(); // Always the same value
|
|
125
|
+
|
|
126
|
+
// Reset to random generation
|
|
127
|
+
genata.resetSeed();
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## 🔒 Security Features
|
|
131
|
+
|
|
132
|
+
- **Input Validation**: All options are validated before use
|
|
133
|
+
- **Sanitization**: User inputs are sanitized to prevent injection
|
|
134
|
+
- **Type Safety**: TypeScript strict mode ensures type correctness
|
|
135
|
+
- **Error Handling**: Proper error messages for invalid inputs
|
|
136
|
+
- **No Shell Execution**: No dynamic code execution
|
|
137
|
+
- **Immutable Defaults**: Safe default values that can't be modified
|
|
138
|
+
|
|
139
|
+
## 📋 Available Field Types
|
|
140
|
+
|
|
141
|
+
When using batch generation, supported field types are:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
Person: first_name, last_name, full_name, email, username, password, phone
|
|
145
|
+
Location: address, city, country, zip
|
|
146
|
+
Internet: url, ipv4, ipv6, credit_card
|
|
147
|
+
Company: company, job_title
|
|
148
|
+
Date: date, datetime
|
|
149
|
+
Data Types: uuid, boolean, int, float, number, zero_one, id_increment, color
|
|
150
|
+
Text: sentence, paragraph
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## 🎛️ API Reference
|
|
154
|
+
|
|
155
|
+
### Core Methods
|
|
156
|
+
|
|
157
|
+
#### `genata.email()`
|
|
158
|
+
|
|
159
|
+
Generate a random email address.
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
const email = genata.email();
|
|
163
|
+
// "alice.johnson@example.com"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### `genata.generateBatch(fields, options?)`
|
|
167
|
+
|
|
168
|
+
Generate multiple records.
|
|
169
|
+
|
|
170
|
+
**Parameters:**
|
|
171
|
+
|
|
172
|
+
- `fields` (FieldDefinition[]): Array of field definitions
|
|
173
|
+
- `options` (BatchGeneratorOptions?):
|
|
174
|
+
- `count` (number): Number of records to generate (default: 100)
|
|
175
|
+
- `seed` (number): Seed for reproducible data
|
|
176
|
+
- `locale` (string): Locale for faker
|
|
177
|
+
|
|
178
|
+
**Returns:** Array of objects with generated data
|
|
179
|
+
|
|
180
|
+
#### `genata.setSeed(seed)`
|
|
181
|
+
|
|
182
|
+
Set a seed for reproducible data generation.
|
|
183
|
+
|
|
184
|
+
**Parameters:**
|
|
185
|
+
|
|
186
|
+
- `seed` (number): Non-negative integer seed value
|
|
187
|
+
|
|
188
|
+
#### `genata.resetSeed()`
|
|
189
|
+
|
|
190
|
+
Reset to random generation without a seed.
|
|
191
|
+
|
|
192
|
+
## 🏗️ Architecture
|
|
193
|
+
|
|
194
|
+
The library is organized into modules:
|
|
195
|
+
|
|
196
|
+
- **generators**: Data generation logic (basic, batch, field-level)
|
|
197
|
+
- **types**: TypeScript type definitions
|
|
198
|
+
- **validators**: Input validation and sanitization
|
|
199
|
+
- **utils**: Helper functions (faker initialization)
|
|
200
|
+
|
|
201
|
+
## 🧪 Testing
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
npm test
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## 📄 License
|
|
208
|
+
|
|
209
|
+
MIT
|
|
210
|
+
|
|
211
|
+
## 🤝 Contributing
|
|
212
|
+
|
|
213
|
+
Contributions are welcome! Please ensure:
|
|
214
|
+
|
|
215
|
+
- All code is TypeScript
|
|
216
|
+
- Security-first approach
|
|
217
|
+
- Input validation for all public methods
|
|
218
|
+
- Comprehensive error messages
|
|
219
|
+
|
|
220
|
+
## 📚 Examples
|
|
221
|
+
|
|
222
|
+
### Generate Test Users
|
|
223
|
+
|
|
224
|
+
```javascript
|
|
225
|
+
import genata from "genata";
|
|
226
|
+
|
|
227
|
+
const generateTestUsers = (count = 10) => {
|
|
228
|
+
return genata.generateBatch(
|
|
229
|
+
[
|
|
230
|
+
{ name: "id", type: "id_increment" },
|
|
231
|
+
{ name: "email", type: "email" },
|
|
232
|
+
{ name: "firstName", type: "first_name" },
|
|
233
|
+
{ name: "lastName", type: "last_name" },
|
|
234
|
+
{ name: "phone", type: "phone" },
|
|
235
|
+
{ name: "company", type: "company" },
|
|
236
|
+
{ name: "jobTitle", type: "job_title" },
|
|
237
|
+
{ name: "createdAt", type: "datetime" },
|
|
238
|
+
],
|
|
239
|
+
{ count }
|
|
240
|
+
);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const users = generateTestUsers(50);
|
|
244
|
+
console.log(users);
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Generate E-commerce Products
|
|
248
|
+
|
|
249
|
+
```javascript
|
|
250
|
+
const generateProducts = (count = 20) => {
|
|
251
|
+
return genata.generateBatch(
|
|
252
|
+
[
|
|
253
|
+
{ name: "id", type: "uuid" },
|
|
254
|
+
{ name: "name", type: "sentence" },
|
|
255
|
+
{ name: "description", type: "paragraph", options: { sentences: 3 } },
|
|
256
|
+
{ name: "price", type: "float", options: { min: 10, max: 1000, decimals: 2 } },
|
|
257
|
+
{ name: "stock", type: "int", options: { min: 0, max: 1000 } },
|
|
258
|
+
{ name: "color", type: "color" },
|
|
259
|
+
],
|
|
260
|
+
{ count }
|
|
261
|
+
);
|
|
262
|
+
};
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Reproducible Data for Tests
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
describe("User Service", () => {
|
|
269
|
+
beforeEach(() => {
|
|
270
|
+
genata.setSeed(42);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("should process user data consistently", () => {
|
|
274
|
+
const user1 = { email: genata.email() };
|
|
275
|
+
|
|
276
|
+
genata.setSeed(42);
|
|
277
|
+
const user2 = { email: genata.email() };
|
|
278
|
+
|
|
279
|
+
expect(user1.email).toBe(user2.email);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## 🐛 Troubleshooting
|
|
285
|
+
|
|
286
|
+
### "Invalid field type" error
|
|
287
|
+
|
|
288
|
+
Make sure you're using a valid field type from the supported list.
|
|
289
|
+
|
|
290
|
+
### Data is not reproducible with seed
|
|
291
|
+
|
|
292
|
+
Make sure to set the seed before generating data and don't mix generator calls without resetting.
|
|
293
|
+
|
|
294
|
+
### Performance issues with large batches
|
|
295
|
+
|
|
296
|
+
For very large batches (>100K records), consider:
|
|
297
|
+
|
|
298
|
+
- Generating in chunks
|
|
299
|
+
- Using `generateBatchWithProgress` to show progress
|
|
300
|
+
- Running in a worker thread if in browser
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
Made with ❤️ by Genata Team
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genata Core - Usage Examples
|
|
3
|
+
* Comprehensive examples showing how to use the library
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Example 1: Simple single value generation
|
|
7
|
+
*/
|
|
8
|
+
export declare function example1_SingleValues(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Example 2: Generate test users for a database
|
|
11
|
+
*/
|
|
12
|
+
export declare function example2_GenerateTestUsers(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Example 3: Generate e-commerce products
|
|
15
|
+
*/
|
|
16
|
+
export declare function example3_GenerateProducts(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Example 4: Generate API test data
|
|
19
|
+
*/
|
|
20
|
+
export declare function example4_GenerateAPITestData(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Example 5: Reproducible data with seed
|
|
23
|
+
*/
|
|
24
|
+
export declare function example5_ReproducibleData(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Example 6: Advanced data generation with options
|
|
27
|
+
*/
|
|
28
|
+
export declare function example6_AdvancedOptions(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Example 7: Looping to generate multiple values
|
|
31
|
+
*/
|
|
32
|
+
export declare function example7_LoopGeneration(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Example 8: Progress tracking for large batches
|
|
35
|
+
*/
|
|
36
|
+
export declare function example8_ProgressTracking(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Example 9: Real-world scenario - E-commerce database
|
|
39
|
+
*/
|
|
40
|
+
export declare function example9_RealWorldEcommerce(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Example 10: Error handling
|
|
43
|
+
*/
|
|
44
|
+
export declare function example10_ErrorHandling(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Run all examples
|
|
47
|
+
*/
|
|
48
|
+
export declare function runAllExamples(): void;
|
|
49
|
+
//# sourceMappingURL=examples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"examples.d.ts","sourceRoot":"","sources":["../src/examples.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;GAEG;AACH,wBAAgB,qBAAqB,SAYpC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,SAmBzC;AAED;;GAEG;AACH,wBAAgB,yBAAyB,SAiBxC;AAED;;GAEG;AACH,wBAAgB,4BAA4B,SAgB3C;AAED;;GAEG;AACH,wBAAgB,yBAAyB,SAmBxC;AAED;;GAEG;AACH,wBAAgB,wBAAwB,SAkBvC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,SAatC;AAED;;GAEG;AACH,wBAAsB,yBAAyB,kBAkB9C;AAED;;GAEG;AACH,wBAAgB,2BAA2B,SA6B1C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,SA6BtC;AAED;;GAEG;AACH,wBAAgB,cAAc,SAW7B"}
|
package/dist/examples.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genata Core - Usage Examples
|
|
4
|
+
* Comprehensive examples showing how to use the library
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.example1_SingleValues = example1_SingleValues;
|
|
11
|
+
exports.example2_GenerateTestUsers = example2_GenerateTestUsers;
|
|
12
|
+
exports.example3_GenerateProducts = example3_GenerateProducts;
|
|
13
|
+
exports.example4_GenerateAPITestData = example4_GenerateAPITestData;
|
|
14
|
+
exports.example5_ReproducibleData = example5_ReproducibleData;
|
|
15
|
+
exports.example6_AdvancedOptions = example6_AdvancedOptions;
|
|
16
|
+
exports.example7_LoopGeneration = example7_LoopGeneration;
|
|
17
|
+
exports.example8_ProgressTracking = example8_ProgressTracking;
|
|
18
|
+
exports.example9_RealWorldEcommerce = example9_RealWorldEcommerce;
|
|
19
|
+
exports.example10_ErrorHandling = example10_ErrorHandling;
|
|
20
|
+
exports.runAllExamples = runAllExamples;
|
|
21
|
+
const index_1 = __importDefault(require("./index"));
|
|
22
|
+
/**
|
|
23
|
+
* Example 1: Simple single value generation
|
|
24
|
+
*/
|
|
25
|
+
function example1_SingleValues() {
|
|
26
|
+
console.log("=== Example 1: Single Values ===");
|
|
27
|
+
console.log("Email:", index_1.default.email());
|
|
28
|
+
console.log("First Name:", index_1.default.firstName());
|
|
29
|
+
console.log("Last Name:", index_1.default.lastName());
|
|
30
|
+
console.log("Full Name:", index_1.default.fullName());
|
|
31
|
+
console.log("Phone:", index_1.default.phone());
|
|
32
|
+
console.log("Username:", index_1.default.username());
|
|
33
|
+
console.log("UUID:", index_1.default.datatype.uuid());
|
|
34
|
+
console.log("Address:", index_1.default.location.address());
|
|
35
|
+
console.log("City:", index_1.default.location.city());
|
|
36
|
+
console.log("URL:", index_1.default.internet.url());
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Example 2: Generate test users for a database
|
|
40
|
+
*/
|
|
41
|
+
function example2_GenerateTestUsers() {
|
|
42
|
+
console.log("\n=== Example 2: Generate Test Users ===");
|
|
43
|
+
const users = index_1.default.generateBatch([
|
|
44
|
+
{ name: "id", type: "id_increment" },
|
|
45
|
+
{ name: "email", type: "email" },
|
|
46
|
+
{ name: "firstName", type: "first_name" },
|
|
47
|
+
{ name: "lastName", type: "last_name" },
|
|
48
|
+
{ name: "phone", type: "phone" },
|
|
49
|
+
{ name: "company", type: "company" },
|
|
50
|
+
{ name: "jobTitle", type: "job_title" },
|
|
51
|
+
{ name: "isActive", type: "boolean" },
|
|
52
|
+
{ name: "createdAt", type: "datetime" },
|
|
53
|
+
], { count: 5 });
|
|
54
|
+
console.table(users);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Example 3: Generate e-commerce products
|
|
58
|
+
*/
|
|
59
|
+
function example3_GenerateProducts() {
|
|
60
|
+
console.log("\n=== Example 3: Generate E-commerce Products ===");
|
|
61
|
+
const products = index_1.default.generateBatch([
|
|
62
|
+
{ name: "sku", type: "uuid" },
|
|
63
|
+
{ name: "name", type: "sentence" },
|
|
64
|
+
{ name: "description", type: "paragraph" },
|
|
65
|
+
{ name: "price", type: "float" },
|
|
66
|
+
{ name: "stock", type: "int" },
|
|
67
|
+
{ name: "color", type: "color" },
|
|
68
|
+
{ name: "company", type: "company" },
|
|
69
|
+
], { count: 3 });
|
|
70
|
+
console.table(products);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Example 4: Generate API test data
|
|
74
|
+
*/
|
|
75
|
+
function example4_GenerateAPITestData() {
|
|
76
|
+
console.log("\n=== Example 4: API Test Data ===");
|
|
77
|
+
const testData = index_1.default.generateBatch([
|
|
78
|
+
{ name: "requestId", type: "uuid" },
|
|
79
|
+
{ name: "userAgent", type: "sentence" },
|
|
80
|
+
{ name: "ipAddress", type: "ipv4" },
|
|
81
|
+
{ name: "timestamp", type: "datetime" },
|
|
82
|
+
{ name: "statusCode", type: "int" },
|
|
83
|
+
{ name: "responseTime", type: "float" },
|
|
84
|
+
], { count: 5 });
|
|
85
|
+
console.table(testData);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Example 5: Reproducible data with seed
|
|
89
|
+
*/
|
|
90
|
+
function example5_ReproducibleData() {
|
|
91
|
+
console.log("\n=== Example 5: Reproducible Data ===");
|
|
92
|
+
// Generate data with seed
|
|
93
|
+
index_1.default.setSeed(12345);
|
|
94
|
+
const email1 = index_1.default.email();
|
|
95
|
+
const name1 = index_1.default.firstName();
|
|
96
|
+
// Reset seed to get the same values
|
|
97
|
+
index_1.default.setSeed(12345);
|
|
98
|
+
const email2 = index_1.default.email();
|
|
99
|
+
const name2 = index_1.default.firstName();
|
|
100
|
+
console.log("First generation:", { email: email1, name: name1 });
|
|
101
|
+
console.log("Second generation:", { email: email2, name: name2 });
|
|
102
|
+
console.log("Are they equal?", email1 === email2 && name1 === name2);
|
|
103
|
+
// Reset to random
|
|
104
|
+
index_1.default.resetSeed();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Example 6: Advanced data generation with options
|
|
108
|
+
*/
|
|
109
|
+
function example6_AdvancedOptions() {
|
|
110
|
+
console.log("\n=== Example 6: Advanced Options ===");
|
|
111
|
+
const randomInt = index_1.default.datatype.integer({ min: 1, max: 100 });
|
|
112
|
+
const randomFloat = index_1.default.datatype.float({
|
|
113
|
+
min: 0,
|
|
114
|
+
max: 1000,
|
|
115
|
+
decimals: 2,
|
|
116
|
+
});
|
|
117
|
+
const password = index_1.default.password({ length: 20 });
|
|
118
|
+
const paragraph = index_1.default.text.paragraph({ sentences: 5 });
|
|
119
|
+
const hex = index_1.default.datatype.hex({ length: 32 });
|
|
120
|
+
console.log("Random integer (1-100):", randomInt);
|
|
121
|
+
console.log("Random float (0-1000):", randomFloat);
|
|
122
|
+
console.log("Secure password (20 chars):", password);
|
|
123
|
+
console.log("Long paragraph:", paragraph);
|
|
124
|
+
console.log("Hex string (32 chars):", hex);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Example 7: Looping to generate multiple values
|
|
128
|
+
*/
|
|
129
|
+
function example7_LoopGeneration() {
|
|
130
|
+
console.log("\n=== Example 7: Loop Generation ===");
|
|
131
|
+
const emails = [];
|
|
132
|
+
for (let i = 0; i < 5; i++) {
|
|
133
|
+
emails.push(index_1.default.email());
|
|
134
|
+
}
|
|
135
|
+
console.log("Generated emails:", emails);
|
|
136
|
+
// Alternative with map
|
|
137
|
+
const names = Array.from({ length: 10 }, () => index_1.default.fullName());
|
|
138
|
+
console.log("Generated names:", names);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Example 8: Progress tracking for large batches
|
|
142
|
+
*/
|
|
143
|
+
async function example8_ProgressTracking() {
|
|
144
|
+
console.log("\n=== Example 8: Progress Tracking ===");
|
|
145
|
+
const fields = [
|
|
146
|
+
{ name: "id", type: "id_increment" },
|
|
147
|
+
{ name: "email", type: "email" },
|
|
148
|
+
{ name: "firstName", type: "first_name" },
|
|
149
|
+
{ name: "createdAt", type: "datetime" },
|
|
150
|
+
];
|
|
151
|
+
const records = index_1.default.generateBatchWithProgress(fields, {
|
|
152
|
+
count: 1000,
|
|
153
|
+
onProgress: (progress) => {
|
|
154
|
+
console.log(`Progress: ${progress}%`);
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
console.log(`Generated ${records.length} records`);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Example 9: Real-world scenario - E-commerce database
|
|
161
|
+
*/
|
|
162
|
+
function example9_RealWorldEcommerce() {
|
|
163
|
+
console.log("\n=== Example 9: Real-world E-commerce Scenario ===");
|
|
164
|
+
// Users
|
|
165
|
+
const users = index_1.default.generateBatch([
|
|
166
|
+
{ name: "userId", type: "uuid" },
|
|
167
|
+
{ name: "email", type: "email" },
|
|
168
|
+
{ name: "firstName", type: "first_name" },
|
|
169
|
+
{ name: "lastName", type: "last_name" },
|
|
170
|
+
{ name: "phone", type: "phone" },
|
|
171
|
+
], { count: 3 });
|
|
172
|
+
// Orders
|
|
173
|
+
const orders = index_1.default.generateBatch([
|
|
174
|
+
{ name: "orderId", type: "uuid" },
|
|
175
|
+
{ name: "userId", type: "id_increment" },
|
|
176
|
+
{ name: "total", type: "float" },
|
|
177
|
+
{ name: "status", type: "sentence" },
|
|
178
|
+
{ name: "createdAt", type: "datetime" },
|
|
179
|
+
], { count: 3 });
|
|
180
|
+
console.log("Users:", users);
|
|
181
|
+
console.log("Orders:", orders);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Example 10: Error handling
|
|
185
|
+
*/
|
|
186
|
+
function example10_ErrorHandling() {
|
|
187
|
+
console.log("\n=== Example 10: Error Handling ===");
|
|
188
|
+
try {
|
|
189
|
+
// This will throw an error - invalid field type
|
|
190
|
+
index_1.default.generateBatch([{ name: "test", type: "invalid_type" }], { count: 10 });
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
console.log("Caught error:", error.message);
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
// This will throw an error - invalid count
|
|
197
|
+
index_1.default.generateBatch([{ name: "email", type: "email" }], { count: -5 });
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
console.log("Caught error:", error.message);
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
// This will throw an error - invalid seed
|
|
204
|
+
index_1.default.setSeed(-10);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
console.log("Caught error:", error.message);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Run all examples
|
|
212
|
+
*/
|
|
213
|
+
function runAllExamples() {
|
|
214
|
+
example1_SingleValues();
|
|
215
|
+
example2_GenerateTestUsers();
|
|
216
|
+
example3_GenerateProducts();
|
|
217
|
+
example4_GenerateAPITestData();
|
|
218
|
+
example5_ReproducibleData();
|
|
219
|
+
example6_AdvancedOptions();
|
|
220
|
+
example7_LoopGeneration();
|
|
221
|
+
example8_ProgressTracking();
|
|
222
|
+
example9_RealWorldEcommerce();
|
|
223
|
+
example10_ErrorHandling();
|
|
224
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic data generators
|
|
3
|
+
* Security: All inputs are validated and sanitized
|
|
4
|
+
*/
|
|
5
|
+
import type { GeneratorOptions } from "../types";
|
|
6
|
+
export declare const PersonGenerators: {
|
|
7
|
+
firstName: (options?: GeneratorOptions) => string;
|
|
8
|
+
lastName: (options?: GeneratorOptions) => string;
|
|
9
|
+
fullName: (options?: GeneratorOptions) => string;
|
|
10
|
+
email: (options?: GeneratorOptions) => string;
|
|
11
|
+
username: (options?: GeneratorOptions) => string;
|
|
12
|
+
password: (options?: GeneratorOptions & {
|
|
13
|
+
length?: number;
|
|
14
|
+
}) => string;
|
|
15
|
+
phone: (options?: GeneratorOptions) => string;
|
|
16
|
+
};
|
|
17
|
+
export declare const LocationGenerators: {
|
|
18
|
+
address: (options?: GeneratorOptions) => string;
|
|
19
|
+
city: (options?: GeneratorOptions) => string;
|
|
20
|
+
country: (options?: GeneratorOptions) => string;
|
|
21
|
+
zipCode: (options?: GeneratorOptions) => string;
|
|
22
|
+
};
|
|
23
|
+
export declare const InternetGenerators: {
|
|
24
|
+
url: (options?: GeneratorOptions) => string;
|
|
25
|
+
ipv4: (options?: GeneratorOptions) => string;
|
|
26
|
+
ipv6: (options?: GeneratorOptions) => string;
|
|
27
|
+
creditCard: (options?: GeneratorOptions) => string;
|
|
28
|
+
};
|
|
29
|
+
export declare const CompanyGenerators: {
|
|
30
|
+
company: (options?: GeneratorOptions) => string;
|
|
31
|
+
jobTitle: (options?: GeneratorOptions) => string;
|
|
32
|
+
};
|
|
33
|
+
export declare const DateGenerators: {
|
|
34
|
+
date: (options?: GeneratorOptions & {
|
|
35
|
+
format?: string;
|
|
36
|
+
}) => string;
|
|
37
|
+
dateTime: (options?: GeneratorOptions) => string;
|
|
38
|
+
futureDate: (options?: GeneratorOptions) => string;
|
|
39
|
+
};
|
|
40
|
+
export declare const DataTypeGenerators: {
|
|
41
|
+
uuid: (options?: GeneratorOptions) => string;
|
|
42
|
+
boolean: (options?: GeneratorOptions) => boolean;
|
|
43
|
+
integer: (options?: GeneratorOptions & {
|
|
44
|
+
min?: number;
|
|
45
|
+
max?: number;
|
|
46
|
+
}) => number;
|
|
47
|
+
float: (options?: GeneratorOptions & {
|
|
48
|
+
min?: number;
|
|
49
|
+
max?: number;
|
|
50
|
+
decimals?: number;
|
|
51
|
+
}) => number;
|
|
52
|
+
hex: (options?: GeneratorOptions & {
|
|
53
|
+
length?: number;
|
|
54
|
+
}) => string;
|
|
55
|
+
color: (options?: GeneratorOptions) => string;
|
|
56
|
+
};
|
|
57
|
+
export declare const TextGenerators: {
|
|
58
|
+
sentence: (options?: GeneratorOptions) => string;
|
|
59
|
+
paragraph: (options?: GeneratorOptions & {
|
|
60
|
+
sentences?: number;
|
|
61
|
+
}) => string;
|
|
62
|
+
word: (options?: GeneratorOptions) => string;
|
|
63
|
+
slug: (options?: GeneratorOptions) => string;
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/generators/base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGjD,eAAO,MAAM,gBAAgB;0BACL,gBAAgB,KAAG,MAAM;yBAM1B,gBAAgB,KAAG,MAAM;yBAMzB,gBAAgB,KAAG,MAAM;sBAM5B,gBAAgB,KAAG,MAAM;yBAMtB,gBAAgB,KAAG,MAAM;yBAMzB,gBAAgB,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,MAAM;sBAYlD,gBAAgB,KAAG,MAAM;CAK5C,CAAC;AAEF,eAAO,MAAM,kBAAkB;wBACT,gBAAgB,KAAG,MAAM;qBAM5B,gBAAgB,KAAG,MAAM;wBAMtB,gBAAgB,KAAG,MAAM;wBAMzB,gBAAgB,KAAG,MAAM;CAK9C,CAAC;AAEF,eAAO,MAAM,kBAAkB;oBACb,gBAAgB,KAAG,MAAM;qBAMxB,gBAAgB,KAAG,MAAM;qBAMzB,gBAAgB,KAAG,MAAM;2BAMnB,gBAAgB,KAAG,MAAM;CAKjD,CAAC;AAEF,eAAO,MAAM,iBAAiB;wBACR,gBAAgB,KAAG,MAAM;yBAMxB,gBAAgB,KAAG,MAAM;CAK/C,CAAC;AAEF,eAAO,MAAM,cAAc;qBACR,gBAAgB,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,MAAM;yBAM3C,gBAAgB,KAAG,MAAM;2BAMvB,gBAAgB,KAAG,MAAM;CAKjD,CAAC;AAEF,eAAO,MAAM,kBAAkB;qBACZ,gBAAgB,KAAG,MAAM;wBAMtB,gBAAgB,KAAG,OAAO;wBAM1B,gBAAgB,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,MAAM;sBAa5D,gBAAgB,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,MAAM;oBAkB/E,gBAAgB,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,MAAM;sBAY7C,gBAAgB,KAAG,MAAM;CAK5C,CAAC;AAEF,eAAO,MAAM,cAAc;yBACJ,gBAAgB,KAAG,MAAM;0BAMxB,gBAAgB,GAAG;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,MAAM;qBAYvD,gBAAgB,KAAG,MAAM;qBAMzB,gBAAgB,KAAG,MAAM;CAK3C,CAAC"}
|