@drichdev/genata 1.0.2 → 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.
package/README.md CHANGED
@@ -2,47 +2,90 @@
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
- npm install genata
31
+ npm install @drichdev/genata
19
32
  # or
20
- yarn add genata
33
+ yarn add @drichdev/genata
21
34
  # or
22
- pnpm add genata
35
+ pnpm add @drichdev/genata
23
36
  ```
24
37
 
25
- ## 🎯 Quick Start
38
+ ---
39
+
40
+ ## Import
26
41
 
27
- ### Basic Usage
42
+ ### ES Modules (recommended)
28
43
 
29
44
  ```javascript
30
- import genata from "genata";
45
+ import genata from '@drichdev/genata';
46
+ ```
47
+
48
+ ### CommonJS
49
+
50
+ ```javascript
51
+ const genata = require('@drichdev/genata');
52
+ ```
53
+
54
+ ### TypeScript
55
+
56
+ ```typescript
57
+ import genata, { type FieldDefinition } from '@drichdev/genata';
58
+ ```
59
+
60
+ ---
61
+
62
+ ## Quick Start
63
+
64
+ ```javascript
65
+ import genata from '@drichdev/genata';
31
66
 
32
- // Generate single values
33
67
  const email = genata.email();
34
68
  const firstName = genata.firstName();
35
69
  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
70
  ```
41
71
 
42
- ### Using Generators by Category
72
+ ---
73
+
74
+ ## Naming Convention
75
+
76
+ * Direct API uses camelCase
77
+ `genata.firstName()`
78
+
79
+ * Batch generation uses snake_case
80
+ `type: "first_name"`
81
+
82
+ ---
83
+
84
+ ## Generators
85
+
86
+ ### Person
43
87
 
44
88
  ```javascript
45
- // Person generators
46
89
  genata.person.firstName();
47
90
  genata.person.lastName();
48
91
  genata.person.fullName();
@@ -50,46 +93,64 @@ genata.person.email();
50
93
  genata.person.username();
51
94
  genata.person.password();
52
95
  genata.person.phone();
96
+ ```
53
97
 
54
- // Location generators
98
+ ### Location
99
+
100
+ ```javascript
55
101
  genata.location.address();
56
102
  genata.location.city();
57
103
  genata.location.country();
58
104
  genata.location.zipCode();
105
+ ```
106
+
107
+ ### Internet
59
108
 
60
- // Internet generators
109
+ ```javascript
61
110
  genata.internet.url();
62
111
  genata.internet.ipv4();
63
112
  genata.internet.ipv6();
64
113
  genata.internet.creditCard();
114
+ ```
65
115
 
66
- // Company generators
116
+ ### Company
117
+
118
+ ```javascript
67
119
  genata.company.company();
68
120
  genata.company.jobTitle();
121
+ ```
122
+
123
+ ### Date
69
124
 
70
- // Date generators
125
+ ```javascript
71
126
  genata.date.date();
72
127
  genata.date.dateTime();
73
128
  genata.date.futureDate();
129
+ ```
130
+
131
+ ### Data Types
74
132
 
75
- // Data type generators
133
+ ```javascript
76
134
  genata.datatype.uuid();
77
135
  genata.datatype.boolean();
78
136
  genata.datatype.integer({ min: 0, max: 100 });
79
137
  genata.datatype.float({ min: 0, max: 100, decimals: 2 });
80
138
  genata.datatype.color();
81
139
  genata.datatype.hex({ length: 16 });
140
+ ```
82
141
 
83
- // Text generators
142
+ ### Text
143
+
144
+ ```javascript
84
145
  genata.text.sentence();
85
146
  genata.text.paragraph({ sentences: 5 });
86
147
  genata.text.word();
87
148
  genata.text.slug();
88
149
  ```
89
150
 
90
- ### Batch Generation
151
+ ---
91
152
 
92
- Generate multiple records at once:
153
+ ## Batch Generation
93
154
 
94
155
  ```javascript
