Skip to content

📄 Parse a field delimited file, line-by-line, and return a JavaScript array containing parsed objects

License

Notifications You must be signed in to change notification settings

brh55/file-to-objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

file-to-objects Travis XO code style

Parse a property delimited file, line-by-line, and return the line in a JavaScript array in object representation.

fileToObjects(📄) => [ {}, {}, {} ]

Install

$ npm install --save file-to-objects OR $ yarn add file-to-objects

Usage

// 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' }
    });

API

fileToObjects(input[, options])

Return a set of parsed objects dictacted by sequence of keys

input | <string>

Path to file to be input.

options | <object>

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"

Related

🔄 objects-to-file - Create a delimited value, output file from an array of objects.

License

MIT

About

📄 Parse a field delimited file, line-by-line, and return a JavaScript array containing parsed objects

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published