https://github.com/brh55/file-to-objects
:page_facing_up: Parse a field delimited file, line-by-line, and return a JavaScript array containing parsed objects
https://github.com/brh55/file-to-objects
delimited-files parser
Last synced: about 1 month ago
JSON representation
:page_facing_up: Parse a field delimited file, line-by-line, and return a JavaScript array containing parsed objects
- Host: GitHub
- URL: https://github.com/brh55/file-to-objects
- Owner: brh55
- License: mit
- Created: 2017-01-19T18:38:39.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-27T05:34:19.000Z (over 9 years ago)
- Last Synced: 2025-06-28T22:50:17.182Z (12 months ago)
- Topics: delimited-files, parser
- Language: JavaScript
- Homepage:
- Size: 72.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# file-to-objects [](https://travis-ci.org/brh55/file-to-objects) [](https://github.com/sindresorhus/xo)
> 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
```javascript
// 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 | [``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
Path to file to be input.
#### options | [``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Normal_objects_and_functions)
##### options.keys | [`[ | ]`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Indexed_collections_Arrays_and_typed_Arrays)
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 | [``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
The delimiter to used for parsing. `Default: ","`
##### options.encoding | [``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
The encoding for reading the file. `Default: "utf8"`
## Related
:arrows_counterclockwise: [objects-to-file](https://github.com/brh55/objects-to-file) - Create a delimited value, output file from an array of objects.
## License
MIT