simple-csv-parser
for javascript / typescript.
marshal/serialize csv string to Object.
No need other dependency. super simple usage.
class Message {
name: string;
message: string;
constructor(name: string, message: string) {
this.name = name;
this.message = message;
}
}
const messages: Message[] = CsvParser.toObject<Message>(
`name,message\r\nnolleh,"hello, world"`
);
// do something with messages...
const messages = CsvParser.toObject<Message>(
`name,message\r\nnolleh,"hello, world"\nnolleh,hello2`
);
console.log({ messages });
result is
{
messages: [
{ name: 'nolleh', message: 'hello, world' },
{ name: 'nolleh', message: 'hello2' }
]
}
if input string is malformed csv, then it return empty array.