csv-faker-generator 2.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 +21 -0
- package/README.md +5 -0
- package/dist/index.js +2 -2
- package/package.json +8 -5
- package/dist/example.d.ts +0 -1
- package/dist/example.js +0 -55
- package/dist/test-advanced.d.ts +0 -1
- package/dist/test-advanced.js +0 -110
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,5 +1,10 @@
|
|
|
1
1
|
# CSV Faker Generator
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/csv-faker-generator)
|
|
4
|
+
[](https://www.npmjs.com/package/csv-faker-generator)
|
|
5
|
+
[](https://github.com/manojkken/csv-faker-generator/actions/workflows/ci.yml)
|
|
6
|
+
[](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
|
package/dist/index.js
CHANGED
|
@@ -36,9 +36,9 @@ function generateValue(column, row) {
|
|
|
36
36
|
case 'jobTitle':
|
|
37
37
|
return faker_1.faker.person.jobTitle();
|
|
38
38
|
case 'number': {
|
|
39
|
-
const num = faker_1.faker.number.int({ min: min
|
|
39
|
+
const num = faker_1.faker.number.int({ min: min ?? 1, max: max ?? 1000 });
|
|
40
40
|
if (decimals !== undefined) {
|
|
41
|
-
const float = faker_1.faker.number.float({ min: min
|
|
41
|
+
const float = faker_1.faker.number.float({ min: min ?? 1, max: max ?? 1000, fractionDigits: decimals });
|
|
42
42
|
return parseFloat(float.toFixed(decimals));
|
|
43
43
|
}
|
|
44
44
|
return num;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "csv-faker-generator",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
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",
|
|
@@ -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
|
|
21
|
+
"test": "npm run build && node --test test/index.test.js"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
24
24
|
"csv",
|
|
@@ -43,7 +43,10 @@
|
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"files": [
|
|
45
45
|
"dist",
|
|
46
|
-
"
|
|
46
|
+
"!dist/example.*",
|
|
47
|
+
"!dist/test-advanced.*",
|
|
48
|
+
"README.md",
|
|
49
|
+
"LICENSE"
|
|
47
50
|
],
|
|
48
51
|
"dependencies": {
|
|
49
52
|
"@faker-js/faker": "^10.1.0",
|
|
@@ -53,4 +56,4 @@
|
|
|
53
56
|
"@types/node": "^24.10.1",
|
|
54
57
|
"typescript": "^5.9.3"
|
|
55
58
|
}
|
|
56
|
-
}
|
|
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
|
-
});
|
package/dist/test-advanced.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test-advanced.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("./index");
|
|
4
|
-
async function testAdvancedFeatures() {
|
|
5
|
-
console.log('Testing Advanced Features...\n');
|
|
6
|
-
// Test 1: Alphanumeric with length and uppercase
|
|
7
|
-
console.log('Test 1: Alphanumeric type with custom length and uppercase...');
|
|
8
|
-
await (0, index_1.generateCSV)({
|
|
9
|
-
columns: [
|
|
10
|
-
{ header: 'product_code', type: 'alphanumeric', length: 10, uppercase: true },
|
|
11
|
-
{ header: 'sku', type: 'alphanumeric', length: 15 },
|
|
12
|
-
{ header: 'name', type: 'name' },
|
|
13
|
-
],
|
|
14
|
-
rows: 5,
|
|
15
|
-
output: 'test-alphanumeric.csv',
|
|
16
|
-
});
|
|
17
|
-
// Test 2: Pick type for enum values
|
|
18
|
-
console.log('\nTest 2: Pick type for predefined values...');
|
|
19
|
-
await (0, index_1.generateCSV)({
|
|
20
|
-
columns: [
|
|
21
|
-
{ header: 'product', type: 'name' },
|
|
22
|
-
{ header: 'tax_rate', type: 'pick', values: [0, 7, 19] },
|
|
23
|
-
{ header: 'status', type: 'pick', values: ['active', 'pending', 'inactive'] },
|
|
24
|
-
{ header: 'unit', type: 'pick', values: ['g', 'kg', 'Stück', 'Meter'] },
|
|
25
|
-
],
|
|
26
|
-
rows: 5,
|
|
27
|
-
output: 'test-pick.csv',
|
|
28
|
-
});
|
|
29
|
-
// Test 3: Formula fields (calculated values)
|
|
30
|
-
console.log('\nTest 3: Formula type for calculated fields...');
|
|
31
|
-
await (0, index_1.generateCSV)({
|
|
32
|
-
columns: [
|
|
33
|
-
{ header: 'product', type: 'company' },
|
|
34
|
-
{ header: 'netto', type: 'number', min: 10, max: 200, decimals: 2 },
|
|
35
|
-
{ header: 'tax', type: 'pick', values: [0, 7, 19] },
|
|
36
|
-
{
|
|
37
|
-
header: 'brutto',
|
|
38
|
-
type: 'formula',
|
|
39
|
-
formula: (row) => {
|
|
40
|
-
const netto = row.netto;
|
|
41
|
-
const tax = row.tax;
|
|
42
|
-
return parseFloat((netto * (1 + tax / 100)).toFixed(2));
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
rows: 5,
|
|
47
|
-
output: 'test-formula.csv',
|
|
48
|
-
});
|
|
49
|
-
// Test 4: Custom delimiter (semicolon)
|
|
50
|
-
console.log('\nTest 4: Custom delimiter (semicolon)...');
|
|
51
|
-
await (0, index_1.generateCSV)({
|
|
52
|
-
columns: [
|
|
53
|
-
{ header: 'id', type: 'uuid' },
|
|
54
|
-
{ header: 'name', type: 'name' },
|
|
55
|
-
{ header: 'email', type: 'email' },
|
|
56
|
-
],
|
|
57
|
-
rows: 5,
|
|
58
|
-
delimiter: ';',
|
|
59
|
-
output: 'test-semicolon.csv',
|
|
60
|
-
});
|
|
61
|
-
// Test 5: Number with decimal precision
|
|
62
|
-
console.log('\nTest 5: Number type with decimal precision...');
|
|
63
|
-
await (0, index_1.generateCSV)({
|
|
64
|
-
columns: [
|
|
65
|
-
{ header: 'price', type: 'number', min: 10, max: 200, decimals: 2 },
|
|
66
|
-
{ header: 'weight', type: 'number', min: 0.1, max: 99.9, decimals: 1 },
|
|
67
|
-
{ header: 'quantity', type: 'number', min: 1, max: 1000, decimals: 0 },
|
|
68
|
-
],
|
|
69
|
-
rows: 5,
|
|
70
|
-
output: 'test-decimals.csv',
|
|
71
|
-
});
|
|
72
|
-
// Test 6: Complete E-commerce Article Example
|
|
73
|
-
console.log('\nTest 6: Complete e-commerce article example (the dogfooding use case)...');
|
|
74
|
-
await (0, index_1.generateCSV)({
|
|
75
|
-
columns: [
|
|
76
|
-
{ header: 'Artikelnummer*', type: 'alphanumeric', length: 15 },
|
|
77
|
-
{ header: 'Bezeichnung*', type: 'company' },
|
|
78
|
-
{ header: 'Beschreibung', type: 'company' },
|
|
79
|
-
{ header: 'Verkaufspreis netto in €', type: 'number', min: 10, max: 200, decimals: 2 },
|
|
80
|
-
{ header: 'Steuersatz', type: 'pick', values: [0, 7, 19] },
|
|
81
|
-
{
|
|
82
|
-
header: 'Verkaufspreis brutto in €',
|
|
83
|
-
type: 'formula',
|
|
84
|
-
formula: (row) => {
|
|
85
|
-
const netto = row['Verkaufspreis netto in €'];
|
|
86
|
-
const tax = row['Steuersatz'];
|
|
87
|
-
return parseFloat((netto * (1 + tax / 100)).toFixed(2));
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
{ header: 'Einkaufspreis netto in €', type: 'number', min: 5, max: 100, decimals: 2 },
|
|
91
|
-
{ header: 'Einheit', type: 'pick', values: ['Stück', 'kg', 'g', 'Meter', 'Liter'] },
|
|
92
|
-
{ header: 'Bestand', type: 'number', min: 0, max: 1000, decimals: 0 },
|
|
93
|
-
{ header: 'Kategorie', type: 'pick', values: ['Electronics', 'Food', 'Clothing', 'Books'] },
|
|
94
|
-
],
|
|
95
|
-
rows: 10,
|
|
96
|
-
output: 'test-articles-complete.csv',
|
|
97
|
-
});
|
|
98
|
-
console.log('\n✓ All advanced feature tests completed successfully!');
|
|
99
|
-
console.log('\nGenerated files:');
|
|
100
|
-
console.log(' - test-alphanumeric.csv (alphanumeric with length/uppercase)');
|
|
101
|
-
console.log(' - test-pick.csv (pick from predefined values)');
|
|
102
|
-
console.log(' - test-formula.csv (calculated fields)');
|
|
103
|
-
console.log(' - test-semicolon.csv (custom delimiter)');
|
|
104
|
-
console.log(' - test-decimals.csv (decimal precision)');
|
|
105
|
-
console.log(' - test-articles-complete.csv (complete e-commerce example)');
|
|
106
|
-
}
|
|
107
|
-
testAdvancedFeatures().catch((error) => {
|
|
108
|
-
console.error('Error running advanced tests:', error);
|
|
109
|
-
process.exit(1);
|
|
110
|
-
});
|