https://github.com/haoliangyu/rx-to-csv
RxJS 5 operator to write data into a CSV file
https://github.com/haoliangyu/rx-to-csv
csv operator read rxjs
Last synced: about 1 year ago
JSON representation
RxJS 5 operator to write data into a CSV file
- Host: GitHub
- URL: https://github.com/haoliangyu/rx-to-csv
- Owner: haoliangyu
- License: mit
- Created: 2017-05-14T02:53:41.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-29T03:14:37.000Z (almost 9 years ago)
- Last Synced: 2025-03-30T13:36:54.326Z (about 1 year ago)
- Topics: csv, operator, read, rxjs
- Language: JavaScript
- Size: 61.5 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rx-to-csv

[](http://reactivex.io/)
[RxJS 5](http://reactivex.io/) operator to write data into a [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) file
Work in both JavaScript and TypeScript
## Installation
```
npm install rx-to-csv
```
## Use
Import this library and it will add `toCSV` operator to the rxjs `Observable` class.
```
public toCSV(path: string, columns: Array, options?: any): Observable
```
This operator will search values in its input by column names and write them into the target CSV file via a write file stream.
Parameters:
* **path**: csv file path
* **columns**: an array of column names
* **options**: optional configuration for the csv creation
* **wrapText**: a boolean value indicating whether to wrap text values with `"`. Default: `true`
* **delimiter**: a character to separate values. Default: `,`
## Example
Generate a CSV file from data flow:
``` javascript
import { Observable } from 'rxjs';
import 'rx-to-csv';
let data = [
{ id: 1, name: 'Mike' },
{ id: 2, name: 'Tommy' }
];
Observable.of(...data)
.toCSV('data.csv', ['id', 'name'])
.subscribe();
```
Download data from a PostgreSQL dadtabase and save it as a CSV file:
``` javascript
import pgrx from 'pg-reactive';
import 'rx-to-csv';
let db = new pgrx('connection string');
db.query('SELECT id, display_name FROM users')
.map((row) => {
// convert the data to match column names
return {
id: row.id,
name: row.display_name
};
})
.toCSV('data.csv', ['id', 'name'])
.subscribe();
```
## License
MIT