RxJS 5 operator to load CSV file
Work in both JavaScript and TypeScript
npm install rx-from-csv
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
noHeaderRow
is true.
- delimiter: a character to separate values. Default:
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' }
*/
MIT