Skip to content

Sheethuahua

Type-safe CSV and Google Sheets Parser

For TypeScript and JavaScript


1. Adopt our little doggo

bash
npm i sheethuaha

2. Map CSV and JS data structure

ts
import { Column, Object, asNumber, asString } from 'sheethuahua';

const schema = Object({
	id: Column('ID', asNumber()),
	name: Column('Name', asString()),
	contact: Object({
		email: Column('Email Address', asString()),
		phone: Column('Phone Number', asString().optional()),
	}),
});

3. And confidently parse it

ts
import { parseCsv, fetchCsv, Spreadsheet } from 'sheethuahua';

// const output: {
//     id: number;
//     name: string;
//     contact: {
//         email: string;
//         phone?: string | undefined;
//     };
// }[]
const output = parseCsv('some,csv,string', schema);

// or from URL
const output = await fetchCsv('https://url-to-csv', schema);

// or from Google Sheets
const sheets = Spreadsheet('google-sheets-id');
const output = await sheets.get('Sheet1', schema);

4. In case you need to format the data back

ts
import { formatToCsv } from 'sheethuahua';

const csvString = formatToCsv(output, schema);

Released under the MIT License.