🔍
Validate and Infer Type
Define what you expect with a schema and never run into a surprise.
Type-safe CSV and Google Sheets Parser
For TypeScript and JavaScript
npm i sheethuahua
ID | Name | Email Address | Phone Number |
---|---|---|---|
1 | Samoyed | samo123@doggo | 0800000000 |
2 | Shiba | shibainu@doggo |
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()),
}),
});
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 output = await Spreadsheet('google-sheets-id').get('Sheet1', schema);
console.log(output);
[
{
"id": 1,
"name": "Samoyed",
"contact": { "email": "samo123@doggo", "phone": "0800000000" }
},
{
"id": 2,
"name": "Shiba",
"contact": { "email": "shibainu@doggo" }
}
]
import { formatToCsv } from 'sheethuahua';
const csvString = formatToCsv(output, schema);
console.log(csvString);
ID,Name,Email Address,Phone Number
1,Samoyed,samo123@doggo,0800000000
2,Shiba,shibainu@doggo,