@drichdev/genata 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/README.md +200 -197
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,17 +2,30 @@
2
2
 
3
3
  A lightweight, secure, and TypeScript-first library for generating realistic fake data for testing, development, and documentation.
4
4
 
5
- ## 🚀 Features
5
+ ---
6
+
7
+ ## Features
8
+
9
+ * Simple and intuitive API
10
+ * Batch data generation
11
+ * Reproducible data with seed support
12
+ * Full TypeScript support
13
+ * Built-in validation and sanitization
14
+ * No runtime dependencies except `@faker-js/faker`
15
+ * 25+ data generators
16
+
17
+ ---
18
+
19
+ ## Why Genata?
6
20
 
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
21
+ * Cleaner and simpler API than typical faker usage
22
+ * Built-in batch generation without extra tooling
23
+ * Consistent seeding across all generators
24
+ * Type-safe by default
25
+
26
+ ---
14
27
 
15
- ## 📦 Installation
28
+ ## Installation
16
29
 
17
30
  ```bash
18
31
  npm install @drichdev/genata
@@ -22,19 +35,31 @@ yarn add @drichdev/genata
22
35
  pnpm add @drichdev/genata
23
36
  ```
24
37
 
25
- ## 🎯 Quick Start
38
+ ---
39
+
40
+ ## Import
41
+
42
+ ### ES Modules (recommended)
43
+
44
+ ```javascript
45
+ import genata from '@drichdev/genata';
46
+ ```
26
47
 
27
- ### CommonJS (Node.js)
48
+ ### CommonJS
28
49
 
29
50
  ```javascript
30
51
  const genata = require('@drichdev/genata');
52
+ ```
31
53
 
32
- const email = genata.email();
33
- const firstName = genata.firstName();
34
- const phone = genata.phone();
54
+ ### TypeScript
55
+
56
+ ```typescript
57
+ import genata, { type FieldDefinition } from '@drichdev/genata';
35
58
  ```
36
59
 
37
- ### ES Modules (Node.js with "type": "module")
60
+ ---
61
+
62
+ ## Quick Start
38
63
 
39
64
  ```javascript
40
65
  import genata from '@drichdev/genata';
@@ -44,30 +69,23 @@ const firstName = genata.firstName();
44
69
  const phone = genata.phone();
45
70
  ```
46
71
 
47
- ### TypeScript / Next.js
72
+ ---
48
73
 
49
- ```typescript
50
- import genata from '@drichdev/genata';
74
+ ## Naming Convention
51
75
 
52
- export default function Home() {
53
- const email = genata.email();
54
- const firstName = genata.firstName();
55
- const phone = genata.phone();
56
-
57
- return (
58
- <div>
59
- <p>Email: {email}</p>
60
- <p>Name: {firstName}</p>
61
- <p>Phone: {phone}</p>
62
- </div>
63
- );
64
- }
65
- ```
76
+ * Direct API uses camelCase
77
+ `genata.firstName()`
78
+
79
+ * Batch generation uses snake_case
80
+ `type: "first_name"`
66
81
 
67
- ### Using Generators by Category
82
+ ---
83
+
84
+ ## Generators
85
+
86
+ ### Person
68
87
 
69
88
  ```javascript
70
- // Person generators
71
89
  genata.person.firstName();
72
90
  genata.person.lastName();
73
91
  genata.person.fullName();
@@ -75,46 +93,64 @@ genata.person.email();
75
93
  genata.person.username();
76
94
  genata.person.password();
77
95
  genata.person.phone();
96
+ ```
78
97
 
79
- // Location generators
98
+ ### Location
99
+
100
+ ```javascript
80
101
  genata.location.address();
81
102
  genata.location.city();
82
103
  genata.location.country();
83
104
  genata.location.zipCode();
105
+ ```
106
+
107
+ ### Internet
84
108
 
85
- // Internet generators
109
+ ```javascript
86
110
  genata.internet.url();
87
111
  genata.internet.ipv4();
88
112
  genata.internet.ipv6();
89
113
  genata.internet.creditCard();
114
+ ```
90
115
 
91
- // Company generators
116
+ ### Company
117
+
118
+ ```javascript
92
119
  genata.company.company();
93
120
  genata.company.jobTitle();
121
+ ```
122
+
123
+ ### Date
94
124
 