95
156
  const fields = [
@@ -101,44 +162,22 @@ const fields = [
101
162
  { name: "createdAt", type: "datetime" },
102
163
  ];
103
164
 
104
- // Generate 100 records (default)
165
+ // Default (100 records)
105
166
  const users = genata.generateBatch(fields);
106
167
 
107
- // Generate 1000 records
168
+ // Custom count
108
169
  const largeDataset = genata.generateBatch(fields, { count: 1000 });
109
170
 
110
- // With progress tracking
171
+ // With progress
111
172
  const data = genata.generateBatchWithProgress(fields, {
112
173
  count: 10000,
113
174
  onProgress: (progress) => console.log(`${progress}% complete`),
114
175
  });
115
176
  ```
116
177
 
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
178
+ ---
140
179
 
141
- When using batch generation, supported field types are:
180
+ ## Supported Field Types
142
181
 
143
182
  ```
144
183
  Person: first_name, last_name, full_name, email, username, password, phone
@@ -146,159 +185,184 @@ Location: address, city, country, zip
146
185
  Internet: url, ipv4, ipv6, credit_card
147
186
  Company: company, job_title
148
187
  Date: date, datetime
149
- Data Types: uuid, boolean, int, float, number, zero_one, id_increment, color
150
- Text: sentence, paragraph
188
+ Data Types: uuid, boolean, int, float, number, zero_one, id_increment, color, hex
189
+ Text: sentence, paragraph, word, slug
151
190
  ```
152
191
 
153
- ## 🎛️ 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
+ ---
154
207
 
155
- ### Core Methods
208
+ ## API Reference
156
209
 
157
- #### `genata.email()`
210
+ ### `genata.email()`
158
211
 
159
- Generate a random email address.
212
+ Generate a random email.
160
213
 
161
214
  ```javascript
162
215
  const email = genata.email();
163
- // "alice.johnson@example.com"
164
216
  ```
165
217
 
166
- #### `genata.generateBatch(fields, options?)`
218
+ ---
219
+
220
+ ### `genata.generateBatch(fields, options?)`
167
221
 
168
222
  Generate multiple records.
169
223
 
170
224
  **Parameters:**
171
225
 
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
226
+ * `fields`: Array of field definitions
227
+ * `options`:
177
228
 
178
- **Returns:** Array of objects with generated data
229
+ * `count` (default: 100)
230
+ * `seed`
231
+ * `locale`
179
232
 
180
- #### `genata.setSeed(seed)`
233
+ **Returns:** Array of objects
181
234
 
182
- Set a seed for reproducible data generation.
235
+ ---
183
236
 
184
- **Parameters:**
237
+ ### `genata.setSeed(seed)`
185
238
 
186
- - `seed` (number): Non-negative integer seed value
239
+ Set a seed for reproducible results.
187
240
 
188
- #### `genata.resetSeed()`
241
+ ---
189
242
 
190
- Reset to random generation without a seed.
243
+ ### `genata.resetSeed()`
191
244
 
192
- ## 🏗️ Architecture
245
+ Reset random generation.
193
246
 
194
- The library is organized into modules:
247
+ ---
195
248
 
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)
249
+ ## Examples
200
250
 
201
- ## 🧪 Testing
251
+ ### Generate Users
202
252
 
203
- ```bash
204
- 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
+ );
205
267
  ```
206
268
 
207
- ## 📄 License
269
+ ---
208
270
 
209
- MIT
271
+ ### Generate Products
210
272
 
211
- ## 🤝 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
+ ```
212
286
 
213
- Contributions are welcome! Please ensure:
287
+ ---
214
288
 
215
- - All code is TypeScript
216
- - Security-first approach
217
- - Input validation for all public methods
218
- - Comprehensive error messages
289
+ ### Reproducible Tests
219
290
 
220
- ## 📚 Examples
291
+ ```javascript
292
+ beforeEach(() => {
293
+ genata.setSeed(42);
294
+ });
221
295
 
222
- ### Generate Test Users
296
+ const user1 = { email: genata.email() };
223
297
 
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);
298
+ genata.setSeed(42);
299
+ const user2 = { email: genata.email() };
245
300
  ```
246
301
 
