This JavaScript program dynamically generates a CSV file of any specified size. It allows users to define custom headers and data types for each column, producing random data accordingly. The generated CSV can then be downloaded directly to the user's machine.
- Customizable Headers: Define your own headers for the CSV file.
- Dynamic Data Generation: Generate random data for each column based on the specified data type (
string
,number
,boolean
, ornull
). - Scalable: Generate a CSV file with any number of rows.
- CSV Download: Automatically prompts the user to download the generated CSV file.
- A modern web browser that supports JavaScript.
-
Define Headers and Data Types: Customize the headers and data types in the
headers
anddataTypes
arrays respectively.const headers = ['Name', 'Age', 'IsStudent', 'Comment']; const dataTypes = ['string', 'number', 'boolean', 'null'];
headers
: An array of strings representing the column names in the CSV.dataTypes
: An array of strings specifying the data type for each corresponding column in theheaders
array. Possible values:'string'
- Random string data'number'
- Random number data'boolean'
- Random boolean data (true
orfalse
)'null'
- Empty cell in the CSV"Any String"
- Double quoted strings will print exactly whats between them for all rows
-
Set Row Count: Define the number of rows you want in your CSV file by setting the
rowCount
variable.const rowCount = 10;
-
Generate and Download CSV: Call the
generateCSV
function with the definedheaders
,rowCount
, anddataTypes
arrays. ThedownloadCSV
function will trigger the download of the generated CSV file.const csvContent = generateCSV(headers, rowCount, dataTypes); downloadCSV(csvContent);
Here is an example that generates a CSV file with 10 rows, where:
- The first column (
Name
) contains random strings. - The second column (
Age
) contains random numbers. - The third column (
IsStudent
) contains random boolean values. - The fourth column (
Comment
) is left empty.
const headers = ['Name', 'Age', 'IsStudent', 'Comment'];
const dataTypes = ['string', 'number', 'boolean', 'null'];
const rowCount = 10;
const csvContent = generateCSV(headers, rowCount, dataTypes);
downloadCSV(csvContent);
You can use the simple frontend by running npm run build
and opening the index.html
Brian Best