95
- // Date generators
125
+ ```javascript
96
126
  genata.date.date();
97
127
  genata.date.dateTime();
98
128
  genata.date.futureDate();
129
+ ```
99
130
 
100
- // Data type generators
131
+ ### Data Types
132
+
133
+ ```javascript
101
134
  genata.datatype.uuid();
102
135
  genata.datatype.boolean();
103
136
  genata.datatype.integer({ min: 0, max: 100 });
104
137
  genata.datatype.float({ min: 0, max: 100, decimals: 2 });
105
138
  genata.datatype.color();
106
139
  genata.datatype.hex({ length: 16 });
140
+ ```
141
+
142
+ ### Text
107
143
 
108
- // Text generators
144
+ ```javascript
109
145
  genata.text.sentence();
110
146
  genata.text.paragraph({ sentences: 5 });
111
147
  genata.text.word();
112
148
  genata.text.slug();
113
149
  ```
114
150
 
115
- ### Batch Generation
151
+ ---
116
152
 
117
- Generate multiple records at once:
153
+ ## Batch Generation
118
154
 
119
155
  ```javascript
120
156
  const fields = [
@@ -126,44 +162,22 @@ const fields = [
126
162
  { name: "createdAt", type: "datetime" },
127
163
  ];
128
164
 
129
- // Generate 100 records (default)
165
+ // Default (100 records)
130
166
  const users = genata.generateBatch(fields);
131
167
 
132
- // Generate 1000 records
168
+ // Custom count
133
169
  const largeDataset = genata.generateBatch(fields, { count: 1000 });
134
170
 
135
- // With progress tracking
171
+ // With progress
136
172
  const data = genata.generateBatchWithProgress(fields, {
137
173
  count: 10000,
138
174
  onProgress: (progress) => console.log(`${progress}% complete`),
139
175
  });
140
176
  ```
141
177
 
142
- ### Seeding for Reproducible Data
143
-
144
- ```javascript
145
- // Set a seed for reproducible results
146
- genata.setSeed(12345);
147
-
148
- const email1 = genata.email(); // Always the same value
149
- const email2 = genata.email(); // Always the same value
150
-
151
- // Reset to random generation
152
- genata.resetSeed();
153
- ```
154
-
155
- ## 🔒 Security Features
156
-
157
- - **Input Validation**: All options are validated before use
158
- - **Sanitization**: User inputs are sanitized to prevent injection
159
- - **Type Safety**: TypeScript strict mode ensures type correctness
160
- - **Error Handling**: Proper error messages for invalid inputs
161
- - **No Shell Execution**: No dynamic code execution
162
- - **Immutable Defaults**: Safe default values that can't be modified
163
-
164
- ## 📋 Available Field Types
178
+ ---
165
179
 
166
- When using batch generation, supported field types are:
180
+ ## Supported Field Types
167
181
 
168
182
  ```
169
183
  Person: first_name, last_name, full_name, email, username, password, phone
@@ -175,191 +189,180 @@ Data Types: uuid, boolean, int, float, number, zero_one, id_increment, color, he
175
189
  Text: sentence, paragraph, word, slug
176
190
  ```
177
191
 
178
- ## 🎛️ API Reference
192
+ ---
193
+
194
+ ## Seeding (Reproducible Data)
195
+
196
+ ```javascript
197
+ genata.setSeed(12345);
198
+
199
+ const email1 = genata.email();
200
+ const email2 = genata.email();
201
+
202
+ // Reset randomness
203
+ genata.resetSeed();
204
+ ```
205
+
206
+ ---
179
207
 
180
- ### Core Methods
208
+ ## API Reference
181
209
 
182
- #### `genata.email()`
210
+ ### `genata.email()`
183
211
 
184
- Generate a random email address.
212
+ Generate a random email.
185
213
 
186
214
  ```javascript
187
215
  const email = genata.email();
188
- // "alice.johnson@example.com"
189
216
  ```
190
217
 
191
- #### `genata.generateBatch(fields, options?)`
218
+ ---
219
+
220
+ ### `genata.generateBatch(fields, options?)`
192
221
 
193
222
  Generate multiple records.
194
223
 
195
224
  **Parameters:**
196
225
 
