0.1.6 • Published 7 years ago

rx-to-csv v0.1.6

Weekly downloads
8
License
MIT
Repository
github
Last release
7 years ago

rx-to-csv

build status

ReactiveX

RxJS 5 operator to write data into a CSV 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<string>, 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:

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:

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

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago