Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rakannimer/csv-append
Low memory overhead, append-only csv writer abstraction over https://github.com/maxogden/csv-write-stream.
https://github.com/rakannimer/csv-append
Last synced: 15 days ago
JSON representation
Low memory overhead, append-only csv writer abstraction over https://github.com/maxogden/csv-write-stream.
- Host: GitHub
- URL: https://github.com/rakannimer/csv-append
- Owner: rakannimer
- Created: 2018-10-11T10:41:45.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-15T14:27:31.000Z (about 6 years ago)
- Last Synced: 2024-09-22T12:05:05.505Z (about 2 months ago)
- Language: TypeScript
- Size: 147 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## csv-append
Low memory overhead, append-only csv writer.
Abstraction over [csv-write-stream](https://github.com/maxogden/csv-write-stream).
## Install
```sh
yarn add csv-append
```## Usage
### Create a new file
```typescript
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
```typescript
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 :
```typescript
{
append: append (👇),
end: end (👇)
}
```### `append`
`append` adds an object or an array of objects to the end of the csv file.
#### Input :
- args: `Array | Array>`
#### Output :
void
### `end`
`end` returns a promise that resolves when the csv has been written to the fs.
#### Input :
None
#### Output :
`Promise`