247
- ### Generate E-commerce Products
302
+ ---
248
303
 
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
- ```
304
+ ## Security
264
305
 
265
- ### 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
266
310
 
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
- });
311
+ ---
312
+
313
+ ## Architecture
314
+
315
+ * `generators`: data generation logic
316
+ * `types`: TypeScript definitions
317
+ * `validators`: input validation
318
+ * `utils`: internal helpers
319
+
320
+ ---
321
+
322
+ ## Testing
323
+
324
+ ```bash
325
+ npm test
282
326
  ```
283
327
 
284
- ## 🐛 Troubleshooting
328
+ ---
329
+
330
+ ## Troubleshooting
331
+
332
+ ### Invalid field type
333
+
334
+ Ensure the field type exists in the supported list.
335
+
336
+ ### Seed not working
285
337
 
286
- ### "Invalid field type" error
338
+ Set the seed before generating data and avoid mixing seeded and non-seeded calls.
287
339
 
288
- Make sure you're using a valid field type from the supported list.
340
+ ### Performance issues
289
341
 
290
- ### Data is not reproducible with seed
342
+ For very large datasets:
291
343
 
292
- Make sure to set the seed before generating data and don't mix generator calls without resetting.
344
+ * Generate in chunks
345
+ * Use progress tracking
346
+ * Consider worker threads in browser environments
293
347
 
294
- ### Performance issues with large batches
348
+ ---
349
+
350
+ ## Contributing
295
351
 
296
- For very large batches (>100K records), consider:
352
+ * TypeScript only
353
+ * Validate all inputs
354
+ * Maintain strong error handling
355
+ * Follow a security-first approach
297
356
 
298
- - Generating in chunks
299
- - Using `generateBatchWithProgress` to show progress
300
- - Running in a worker thread if in browser
301
357
 
302
358
  ---
303
359
 
304
- Made with ❤️ by Drichdev
360
+ ## Documentation
361
+
362
+ See [USAGE.md](./USAGE.md) for advanced usage.
363
+
364
+ ---
365
+
366
+ ## Author
367
+
368
+ Created by Drichdev
package/dist/index.d.ts CHANGED
@@ -7,7 +7,6 @@
7
7
  * - genata.person.firstName() - generates a first name
8
8
  * - genata.generateBatch([...]) - generates multiple records
9
9
  */
10
- import { PersonGenerators, LocationGenerators, InternetGenerators, CompanyGenerators, DateGenerators, DataTypeGenerators, TextGenerators, generateBatch, generateBatchWithProgress } from "./generators";
11
10
  import type { FieldDefinition, BatchGeneratorOptions } from "./types";
12
11
  /**
13
12
  * Main Genata API
@@ -89,8 +88,5 @@ declare const genata: {
89
88
  resetSeed: () => void;
90
89
  setLocale: (locale: string) => void;
91
90
  };
92
- export default genata;
93
- export * from "./types";
94
- export * from "./validators";
95
- export { PersonGenerators, LocationGenerators, InternetGenerators, CompanyGenerators, DateGenerators, DataTypeGenerators, TextGenerators, generateBatch, generateBatchWithProgress, };
91
+ export = genata;
96
92
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,c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BAAwhB,CAAC;;;;;;;qBAA2uB,CAAC;;;;;4BA1B/vI,eAAe,EAAE,YACf,qBAAqB;wCAIvB,eAAe,EAAE,YACf,qBAAqB,GAAG;QAAE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE;oBAI/D,MAAM;;wBASF,MAAM;CAI3B,CAAC;AAEF,SAAS,MAAM,CAAC"}
package/dist/index.js CHANGED
@@ -8,32 +8,7 @@
8
8
  * - genata.person.firstName() - generates a first name
9
9
  * - genata.generateBatch([...]) - generates multiple records
10
10
  */
11
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- var desc = Object.getOwnPropertyDescriptor(m, k);
14
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
- desc = { enumerable: true, get: function() { return m[k]; } };
16
- }
17
- Object.defineProperty(o, k2, desc);
18
- }) : (function(o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- }));
22
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
23
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.generateBatchWithProgress = exports.generateBatch = exports.TextGenerators = exports.DataTypeGenerators = exports.DateGenerators = exports.CompanyGenerators = exports.InternetGenerators = exports.LocationGenerators = exports.PersonGenerators = void 0;
27
11
  const generators_1 = require("./generators");
28
- Object.defineProperty(exports, "PersonGenerators", { enumerable: true, get: function () { return generators_1.PersonGenerators; } });
29
- Object.defineProperty(exports, "LocationGenerators", { enumerable: true, get: function () { return generators_1.LocationGenerators; } });
30
- Object.defineProperty(exports, "InternetGenerators", { enumerable: true, get: function () { return generators_1.InternetGenerators; } });
31
- Object.defineProperty(exports, "CompanyGenerators", { enumerable: true, get: function () { return generators_1.CompanyGenerators; } });
32
- Object.defineProperty(exports, "DateGenerators", { enumerable: true, get: function () { return generators_1.DateGenerators; } });
33
- Object.defineProperty(exports, "DataTypeGenerators", { enumerable: true, get: function () { return generators_1.DataTypeGenerators; } });
34
- Object.defineProperty(exports, "TextGenerators", { enumerable: true, get: function () { return generators_1.TextGenerators; } });
35
- Object.defineProperty(exports, "generateBatch", { enumerable: true, get: function () { return generators_1.generateBatch; } });
36
- Object.defineProperty(exports, "generateBatchWithProgress", { enumerable: true, get: function () { return generators_1.generateBatchWithProgress; } });
37
12
  const faker_1 = require("./utils/faker");
38
13
  const validators_1 = require("./validators");
39
14
  /**
@@ -72,6 +47,4 @@ const genata = {
72
47
  (0, faker_1.initializeFaker)({ locale });
73
48
  },
74
49
  };
75
- exports.default = genata;
76
- __exportStar(require("./types"), exports);
77
- __exportStar(require("./validators"), exports);
50
+ module.exports = genata;
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@drichdev/genata",
3
- "version": "1.0.2",
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",
7
- "module": "dist/index.esm.js",
8
7
  "files": [
9
8
  "dist"
10
9
  ],
@@ -22,7 +21,7 @@
22
21
  "testing",
23
22
  "data-generator"
24
23
  ],
25
- "author": "Genata",
24
+ "author": "Drichdev",
26
25
  "license": "MIT",
27
26
  "dependencies": {
28
27
  "@faker-js/faker": "^10.0.0"