Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rxtoolkit/csv
🚰 RxJS operators for handling CSV data streams
https://github.com/rxtoolkit/csv
csv csv-parser csv-reader csv-writer data-science fp functional-programming observables package reactive-programming rxjs
Last synced: 11 days ago
JSON representation
🚰 RxJS operators for handling CSV data streams
- Host: GitHub
- URL: https://github.com/rxtoolkit/csv
- Owner: rxtoolkit
- License: mit
- Created: 2021-03-18T02:59:28.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-16T18:39:38.000Z (11 months ago)
- Last Synced: 2024-12-10T00:42:11.492Z (about 1 month ago)
- Topics: csv, csv-parser, csv-reader, csv-writer, data-science, fp, functional-programming, observables, package, reactive-programming, rxjs
- Language: JavaScript
- Homepage:
- Size: 598 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @rxtk/csv
> 🚰 RxJS operators for handling CSV data streams> ☠️ Warning: Be careful about upgrading the version of csv-parse used in this package. csv-parse does not use proper semantic versioning. For example upgrading it from 4.15 to 4.16 introduces breaking changes that will cause code that previously parsed CSV properly to no longer do so. Any such updates may require a major version change to this package.
```bash
npm i @rxtk/csv
``````bash
yarn add @rxtk/csv
```## API
### `toCSV`
```js
import {from} from 'rxjs';
import {toCSV} from '@rxtk/csv';const pirate$ = from([
{name: 'Blackbeard', systolicBp: 140, diastolicBp: 91, message: 'Yarr'},
{name: 'Crunch', systolicBp: 120, diastolicBp: 80, message: 'Arr'},
{name: 'Blackbeard', systolicBp: 110, diastolicBp: 70, message: 'Savvy'},
]);const csvRow$ = pirate$.pipe(toCSV(options));
csvRow$.subscribe(console.log);
// "name","systolicBp","dialostilicBp","message"
// "Blackbeard",140,91,"Yarr"
// "Crunch",120,180,"Arr"
// "Sparrow",110,70,"Savvy"
```### `parseCSV`
Given a stream of CSV data, parse it into rows/data:
```js
import { from } from 'rxjs';
import { map } from 'rxjs/operators';
import { parseCSV } from '@rxtk/csv';// Create a stream of raw CSV data
const csvString$ = from([
'"name","systolicBp","dialostilicBp","message"\n',
'"Blackbeard",140,91,"Yarr"\n"Crunch",120,',
',180,"Arr"\n"Sparrow",110,70,"Savvy"\n',
]);// Stream the CSV data into an RxJS Subject
const row$ = csvString$.pipe(parseCSV());
row$.subscribe(console.log);
// {name: "Blackbeard", systolicBp: 140, diastolicBp: 91, message: 'Yarr'},
// {name: "Crunch", systolicBp: 120, diastolicBp: 80, message: 'Arr'},
// {name: "Sparrow", systolicBp: 110, diastolicBp: 70, message: 'Savvy'},
```