Skip to content

Wrap string values with new lines in quotes #110

@okmanideep

Description

@okmanideep

Reproduction code

import { createObjectCsvWriter } from 'csv-writer';

const csvPath = 'test.csv'
const csvWriter = createObjectCsvWriter({
path: csvPath,
header: [
	{ id: 'phone_number', title: 'phone_number' },
	{ id: 'name', title: 'name' },
	{ id: 'email', title: 'email' },
],
});
let data = [{ phone_number: 9978789799, name: "John Doe \r", email: "johndoe@email.com" }, {phone_number: 8898988989, name: "Bob Marlin", email: "bormarlin@email.com"}]
await csvWriter.writeRecords(data);

The resultant output is not a valid CSV. Checked with CSV Validator Tool

The output

phone_number,name,email
9978789799,John Doe 
,johndoe@email.com
8898988989,Bob Marlin,bormarlin@email.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions