csv-append
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

csv-append

Low memory overhead, append-only csv writer.

Abstraction over csv-write-stream.

Install

  yarn add csv-append

Usage

Create a new file

import csvAppend from "csv-append";
const RELATIVE_PATH_TO_CSV = `./data/output.csv`;
const { append, end } = csvAppend(RELATIVE_PATH_TO_CSV);
 
append([{ a: 1, b: 2 }, { a: 2, b: 3 }]);
// Or
append({ a: 1, b: 2 });
append({ a: 2, b: 3 });
 
await end();
console.log(fs.readFileSync(RELATIVE_PATH_TO_CSV, { encoding: "utf8" }));
/* 
a,b
1,2
b,3
*/

Append to file

import csvAppend from "csv-append";
const RELATIVE_PATH_TO_CSV = `./data/output.csv`;
const { append, end } = csvAppend(RELATIVE_PATH_TO_CSV, true);
 
// append([{ a: 1, b: 2 }, { a: 2, b: 3 }]);
// Or
append({ a: 1, b: 2 });
append({ a: 2, b: 3 });
 
await end();
console.log(fs.readFileSync(RELATIVE_PATH_TO_CSV, { encoding: "utf8" }));
/* 
a,b
1,2
b,3
*/

API

csvAppend

Input :

  • path: string (required)
  • appendToFile: boolean (optional, default false)

Output :

{
  appendappend (👇),
  endend (👇)
}

append

append adds an object or an array of objects to the end of the csv file.

Input :

  • args: Array<any> | Array<Array<any>>

Output :

void

end

end returns a promise that resolves when the csv has been written to the fs.

Input :

None

Output :

Promise<void>

Readme

Keywords

none

Package Sidebar

Install

npm i csv-append

Weekly Downloads

125

Version

1.0.0

License

MIT

Unpacked Size

6.99 kB

Total Files

7

Last publish

Collaborators

  • rakannimer