csv-faker-generator 1.0.0 → 2.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Manoj Kengudelu
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 CHANGED
@@ -1,14 +1,21 @@
1
1
  # CSV Faker Generator
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/csv-faker-generator.svg)](https://www.npmjs.com/package/csv-faker-generator)
4
+ [![npm downloads](https://img.shields.io/npm/dm/csv-faker-generator.svg)](https://www.npmjs.com/package/csv-faker-generator)
5
+ [![CI](https://github.com/manojkken/csv-faker-generator/actions/workflows/ci.yml/badge.svg)](https://github.com/manojkken/csv-faker-generator/actions/workflows/ci.yml)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
7
+
3
8
  Generate CSV files with realistic fake data using customizable headers and data types. Perfect for testing, prototyping, and development.
4
9
 
5
10
  ## Features
6
11
 
7
- - Generate CSV files with custom column headers
8
- - Support for 19+ data types (UUID, names, emails, addresses, etc.)
9
- - Simple CLI interface
10
- - Programmatic API for Node.js projects
11
- - TypeScript support with full type definitions
12
+ - **27+ data types**: UUID, names, emails, addresses, banking info, and more
13
+ - **Advanced data generation**: Alphanumeric strings, pick from custom values, formula-based calculated fields
14
+ - **Flexible number formatting**: Control decimal precision and ranges
15
+ - **Custom delimiters**: Support for comma, semicolon, tab, pipe
16
+ - **Simple CLI interface**: Generate CSV files from command line
17
+ - **Programmatic API**: Use in Node.js/TypeScript projects
18
+ - **Full TypeScript support**: Complete type definitions included
12
19
 
13
20
  ## Installation
14
21
 
@@ -16,34 +23,20 @@ Generate CSV files with realistic fake data using customizable headers and data
16
23
  npm install csv-faker-generator
17
24
  ```
18
25
 
19
- ## Usage
26
+ ## Quick Start
20
27
 
21
28
  ### CLI Usage
22
29
 
23
- Generate a CSV file from the command line:
24
-
25
30
  ```bash
26
31
  # Basic usage
27
32
  npx csv-faker -c id:uuid,name:name,email:email -r 100 -o users.csv
28
33
 
29
- # Generate user data
30
- npx csv-faker --columns "userId:uuid,firstName:firstName,lastName:lastName,email:email,phone:phone" --rows 50 --output customers.csv
31
-
32
- # Generate company data
33
- npx csv-faker -c id:uuid,company:company,city:city,country:country -r 20
34
+ # With custom delimiter
35
+ npx csv-faker -c id:uuid,name:name,email:email --delimiter ";" -r 50 -o contacts.csv
34
36
  ```
35
37
 
36
- #### CLI Options
37
-
38
- - `--columns, -c` - Column definitions (format: `header:type,header:type,...`)
39
- - `--rows, -r` - Number of rows to generate (default: 10)
40
- - `--output, -o` - Output file path (default: output.csv)
41
- - `--help, -h` - Show help message
42
-
43
38
  ### Programmatic Usage
44
39
 
45
- Use in your Node.js/TypeScript projects:
46
-
47
40
  ```typescript
48
41
  import { generateCSV } from 'csv-faker-generator';
49
42
 
@@ -52,109 +45,313 @@ await generateCSV({
52
45
  { header: 'id', type: 'uuid' },
53
46
  { header: 'name', type: 'name' },
54
47
  { header: 'email', type: 'email' },
55
- { header: 'address', type: 'address' },
56
48
  ],
57
49
  rows: 100,
58
50
  output: 'users.csv',
59
51
  });
60
52
  ```
61
53
 
62
- #### With Custom Number Ranges
54
+ ## Advanced Features
55
+
56
+ ### 1. Alphanumeric Type
57
+
58
+ Generate alphanumeric strings with custom length and case:
63
59
 
64
60
  ```typescript
65
61
  await generateCSV({
66
62
  columns: [
67
- { header: 'id', type: 'uuid' },
68
- { header: 'age', type: 'number', min: 18, max: 65 },
69
- { header: 'salary', type: 'number', min: 30000, max: 150000 },
63
+ { header: 'product_code', type: 'alphanumeric', length: 10, uppercase: true },
64
+ { header: 'sku', type: 'alphanumeric', length: 15 },
70
65
  ],
71
- rows: 50,
72
- output: 'employees.csv',
66
+ rows: 100,
67
+ output: 'products.csv',
73
68
  });
74
69
  ```
75
70
 
76
- ## Supported Data Types
71
+ Output:
72
+ ```csv
73
+ product_code,sku
74
+ PMA094QITG,nbdAIBY9Og7gDWd
75
+ SXYBL4LJQO,gakXOrBZYw1tYFP
76
+ ```
77
77
 
78
- | Type | Description | Example |
79
- |------|-------------|---------|
80
- | `uuid` | UUID v4 | `550e8400-e29b-41d4-a716-446655440000` |
81
- | `name` | Full name | `John Doe` |
82
- | `firstName` | First name only | `John` |
83
- | `lastName` | Last name only | `Doe` |
84
- | `email` | Email address | `john.doe@example.com` |
85
- | `phone` | Phone number | `+1-234-567-8900` |
86
- | `address` | Street address | `123 Main St` |
87
- | `city` | City name | `New York` |
88
- | `country` | Country name | `United States` |
89
- | `zipCode` | Postal code | `10001` |
90
- | `company` | Company name | `Tech Corp` |
91
- | `jobTitle` | Job title | `Software Engineer` |
92
- | `number` | Random number | `42` |
93
- | `date` | ISO date string | `2024-01-15T10:30:00.000Z` |
94
- | `boolean` | Boolean value | `true` or `false` |
95
- | `url` | Website URL | `https://example.com` |
96
- | `ip` | IP address | `192.168.1.1` |
97
- | `username` | Username | `john_doe123` |
98
- | `password` | Password | `aB3$xYz9!qW` |
99
-
100
- ## Examples
78
+ ### 2. Pick Type (Enum Values)
101
79
 
102
- ### Example 1: User Database
80
+ Select values from predefined arrays:
103
81
 
104
- ```bash
105
- npx csv-faker -c userId:uuid,username:username,email:email,password:password,createdAt:date -r 1000 -o users.csv
82
+ ```typescript
83
+ await generateCSV({
84
+ columns: [
85
+ { header: 'product', type: 'name' },
86
+ { header: 'tax_rate', type: 'pick', values: [0, 7, 19] },
87
+ { header: 'status', type: 'pick', values: ['active', 'pending', 'inactive'] },
88
+ { header: 'unit', type: 'pick', values: ['g', 'kg', 'Stück', 'Meter'] },
89
+ ],
90
+ rows: 100,
91
+ output: 'products.csv',
92
+ });
106
93
  ```
107
94
 
108
- ### Example 2: E-commerce Orders
95
+ ### 3. Formula Type (Calculated Fields)
96
+
97
+ Create calculated fields based on other columns:
98
+
99
+ ```typescript
100
+ await generateCSV({
101
+ columns: [
102
+ { header: 'product', type: 'company' },
103
+ { header: 'netto', type: 'number', min: 10, max: 200, decimals: 2 },
104
+ { header: 'tax', type: 'pick', values: [0, 7, 19] },
105
+ {
106
+ header: 'brutto',
107
+ type: 'formula',
108
+ formula: (row) => {
109
+ const netto = row.netto;
110
+ const tax = row.tax;
111
+ return parseFloat((netto * (1 + tax / 100)).toFixed(2));
112
+ },
113
+ },
114
+ ],
115
+ rows: 100,
116
+ output: 'invoices.csv',
117
+ });
118
+ ```
119
+
120
+ Output:
121
+ ```csv
122
+ product,netto,tax,brutto
123
+ Reichert LLC,120.39,19,143.26
124
+ Becker LLC,132.14,7,141.39
125
+ ```
126
+
127
+ ### 4. Decimal Precision
128
+
129
+ Control decimal places for number types:
130
+
131
+ ```typescript
132
+ await generateCSV({
133
+ columns: [
134
+ { header: 'price', type: 'number', min: 10, max: 200, decimals: 2 },
135
+ { header: 'weight', type: 'number', min: 0.1, max: 99.9, decimals: 1 },
136
+ { header: 'quantity', type: 'number', min: 1, max: 1000, decimals: 0 }, // integers
137
+ ],
138
+ rows: 100,
139
+ output: 'products.csv',
140
+ });
141
+ ```
142
+
143
+ ### 5. Custom Delimiters
144
+
145
+ Generate CSV files with different delimiters:
146
+
147
+ ```typescript
148
+ // Semicolon-separated
149
+ await generateCSV({
150
+ columns: [{ header: 'id', type: 'uuid' }, { header: 'name', type: 'name' }],
151
+ rows: 100,
152
+ delimiter: ';',
153
+ output: 'contacts.csv',
154
+ });
155
+
156
+ // Tab-separated (TSV)
157
+ await generateCSV({
158
+ columns: [{ header: 'id', type: 'uuid' }, { header: 'name', type: 'name' }],
159
+ rows: 100,
160
+ delimiter: '\t',
161
+ output: 'data.tsv',
162
+ });
163
+ ```
164
+
165
+ ## Complete Example: E-commerce Articles
166
+
167
+ This example demonstrates all advanced features together:
109
168
 
110
169
  ```typescript
111
170
  import { generateCSV } from 'csv-faker-generator';
112
171
 
113
172
  await generateCSV({
114
173
  columns: [
115
- { header: 'orderId', type: 'uuid' },
116
- { header: 'customerName', type: 'name' },
117
- { header: 'email', type: 'email' },
118
- { header: 'amount', type: 'number', min: 10, max: 500 },
119
- { header: 'orderDate', type: 'date' },
120
- { header: 'city', type: 'city' },
121
- { header: 'country', type: 'country' },
174
+ { header: 'Artikelnummer*', type: 'alphanumeric', length: 15 },
175
+ { header: 'Bezeichnung*', type: 'company' },
176
+ { header: 'Beschreibung', type: 'company' },
177
+ { header: 'Verkaufspreis netto in €', type: 'number', min: 10, max: 200, decimals: 2 },
178
+ { header: 'Steuersatz', type: 'pick', values: [0, 7, 19] },
179
+ {
180
+ header: 'Verkaufspreis brutto in €',
181
+ type: 'formula',
182
+ formula: (row) => {
183
+ const netto = row['Verkaufspreis netto in €'];
184
+ const tax = row['Steuersatz'];
185
+ return parseFloat((netto * (1 + tax / 100)).toFixed(2));
186
+ },
187
+ },
188
+ { header: 'Einkaufspreis netto in €', type: 'number', min: 5, max: 100, decimals: 2 },
189
+ { header: 'Einheit', type: 'pick', values: ['Stück', 'kg', 'g', 'Meter', 'Liter'] },
190
+ { header: 'Bestand', type: 'number', min: 0, max: 1000, decimals: 0 },
191
+ { header: 'Kategorie', type: 'pick', values: ['Electronics', 'Food', 'Clothing', 'Books'] },
122
192
  ],
123
- rows: 500,
124
- output: 'orders.csv',
193
+ rows: 100,
194
+ output: 'articles.csv',
125
195
  });
126
196
  ```
127
197
 
128
- ### Example 3: Employee Directory
198
+ ## CLI Reference
199
+
200
+ ### Options
201
+
202
+ - `--columns, -c` - Column definitions (format: `header:type,header:type,...`)
203
+ - `--rows, -r` - Number of rows to generate (default: 10)
204
+ - `--output, -o` - Output file path (default: output.csv)
205
+ - `--delimiter, -d` - Field delimiter (default: `,`) [options: `,` `;` `|` `\t`]
206
+ - `--help, -h` - Show help message
207
+
208
+ ### Examples
129
209
 
130
210
  ```bash
131
- npx csv-faker -c id:uuid,firstName:firstName,lastName:lastName,email:email,phone:phone,jobTitle:jobTitle,company:company -r 200 -o employees.csv
132
- ```
211
+ # Generate users
212
+ npx csv-faker -c id:uuid,name:name,email:email -r 100 -o users.csv
133
213
 
134
- ## API Reference
214
+ # Generate with semicolon delimiter
215
+ npx csv-faker -c id:uuid,name:name,email:email --delimiter ";" -r 50 -o contacts.csv
135
216
 
136
- ### `generateCSV(options: GenerateOptions): Promise<void>`
217
+ # Generate customer data
218
+ npx csv-faker -c customer_number:number,title:title,firstname:firstName,lastname:lastName,email:email,iban:iban,bic:bic -r 200 -o customers.csv
219
+ ```
137
220
 
138
- Generates a CSV file with fake data.
221
+ **Note**: Advanced features like `alphanumeric` with length, `pick` with values, and `formula` require programmatic usage. CLI only supports basic data types.
139
222
 
140
- **Parameters:**
141
- - `options.columns`: Array of column definitions
142
- - `options.rows`: Number of rows to generate
143
- - `options.output`: Output file path
223
+ ## Supported Data Types
224
+
225
+ | Type | Description | Example | CLI | Programmatic |
226
+ |------|-------------|---------|-----|--------------|
227
+ | `uuid` | UUID v4 | `550e8400-e29b-...` | ✓ | ✓ |
228
+ | `name` | Full name | `John Doe` | ✓ | ✓ |
229
+ | `firstName` | First name | `John` | ✓ | ✓ |
230
+ | `lastName` | Last name | `Doe` | ✓ | ✓ |
231
+ | `title` | Person prefix | `Mr.`, `Mrs.`, `Dr.` | ✓ | ✓ |
232
+ | `email` | Email address | `john.doe@example.com` | ✓ | ✓ |
233
+ | `phone` | Phone number | `+1-234-567-8900` | ✓ | ✓ |
234
+ | `address` | Street address | `123 Main St` | ✓ | ✓ |
235
+ | `secondaryAddress` | Apt/Suite | `Apt. 4B` | ✓ | ✓ |
236
+ | `city` | City name | `New York` | ✓ | ✓ |
237
+ | `country` | Country name | `United States` | ✓ | ✓ |
238
+ | `zipCode` | Postal code | `10001` | ✓ | ✓ |
239
+ | `company` | Company name | `Tech Corp` | ✓ | ✓ |
240
+ | `jobTitle` | Job title | `Software Engineer` | ✓ | ✓ |
241
+ | `number` | Random number | `42` | ✓ | ✓ |
242
+ | `date` | ISO date | `2024-01-15T10:30:00.000Z` | ✓ | ✓ |
243
+ | `boolean` | Boolean | `true` / `false` | ✓ | ✓ |
244
+ | `url` | Website URL | `https://example.com` | ✓ | ✓ |
245
+ | `ip` | IP address | `192.168.1.1` | ✓ | ✓ |
246
+ | `username` | Username | `john_doe123` | ✓ | ✓ |
247
+ | `password` | Password | `aB3$xYz9!qW` | ✓ | ✓ |
248
+ | `iban` | IBAN | `DE89370400440532013000` | ✓ | ✓ |
249
+ | `bic` | BIC/SWIFT | `COBADEFFXXX` | ✓ | ✓ |
250
+ | `bankName` | Bank name | `Deutsche Bank` | ✓ | ✓ |
251
+ | `alphanumeric` | Alphanumeric string | `aB3xYz9qW` | ✓* | ✓ |
252
+ | `pick` | Pick from array | Custom values | ✓* | ✓ |
253
+ | `formula` | Calculated value | Based on other fields | ✗ | ✓ |
254
+
255
+ *CLI supports the type but not advanced options (length, uppercase, values, etc.)
256
+
257
+ ## TypeScript API
258
+
259
+ ### Types
144
260
 
145
- **ColumnDefinition:**
146
261
  ```typescript
262
+ type DataType =
263
+ | 'uuid' | 'name' | 'firstName' | 'lastName' | 'title'
264
+ | 'email' | 'phone' | 'address' | 'secondaryAddress'
265
+ | 'city' | 'country' | 'zipCode' | 'company' | 'jobTitle'
266
+ | 'number' | 'date' | 'boolean' | 'url' | 'ip'
267
+ | 'username' | 'password' | 'iban' | 'bic' | 'bankName'
268
+ | 'alphanumeric' | 'pick' | 'formula';
269
+
147
270
  interface ColumnDefinition {
148
271
  header: string;
149
272
  type: DataType;
150
- min?: number; // For 'number' type
151
- max?: number; // For 'number' type
273
+ min?: number; // For 'number' type
274
+ max?: number; // For 'number' type
275
+ length?: number; // For 'alphanumeric' type
276
+ uppercase?: boolean; // For 'alphanumeric' type
277
+ values?: any[]; // For 'pick' type
278
+ formula?: (row: Record<string, any>) => any; // For 'formula' type
279
+ decimals?: number; // For 'number' type
152
280
  }
281
+
282
+ interface GenerateOptions {
283
+ columns: ColumnDefinition[];
284
+ rows: number;
285
+ output: string;
286
+ delimiter?: string; // Default: ','
287
+ }
288
+
289
+ function generateCSV(options: GenerateOptions): Promise<void>;
290
+ ```
291
+
292
+ ## More Examples
293
+
294
+ ### Example 1: User Database
295
+
296
+ ```typescript
297
+ await generateCSV({
298
+ columns: [
299
+ { header: 'userId', type: 'uuid' },
300
+ { header: 'username', type: 'username' },
301
+ { header: 'email', type: 'email' },
302
+ { header: 'password', type: 'password' },
303
+ { header: 'createdAt', type: 'date' },
304
+ ],
305
+ rows: 1000,
306
+ output: 'users.csv',
307
+ });
153
308
  ```
154
309
 
155
- ### `parseColumnString(columnStr: string): ColumnDefinition`
310
+ ### Example 2: Banking Data
311
+
312
+ ```typescript
313
+ await generateCSV({
314
+ columns: [
315
+ { header: 'accountId', type: 'uuid' },
316
+ { header: 'accountOwner', type: 'name' },
317
+ { header: 'iban', type: 'iban' },
318
+ { header: 'bic', type: 'bic' },
319
+ { header: 'bankName', type: 'bankName' },
320
+ { header: 'balance', type: 'number', min: 0, max: 100000, decimals: 2 },
321
+ ],
322
+ rows: 500,
323
+ output: 'accounts.csv',
324
+ });
325
+ ```
326
+
327
+ ### Example 3: Inventory System
328
+
329
+ ```typescript
330
+ await generateCSV({
331
+ columns: [
332
+ { header: 'SKU', type: 'alphanumeric', length: 12, uppercase: true },
333
+ { header: 'Product', type: 'company' },
334
+ { header: 'Category', type: 'pick', values: ['Electronics', 'Furniture', 'Clothing', 'Food'] },
335
+ { header: 'Price', type: 'number', min: 5, max: 500, decimals: 2 },
336
+ { header: 'Stock', type: 'number', min: 0, max: 1000, decimals: 0 },
337
+ { header: 'Status', type: 'pick', values: ['In Stock', 'Low Stock', 'Out of Stock'] },
338
+ ],
339
+ rows: 200,
340
+ output: 'inventory.csv',
341
+ });
342
+ ```
343
+
344
+ ## Future Features (Roadmap)
345
+
346
+ Based on community feedback, we're considering:
347
+
348
+ - Locale support for region-specific data
349
+ - Templates/presets for common use cases
350
+ - Row dependencies and conditional values
351
+ - Related dataset generation (parent-child relationships)
352
+ - More business data types (VAT numbers, tax IDs, etc.)
156
353
 
157
- Parses a column string (e.g., "id:uuid") into a ColumnDefinition object.
354
+ See [issues](https://github.com/yourusername/csv-faker-generator/issues) for discussions and requests.
158
355
 
159
356
  ## License
160
357
 
@@ -164,6 +361,6 @@ MIT
164
361
 
165
362
  Contributions are welcome! Please feel free to submit a Pull Request.
166
363
 
167
- ## Issues
364
+ ## Issues & Support
168
365
 
169
366
  Found a bug or have a feature request? Please open an issue on [GitHub](https://github.com/yourusername/csv-faker-generator/issues).
package/dist/cli.js CHANGED
@@ -14,23 +14,30 @@ Options:
14
14
  --columns, -c Column definitions (format: header:type,header:type,...)
15
15
  --rows, -r Number of rows to generate (default: 10)
16
16
  --output, -o Output file path (default: output.csv)
17
+ --delimiter, -d Field delimiter (default: ,) [options: , ; | \\t]
17
18
  --help, -h Show this help message
18
19
 
19
20
  Data Types:
20
- uuid, name, firstName, lastName, email, phone, address, city,
21
- country, zipCode, company, jobTitle, number, date, boolean,
22
- url, ip, username, password
21
+ uuid, name, firstName, lastName, title, email, phone, address,
22
+ secondaryAddress, city, country, zipCode, company, jobTitle,
23
+ number, date, boolean, url, ip, username, password, iban, bic,
24
+ bankName, alphanumeric, pick
25
+
26
+ Note: Advanced features (alphanumeric length, pick values, formula)
27
+ require programmatic usage. See README for examples.
23
28
 
24
29
  Examples:
25
30
  csv-faker -c id:uuid,name:name,email:email -r 100 -o users.csv
26
31
  csv-faker -c userId:uuid,firstName:firstName,lastName:lastName,email:email,address:address -r 50
27
32
  csv-faker --columns "id:uuid,company:company,city:city" --rows 20 --output companies.csv
33
+ csv-faker -c id:uuid,name:name,email:email --delimiter ";" -r 50 -o contacts.csv
28
34
  `);
29
35
  }
30
36
  function parseArgs() {
31
37
  let columnsStr = '';
32
38
  let rows = 10;
33
39
  let output = 'output.csv';
40
+ let delimiter = ',';
34
41
  for (let i = 0; i < args.length; i++) {
35
42
  const arg = args[i];
36
43
  if (arg === '--help' || arg === '-h') {
@@ -50,6 +57,13 @@ function parseArgs() {
50
57
  else if (arg === '--output' || arg === '-o') {
51
58
  output = args[++i];
52
59
  }
60
+ else if (arg === '--delimiter' || arg === '-d') {
61
+ delimiter = args[++i];
62
+ // Handle common escape sequences
63
+ if (delimiter === '\\t') {
64
+ delimiter = '\t';
65
+ }
66
+ }
53
67
  }
54
68
  if (!columnsStr) {
55
69
  console.error('Error: --columns is required\n');
@@ -57,7 +71,7 @@ function parseArgs() {
57
71
  process.exit(1);
58
72
  }
59
73
  const columns = columnsStr.split(',').map(index_1.parseColumnString);
60
- return { columns, rows, output };
74
+ return { columns, rows, output, delimiter };
61
75
  }
62
76
  async function main() {
63
77
  try {
package/dist/index.d.ts CHANGED
@@ -1,14 +1,20 @@
1
- export type DataType = 'uuid' | 'name' | 'firstName' | 'lastName' | 'title' | 'email' | 'phone' | 'address' | 'secondaryAddress' | 'city' | 'country' | 'zipCode' | 'company' | 'jobTitle' | 'number' | 'date' | 'boolean' | 'url' | 'ip' | 'username' | 'password' | 'iban' | 'bic' | 'bankName';
1
+ export type DataType = 'uuid' | 'name' | 'firstName' | 'lastName' | 'title' | 'email' | 'phone' | 'address' | 'secondaryAddress' | 'city' | 'country' | 'zipCode' | 'company' | 'jobTitle' | 'number' | 'date' | 'boolean' | 'url' | 'ip' | 'username' | 'password' | 'iban' | 'bic' | 'bankName' | 'alphanumeric' | 'pick' | 'formula';
2
2
  export interface ColumnDefinition {
3
3
  header: string;
4
4
  type: DataType;
5
5
  min?: number;
6
6
  max?: number;
7
+ length?: number;
8
+ uppercase?: boolean;
9
+ values?: any[];
10
+ formula?: (row: Record<string, any>) => any;
11
+ decimals?: number;
7
12
  }
8
13
  export interface GenerateOptions {
9
14
  columns: ColumnDefinition[];
10
15
  rows: number;
11
16
  output: string;
17
+ delimiter?: string;
12
18
  }
13
19
  export declare function generateCSV(options: GenerateOptions): Promise<void>;
14
20
  export declare function parseColumnString(columnStr: string): ColumnDefinition;
package/dist/index.js CHANGED
@@ -4,7 +4,8 @@ exports.generateCSV = generateCSV;
4
4
  exports.parseColumnString = parseColumnString;
5
5
  const faker_1 = require("@faker-js/faker");
6
6
  const csv_writer_1 = require("csv-writer");
7
- function generateValue(type, min, max) {
7
+ function generateValue(column, row) {
8
+ const { type, min, max, length, uppercase, values, decimals } = column;
8
9
  switch (type) {
9
10
  case 'uuid':
10
11
  return faker_1.faker.string.uuid();
@@ -34,8 +35,14 @@ function generateValue(type, min, max) {
34
35
  return faker_1.faker.company.name();
35
36
  case 'jobTitle':
36
37
  return faker_1.faker.person.jobTitle();
37
- case 'number':
38
- return faker_1.faker.number.int({ min: min || 1, max: max || 1000 });
38
+ case 'number': {
39
+ const num = faker_1.faker.number.int({ min: min ?? 1, max: max ?? 1000 });
40
+ if (decimals !== undefined) {
41
+ const float = faker_1.faker.number.float({ min: min ?? 1, max: max ?? 1000, fractionDigits: decimals });
42
+ return parseFloat(float.toFixed(decimals));
43
+ }
44
+ return num;
45
+ }
39
46
  case 'date':
40
47
  return faker_1.faker.date.recent().toISOString();
41
48
  case 'boolean':
@@ -54,24 +61,54 @@ function generateValue(type, min, max) {
54
61
  return faker_1.faker.finance.bic();
55
62
  case 'bankName':
56
63
  return faker_1.faker.company.name() + ' Bank';
64
+ case 'alphanumeric': {
65
+ const len = length || 10;
66
+ let result = faker_1.faker.string.alphanumeric(len);
67
+ if (uppercase) {
68
+ result = result.toUpperCase();
69
+ }
70
+ return result;
71
+ }
72
+ case 'pick': {
73
+ if (!values || values.length === 0) {
74
+ throw new Error('pick type requires values array');
75
+ }
76
+ return faker_1.faker.helpers.arrayElement(values);
77
+ }
78
+ case 'formula': {
79
+ if (!column.formula || !row) {
80
+ throw new Error('formula type requires formula function and row context');
81
+ }
82
+ return column.formula(row);
83
+ }
57
84
  default:
58
85
  return faker_1.faker.lorem.word();
59
86
  }
60
87
  }
61
88
  async function generateCSV(options) {
62
- const { columns, rows, output } = options;
89
+ const { columns, rows, output, delimiter = ',' } = options;
63
90
  const csvWriter = (0, csv_writer_1.createObjectCsvWriter)({
64
91
  path: output,
65
92
  header: columns.map((col) => ({
66
93
  id: col.header,
67
94
  title: col.header,
68
95
  })),
96
+ fieldDelimiter: delimiter,
69
97
  });
70
98
  const records = [];
71
99
  for (let i = 0; i < rows; i++) {
72
100
  const record = {};
101
+ // First pass: generate non-formula columns
102
+ for (const column of columns) {
103
+ if (column.type !== 'formula') {
104
+ record[column.header] = generateValue(column, record);
105
+ }
106
+ }
107
+ // Second pass: generate formula columns (they can reference other columns)
73
108
  for (const column of columns) {
74
- record[column.header] = generateValue(column.type, column.min, column.max);
109
+ if (column.type === 'formula') {
110
+ record[column.header] = generateValue(column, record);
111
+ }
75
112
  }
76
113
  records.push(record);
77
114
  }
@@ -89,7 +126,7 @@ function parseColumnString(columnStr) {
89
126
  'uuid', 'name', 'firstName', 'lastName', 'title', 'email', 'phone',
90
127
  'address', 'secondaryAddress', 'city', 'country', 'zipCode', 'company', 'jobTitle',
91
128
  'number', 'date', 'boolean', 'url', 'ip', 'username', 'password',
92
- 'iban', 'bic', 'bankName'
129
+ 'iban', 'bic', 'bankName', 'alphanumeric', 'pick'
93
130
  ];
94
131
  if (!validTypes.includes(type)) {
95
132
  throw new Error(`Invalid data type: ${type}. Valid types: ${validTypes.join(', ')}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "csv-faker-generator",
3
- "version": "1.0.0",
4
- "description": "Generate CSV files with fake data using custom headers (UUID, names, emails, addresses, etc.)",
3
+ "version": "2.0.1",
4
+ "description": "Generate CSV files with fake data: 27+ data types, alphanumeric strings, pick from custom values, formula fields, decimal precision, custom delimiters. Perfect for testing and prototyping.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "bin": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/manojkken/csv-faker-generator.git"
12
+ "url": "git+https://github.com/manojkken/csv-faker-generator.git"
13
13
  },
14
14
  "homepage": "https://github.com/manojkken/csv-faker-generator#readme",
15
15
  "bugs": {
@@ -18,7 +18,7 @@
18
18
  "scripts": {
19
19
  "build": "tsc",
20
20
  "prepare": "npm run build",
21
- "test": "node dist/example.js"
21
+ "test": "npm run build && node --test test/index.test.js"
22
22
  },
23
23
  "keywords": [
24
24
  "csv",
@@ -27,13 +27,26 @@
27
27
  "generator",
28
28
  "uuid",
29
29
  "csv-generator",
30
- "mock-data"
30
+ "mock-data",
31
+ "alphanumeric",
32
+ "formula",
33
+ "calculated-fields",
34
+ "enum",
35
+ "pick",
36
+ "delimiter",
37
+ "test-data",
38
+ "prototyping",
39
+ "iban",
40
+ "banking"
31
41
  ],
32
42
  "author": "Manoj Kengudelu",
33
43
  "license": "MIT",
34
44
  "files": [
35
45
  "dist",
36
- "README.md"
46
+ "!dist/example.*",
47
+ "!dist/test-advanced.*",
48
+ "README.md",
49
+ "LICENSE"
37
50
  ],
38
51
  "dependencies": {
39
52
  "@faker-js/faker": "^10.1.0",
@@ -43,4 +56,4 @@
43
56
  "@types/node": "^24.10.1",
44
57
  "typescript": "^5.9.3"
45
58
  }
46
- }
59
+ }
package/dist/example.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/example.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_1 = require("./index");
4
- async function runExamples() {
5
- console.log('Running CSV Faker Generator examples...\n');
6
- console.log('Example 1: Generating user data...');
7
- await (0, index_1.generateCSV)({
8
- columns: [
9
- { header: 'id', type: 'uuid' },
10
- { header: 'name', type: 'name' },
11
- { header: 'email', type: 'email' },
12
- { header: 'address', type: 'address' },
13
- { header: 'phone', type: 'phone' },
14
- ],
15
- rows: 10,
16
- output: 'example-users.csv',
17
- });
18
- console.log('\nExample 2: Generating employee data with age range...');
19
- await (0, index_1.generateCSV)({
20
- columns: [
21
- { header: 'employeeId', type: 'uuid' },
22
- { header: 'firstName', type: 'firstName' },
23
- { header: 'lastName', type: 'lastName' },
24
- { header: 'email', type: 'email' },
25
- { header: 'age', type: 'number', min: 22, max: 65 },
26
- { header: 'jobTitle', type: 'jobTitle' },
27
- { header: 'company', type: 'company' },
28
- { header: 'salary', type: 'number', min: 40000, max: 150000 },
29
- ],
30
- rows: 15,
31
- output: 'example-employees.csv',
32
- });
33
- console.log('\nExample 3: Generating company data...');
34
- await (0, index_1.generateCSV)({
35
- columns: [
36
- { header: 'companyId', type: 'uuid' },
37
- { header: 'companyName', type: 'company' },
38
- { header: 'city', type: 'city' },
39
- { header: 'country', type: 'country' },
40
- { header: 'website', type: 'url' },
41
- { header: 'verified', type: 'boolean' },
42
- ],
43
- rows: 8,
44
- output: 'example-companies.csv',
45
- });
46
- console.log('\n✓ All examples completed successfully!');
47
- console.log('\nGenerated files:');
48
- console.log(' - example-users.csv (10 rows)');
49
- console.log(' - example-employees.csv (15 rows)');
50
- console.log(' - example-companies.csv (8 rows)');
51
- }
52
- runExamples().catch((error) => {
53
- console.error('Error running examples:', error);
54
- process.exit(1);
55
- });