csv-faker-generator 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/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # CSV Faker Generator
2
+
3
+ Generate CSV files with realistic fake data using customizable headers and data types. Perfect for testing, prototyping, and development.
4
+
5
+ ## Features
6
+
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
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install csv-faker-generator
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### CLI Usage
22
+
23
+ Generate a CSV file from the command line:
24
+
25
+ ```bash
26
+ # Basic usage
27
+ npx csv-faker -c id:uuid,name:name,email:email -r 100 -o users.csv
28
+
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
+ ```
35
+
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
+ ### Programmatic Usage
44
+
45
+ Use in your Node.js/TypeScript projects:
46
+
47
+ ```typescript
48
+ import { generateCSV } from 'csv-faker-generator';
49
+
50
+ await generateCSV({
51
+ columns: [
52
+ { header: 'id', type: 'uuid' },
53
+ { header: 'name', type: 'name' },
54
+ { header: 'email', type: 'email' },
55
+ { header: 'address', type: 'address' },
56
+ ],
57
+ rows: 100,
58
+ output: 'users.csv',
59
+ });
60
+ ```
61
+
62
+ #### With Custom Number Ranges
63
+
64
+ ```typescript
65
+ await generateCSV({
66
+ columns: [
67
+ { header: 'id', type: 'uuid' },
68
+ { header: 'age', type: 'number', min: 18, max: 65 },
69
+ { header: 'salary', type: 'number', min: 30000, max: 150000 },
70
+ ],
71
+ rows: 50,
72
+ output: 'employees.csv',
73
+ });
74
+ ```
75
+
76
+ ## Supported Data Types
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
101
+
102
+ ### Example 1: User Database
103
+
104
+ ```bash
105
+ npx csv-faker -c userId:uuid,username:username,email:email,password:password,createdAt:date -r 1000 -o users.csv
106
+ ```
107
+
108
+ ### Example 2: E-commerce Orders
109
+
110
+ ```typescript
111
+ import { generateCSV } from 'csv-faker-generator';
112
+
113
+ await generateCSV({
114
+ 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' },
122
+ ],
123
+ rows: 500,
124
+ output: 'orders.csv',
125
+ });
126
+ ```
127
+
128
+ ### Example 3: Employee Directory
129
+
130
+ ```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
+ ```
133
+
134
+ ## API Reference
135
+
136
+ ### `generateCSV(options: GenerateOptions): Promise<void>`
137
+
138
+ Generates a CSV file with fake data.
139
+
140
+ **Parameters:**
141
+ - `options.columns`: Array of column definitions
142
+ - `options.rows`: Number of rows to generate
143
+ - `options.output`: Output file path
144
+
145
+ **ColumnDefinition:**
146
+ ```typescript
147
+ interface ColumnDefinition {
148
+ header: string;
149
+ type: DataType;
150
+ min?: number; // For 'number' type
151
+ max?: number; // For 'number' type
152
+ }
153
+ ```
154
+
155
+ ### `parseColumnString(columnStr: string): ColumnDefinition`
156
+
157
+ Parses a column string (e.g., "id:uuid") into a ColumnDefinition object.
158
+
159
+ ## License
160
+
161
+ MIT
162
+
163
+ ## Contributing
164
+
165
+ Contributions are welcome! Please feel free to submit a Pull Request.
166
+
167
+ ## Issues
168
+
169
+ 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.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const index_1 = require("./index");
5
+ const args = process.argv.slice(2);
6
+ function showHelp() {
7
+ console.log(`
8
+ CSV Faker Generator
9
+
10
+ Usage:
11
+ csv-faker [options]
12
+
13
+ Options:
14
+ --columns, -c Column definitions (format: header:type,header:type,...)
15
+ --rows, -r Number of rows to generate (default: 10)
16
+ --output, -o Output file path (default: output.csv)
17
+ --help, -h Show this help message
18
+
19
+ Data Types:
20
+ uuid, name, firstName, lastName, email, phone, address, city,
21
+ country, zipCode, company, jobTitle, number, date, boolean,
22
+ url, ip, username, password
23
+
24
+ Examples:
25
+ csv-faker -c id:uuid,name:name,email:email -r 100 -o users.csv
26
+ csv-faker -c userId:uuid,firstName:firstName,lastName:lastName,email:email,address:address -r 50
27
+ csv-faker --columns "id:uuid,company:company,city:city" --rows 20 --output companies.csv
28
+ `);
29
+ }
30
+ function parseArgs() {
31
+ let columnsStr = '';
32
+ let rows = 10;
33
+ let output = 'output.csv';
34
+ for (let i = 0; i < args.length; i++) {
35
+ const arg = args[i];
36
+ if (arg === '--help' || arg === '-h') {
37
+ showHelp();
38
+ process.exit(0);
39
+ }
40
+ else if (arg === '--columns' || arg === '-c') {
41
+ columnsStr = args[++i];
42
+ }
43
+ else if (arg === '--rows' || arg === '-r') {
44
+ rows = parseInt(args[++i], 10);
45
+ if (isNaN(rows) || rows < 1) {
46
+ console.error('Error: rows must be a positive number');
47
+ process.exit(1);
48
+ }
49
+ }
50
+ else if (arg === '--output' || arg === '-o') {
51
+ output = args[++i];
52
+ }
53
+ }
54
+ if (!columnsStr) {
55
+ console.error('Error: --columns is required\n');
56
+ showHelp();
57
+ process.exit(1);
58
+ }
59
+ const columns = columnsStr.split(',').map(index_1.parseColumnString);
60
+ return { columns, rows, output };
61
+ }
62
+ async function main() {
63
+ try {
64
+ const options = parseArgs();
65
+ await (0, index_1.generateCSV)(options);
66
+ }
67
+ catch (error) {
68
+ console.error('Error:', error instanceof Error ? error.message : error);
69
+ process.exit(1);
70
+ }
71
+ }
72
+ main();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,55 @@
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
+ });
@@ -0,0 +1,15 @@
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';
2
+ export interface ColumnDefinition {
3
+ header: string;
4
+ type: DataType;
5
+ min?: number;
6
+ max?: number;
7
+ }
8
+ export interface GenerateOptions {
9
+ columns: ColumnDefinition[];
10
+ rows: number;
11
+ output: string;
12
+ }
13
+ export declare function generateCSV(options: GenerateOptions): Promise<void>;
14
+ export declare function parseColumnString(columnStr: string): ColumnDefinition;
15
+ export { DataType as DataTypes };
package/dist/index.js ADDED
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCSV = generateCSV;
4
+ exports.parseColumnString = parseColumnString;
5
+ const faker_1 = require("@faker-js/faker");
6
+ const csv_writer_1 = require("csv-writer");
7
+ function generateValue(type, min, max) {
8
+ switch (type) {
9
+ case 'uuid':
10
+ return faker_1.faker.string.uuid();
11
+ case 'name':
12
+ return faker_1.faker.person.fullName();
13
+ case 'firstName':
14
+ return faker_1.faker.person.firstName();
15
+ case 'lastName':
16
+ return faker_1.faker.person.lastName();
17
+ case 'title':
18
+ return faker_1.faker.person.prefix();
19
+ case 'email':
20
+ return faker_1.faker.internet.email();
21
+ case 'phone':
22
+ return faker_1.faker.phone.number();
23
+ case 'address':
24
+ return faker_1.faker.location.streetAddress();
25
+ case 'secondaryAddress':
26
+ return faker_1.faker.location.secondaryAddress();
27
+ case 'city':
28
+ return faker_1.faker.location.city();
29
+ case 'country':
30
+ return faker_1.faker.location.country();
31
+ case 'zipCode':
32
+ return faker_1.faker.location.zipCode();
33
+ case 'company':
34
+ return faker_1.faker.company.name();
35
+ case 'jobTitle':
36
+ return faker_1.faker.person.jobTitle();
37
+ case 'number':
38
+ return faker_1.faker.number.int({ min: min || 1, max: max || 1000 });
39
+ case 'date':
40
+ return faker_1.faker.date.recent().toISOString();
41
+ case 'boolean':
42
+ return faker_1.faker.datatype.boolean();
43
+ case 'url':
44
+ return faker_1.faker.internet.url();
45
+ case 'ip':
46
+ return faker_1.faker.internet.ip();
47
+ case 'username':
48
+ return faker_1.faker.internet.username();
49
+ case 'password':
50
+ return faker_1.faker.internet.password();
51
+ case 'iban':
52
+ return faker_1.faker.finance.iban();
53
+ case 'bic':
54
+ return faker_1.faker.finance.bic();
55
+ case 'bankName':
56
+ return faker_1.faker.company.name() + ' Bank';
57
+ default:
58
+ return faker_1.faker.lorem.word();
59
+ }
60
+ }
61
+ async function generateCSV(options) {
62
+ const { columns, rows, output } = options;
63
+ const csvWriter = (0, csv_writer_1.createObjectCsvWriter)({
64
+ path: output,
65
+ header: columns.map((col) => ({
66
+ id: col.header,
67
+ title: col.header,
68
+ })),
69
+ });
70
+ const records = [];
71
+ for (let i = 0; i < rows; i++) {
72
+ const record = {};
73
+ for (const column of columns) {
74
+ record[column.header] = generateValue(column.type, column.min, column.max);
75
+ }
76
+ records.push(record);
77
+ }
78
+ await csvWriter.writeRecords(records);
79
+ console.log(`✓ Generated ${rows} rows in ${output}`);
80
+ }
81
+ function parseColumnString(columnStr) {
82
+ const parts = columnStr.split(':');
83
+ if (parts.length < 2) {
84
+ throw new Error(`Invalid column format: ${columnStr}. Expected format: header:type`);
85
+ }
86
+ const [header, typeStr] = parts;
87
+ const type = typeStr;
88
+ const validTypes = [
89
+ 'uuid', 'name', 'firstName', 'lastName', 'title', 'email', 'phone',
90
+ 'address', 'secondaryAddress', 'city', 'country', 'zipCode', 'company', 'jobTitle',
91
+ 'number', 'date', 'boolean', 'url', 'ip', 'username', 'password',
92
+ 'iban', 'bic', 'bankName'
93
+ ];
94
+ if (!validTypes.includes(type)) {
95
+ throw new Error(`Invalid data type: ${type}. Valid types: ${validTypes.join(', ')}`);
96
+ }
97
+ return { header, type };
98
+ }
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
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.)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "csv-faker": "dist/cli.js"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/manojkken/csv-faker-generator.git"
13
+ },
14
+ "homepage": "https://github.com/manojkken/csv-faker-generator#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/manojkken/csv-faker-generator/issues"
17
+ },
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "prepare": "npm run build",
21
+ "test": "node dist/example.js"
22
+ },
23
+ "keywords": [
24
+ "csv",
25
+ "faker",
26
+ "fake-data",
27
+ "generator",
28
+ "uuid",
29
+ "csv-generator",
30
+ "mock-data"
31
+ ],
32
+ "author": "Manoj Kengudelu",
33
+ "license": "MIT",
34
+ "files": [
35
+ "dist",
36
+ "README.md"
37
+ ],
38
+ "dependencies": {
39
+ "@faker-js/faker": "^10.1.0",
40
+ "csv-writer": "^1.6.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^24.10.1",
44
+ "typescript": "^5.9.3"
45
+ }
46
+ }