1.0.0 • Published 8 years ago
rx-from-csv v1.0.0
rx-from-csv
RxJS 5 operator to load CSV file
Work in both JavaScript and TypeScript
Installation
npm install rx-from-csvUse
This library exposes a static fromCSV operator:
fromCSV(path: string, options?: object): Observable<T>;The new fromCSV operator will load the CSV file from the give path and emit each row as an object, whose keys are column names and values are column values.
Parameters:
- path: csv file path
- options: optional configuration for the csv creation
- delimiter: a character to separate values. Default:
, - noHeaderRow: a boolean value to indicate whether there is a head row.
- columns: an array of column names. This is required if
noHeaderRowis true.
- delimiter: a character to separate values. Default:
Example
import { fromCSV } from 'rx-from-csv';
/**
* For example, there is a data.csv with content
*
* id,name
* 1,"Mike",
* 2,"Tommy"
*/
fromCSV('data.csv')
.subscribe((data) => {
console.log(data);
});
/**
* It will output:
* { id: '1', name: 'Mike' }
* { id: '1', name: 'Tommy' }
*/License
MIT
