@appvise/format-csv
v1.0.1
Published
Simple CSV encoder/decoder
Downloads
3
Readme
@appvise/format-csv
Simple CSV encoder/decoder
Usage
import { encode, decode } from '@appvise/format-csv';
// {subject:"world",greeting:"hello"}
const data = decode(`
subject,greeting
world,hello
`);
const recoded = encode(data);
console.log({
data,
recoded,
});
// {
// data: [ { subject: 'world', greeting: 'hello' } ],
// recoded: '"subject","greeting"\n"world","hello"'
// }
API Reference
encode(data: CsvData, opts: CsvEncodeOptions = {}): string
decode(str: string, opts: CsvDecodeOptions = {}): CsvData
type CsvData = ({[index:string]:string|number|boolean}|[string|number|boolean])[]
type CsvEncodeOptions = { delimiter?: string, wrapString?: string, }
type CsvDecodeOptions = { delimiter? : string, wrapString? : string, parseNumbers? : boolean, parseHeaders? : boolean, parseBooleans?: boolean, headers? : string[], }