197
- - `fields` (FieldDefinition[]): Array of field definitions
198
- - `options` (BatchGeneratorOptions?):
199
- - `count` (number): Number of records to generate (default: 100)
200
- - `seed` (number): Seed for reproducible data
201
- - `locale` (string): Locale for faker
226
+ * `fields`: Array of field definitions
227
+ * `options`:
202
228
 
203
- **Returns:** Array of objects with generated data
229
+ * `count` (default: 100)
230
+ * `seed`
231
+ * `locale`
204
232
 
205
- #### `genata.setSeed(seed)`
233
+ **Returns:** Array of objects
206
234
 
207
- Set a seed for reproducible data generation.
235
+ ---
208
236
 
209
- **Parameters:**
237
+ ### `genata.setSeed(seed)`
210
238
 
211
- - `seed` (number): Non-negative integer seed value
239
+ Set a seed for reproducible results.
212
240
 
213
- #### `genata.resetSeed()`
241
+ ---
214
242
 
215
- Reset to random generation without a seed.
243
+ ### `genata.resetSeed()`
216
244
 
217
- ## 🏗️ Architecture
245
+ Reset random generation.
218
246
 
219
- The library is organized into modules:
247
+ ---
220
248
 
221
- - **generators**: Data generation logic (basic, batch, field-level)
222
- - **types**: TypeScript type definitions
223
- - **validators**: Input validation and sanitization
224
- - **utils**: Helper functions (faker initialization)
249
+ ## Examples
225
250
 
226
- ## 🧪 Testing
251
+ ### Generate Users
227
252
 
228
- ```bash
229
- npm test
253
+ ```javascript
254
+ const users = genata.generateBatch(
255
+ [
256
+ { name: "id", type: "id_increment" },
257
+ { name: "email", type: "email" },
258
+ { name: "firstName", type: "first_name" },
259
+ { name: "lastName", type: "last_name" },
260
+ { name: "phone", type: "phone" },
261
+ { name: "company", type: "company" },
262
+ { name: "jobTitle", type: "job_title" },
263
+ { name: "createdAt", type: "datetime" },
264
+ ],
265
+ { count: 50 }
266
+ );
230
267
  ```
231
268
 
232
- ## 📄 License
269
+ ---
233
270
 
234
- MIT
271
+ ### Generate Products
235
272
 
236
- ## 🤝 Contributing
273
+ ```javascript
274
+ const products = genata.generateBatch(
275
+ [
276
+ { name: "id", type: "uuid" },
277
+ { name: "name", type: "sentence" },
278
+ { name: "description", type: "paragraph", options: { sentences: 3 } },
279
+ { name: "price", type: "float", options: { min: 10, max: 1000, decimals: 2 } },
280
+ { name: "stock", type: "int", options: { min: 0, max: 1000 } },
281
+ { name: "color", type: "color" },
282
+ ],
283
+ { count: 20 }
284
+ );
285
+ ```
237
286
 
238
- Contributions are welcome! Please ensure:
287
+ ---
239
288
 
240
- - All code is TypeScript
241
- - Security-first approach
242
- - Input validation for all public methods
243
- - Comprehensive error messages
289
+ ### Reproducible Tests
244
290
 
245
- ## 📚 Examples
291
+ ```javascript
292
+ beforeEach(() => {
293
+ genata.setSeed(42);
294
+ });
246
295
 
247
- ### Generate Test Users
296
+ const user1 = { email: genata.email() };
248
297
 
249
- ```javascript
250
- import genata from "genata";
251
-
252
- const generateTestUsers = (count = 10) => {
253
- return genata.generateBatch(
254
- [
255
- { name: "id", type: "id_increment" },
256
- { name: "email", type: "email" },
257
- { name: "firstName", type: "first_name" },
258
- { name: "lastName", type: "last_name" },
259
- { name: "phone", type: "phone" },
260
- { name: "company", type: "company" },
261
- { name: "jobTitle", type: "job_title" },
262
- { name: "createdAt", type: "datetime" },
263
- ],
264
- { count }
265
- );
266
- };
267
-
268
- const users = generateTestUsers(50);
269
- console.log(users);
298
+ genata.setSeed(42);
299
+ const user2 = { email: genata.email() };
270
300
  ```
271
301
 
