// Name: Generate CSV with Faker Data // Description: Generate a CSV file with fake data using Faker.js // Author: gunhaxxor import '@johnlindquist/kit' import { faker } from '@faker-js/faker' const numberOfRows = await arg({ placeholder: 'How many rows of data?', hint: 'Enter a number (default: 100)', strict: false, }) const rowCount = parseInt(numberOfRows) || 100 // Generate CSV headers const headers = [ 'id', 'firstName', 'lastName', 'email', 'phone', 'company', 'jobTitle', 'address', 'city', 'state', 'zipCode', 'country', 'birthDate', 'salary', 'department' ] // Generate CSV data const csvData = [] csvData.push(headers.join(',')) for (let i = 1; i <= rowCount; i++) { const row = [ i, `"${faker.person.firstName()}"`, `"${faker.person.lastName()}"`, `"${faker.internet.email()}"`, `"${faker.phone.number()}"`, `"${faker.company.name()}"`, `"${faker.person.jobTitle()}"`, `"${faker.location.streetAddress()}"`, `"${faker.location.city()}"`, `"${faker.location.state()}"`, `"${faker.location.zipCode()}"`, `"${faker.location.country()}"`, `"${faker.date.birthdate().toISOString().split('T')[0]}"`, `"${faker.number.int({ min: 30000, max: 150000 })}"`, `"${faker.commerce.department()}"` ] csvData.push(row.join(',')) } const csvContent = csvData.join('\n') // Save to file const fileName = `fake-data-${formatDate(new Date(), 'yyyy-MM-dd-HHmmss')}.csv` const filePath = home('Downloads', fileName) await writeFile(filePath, csvContent) await revealFile(filePath) await div(md(` # CSV Generated Successfully! 📊 **File:** ${fileName} **Location:** ${filePath} **Rows:** ${rowCount} **Columns:** ${headers.length} The file has been saved to your Downloads folder and revealed in Finder. `))