Parse a property delimited file, line-by-line, and return the line in a JavaScript array in object representation.
fileToObjects(📄) => [ {}, {}, {} ]
$ npm install --save file-to-objects
OR $ yarn add file-to-objects
// CATS_DATA.csv:
// name,breed,age,color
// Bubbles,Persian,24,honey-brown
// Garfield,Tabby,33,orange with stripes
const fileToObjects = require('file-to-objects');
const input = './data/CATS_DATA.csv';
fileToObjects(input)
.then(cats => {
console.log(cats[0])
// { name: 'Bubbles', breed: 'Persian', age: '24', color: 'honey-brown' }
console.log(cats[1])
// { name: 'Garfield', breed: 'Tabby', age: '33', color: 'orange with stripes' }
});
Return a set
of parsed objects dictacted by sequence of keys
input | <string>
Path to file to be input.
options | <object>
options.keys | <array>[<string> | <int>]
An array of keys to serve as a mapping for objects, this will override any column header to serve as a mapping for object creation.
options.delimiter | <string>
The delimiter to used for parsing. Default: ","
options.encoding | <string>
The encoding for reading the file. Default: "utf8"
🔄 objects-to-file - Create a delimited value, output file from an array of objects.
MIT