Socket
Book a DemoInstallSign in
Socket

file-to-objects

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-to-objects

Parse a propery delimited file, line-by-line, and return a Javascript array with object representations

1.0.4
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

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:
// Bubbles,Persian,24,honey-brown
// Garfield,Tabby,33,orange with stripes
const fileToObjects = require('file-line-parse');
const input = './data/CATS_DATA.csv';
const keys = [ 'name', 'breed', 'age', 'color'];
fileToObjects(input, { keys: keys })
    .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>

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"

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

License

MIT

Keywords

file

FAQs

Package last updated on 27 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.