272
- ### Generate E-commerce Products
302
+ ---
273
303
 
274
- ```javascript
275
- const generateProducts = (count = 20) => {
276
- return genata.generateBatch(
277
- [
278
- { name: "id", type: "uuid" },
279
- { name: "name", type: "sentence" },
280
- { name: "description", type: "paragraph", options: { sentences: 3 } },
281
- { name: "price", type: "float", options: { min: 10, max: 1000, decimals: 2 } },
282
- { name: "stock", type: "int", options: { min: 0, max: 1000 } },
283
- { name: "color", type: "color" },
284
- ],
285
- { count }
286
- );
287
- };
288
- ```
304
+ ## Security
289
305
 
290
- ### Reproducible Data for Tests
306
+ * Input validation on all public methods
307
+ * Sanitization of user-provided options
308
+ * No dynamic code execution
309
+ * Safe default values
291
310
 
292
- ```javascript
293
- describe("User Service", () => {
294
- beforeEach(() => {
295
- genata.setSeed(42);
296
- });
297
-
298
- test("should process user data consistently", () => {
299
- const user1 = { email: genata.email() };
300
-
301
- genata.setSeed(42);
302
- const user2 = { email: genata.email() };
303
-
304
- expect(user1.email).toBe(user2.email);
305
- });
306
- });
307
- ```
311
+ ---
308
312
 
309
- ## 🐛 Troubleshooting
313
+ ## Architecture
310
314
 
311
- ### "Invalid field type" error
315
+ * `generators`: data generation logic
316
+ * `types`: TypeScript definitions
317
+ * `validators`: input validation
318
+ * `utils`: internal helpers
312
319
 
313
- Make sure you're using a valid field type from the supported list.
320
+ ---
314
321
 
315
- ### Data is not reproducible with seed
322
+ ## Testing
316
323
 
317
- Make sure to set the seed before generating data and don't mix generator calls without resetting.
324
+ ```bash
325
+ npm test
326
+ ```
318
327
 
319
- ### Performance issues with large batches
328
+ ---
320
329
 
321
- For very large batches (>100K records), consider:
330
+ ## Troubleshooting
322
331
 
323
- - Generating in chunks
324
- - Using `generateBatchWithProgress` to show progress
325
- - Running in a worker thread if in browser
332
+ ### Invalid field type
326
333
 
327
- ## 📚 Complete Documentation
334
+ Ensure the field type exists in the supported list.
328
335
 
329
- For detailed examples and advanced usage, see [USAGE.md](./USAGE.md)
336
+ ### Seed not working
330
337
 
331
- ## 🔧 Import Methods
338
+ Set the seed before generating data and avoid mixing seeded and non-seeded calls.
332
339
 
333
- ### CommonJS
334
- ```javascript
335
- const genata = require('@drichdev/genata');
336
- genata.email();
337
- ```
340
+ ### Performance issues
338
341
 
339
- ### ES Modules
340
- ```javascript
341
- import genata from '@drichdev/genata';
342
- genata.email();
343
- ```
342
+ For very large datasets:
344
343
 
345
- ### TypeScript
346
- ```typescript
347
- import genata, { type FieldDefinition } from '@drichdev/genata';
348
- ```
344
+ * Generate in chunks
345
+ * Use progress tracking
346
+ * Consider worker threads in browser environments
349
347
 
350
- ### Next.js / React
351
- ```typescript
352
- import genata from '@drichdev/genata';
348
+ ---
353
349
 
354
- export default function Component() {
355
- const data = genata.email();
356
- return <div>{data}</div>;
357
- }
358
- ```
350
+ ## Contributing
351
+
352
+ * TypeScript only
353
+ * Validate all inputs
354
+ * Maintain strong error handling
355
+ * Follow a security-first approach
356
+
357
+
358
+ ---
359
+
360
+ ## Documentation
359
361
 
360
- **⚠️ Note**: If you get a "Module type is not specified" warning, add `"type": "module"` to your `package.json` or use CommonJS require instead.
362
+ See [USAGE.md](./USAGE.md) for advanced usage.
361
363
 
362
364
  ---
363
365
 
364
- Made with ❤️ by Drichdev
366
+ ## Author
365
367
 
368
+ Created by Drichdev
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drichdev/genata",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Generate realistic fake data easily",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",