Create a delimited value, output file from an array of objects
objectsToFile([{}, {}, {}]) => 📄
Install
$ npm install --save objects-to-file
OR $ yarn add objects-to-file
Usage
Basic
const fs = ;const objectsToFile = ; const cats = name: 'Bubbles' breed: 'Persian' age: '24' color: 'honey-brown' name: 'Garfield' breed: 'Tabby' age: '33' color: 'orange with stripes' ;
Advance
const fs = ;const objectsToFile = ; const dogData = './data/dogs/german_sheperd' './data/dogs/pug' './data/dogs/beagle'; let dogOutput = dogsPaths
API
objectsToFile(data, outputPath[, options])
Creates a file based on an array of objects. Unless specified, it will use the first object as a mapping for subsequent objects.
Returns a {Promise}, when resolved returns the file location path
<array>
data | The input array of objects.
<string>
outputPath | The output file location
<object>
options | <array>[<string> | <int>]
options.keys | A list of keys to map and dictate the order of the value output. Any non-existent fields will be omitted.
<bool>
options.header | Set true
to print the key on the first chunk of the file. Note: this will not work with options.raw = true
<int>
options.count | Number of desired objects to be written.
<object>
options.bar | Assign a progress bar instance to be bar.tick()
per each chunk written.
<string>
options.delimiter | The delimiter to be used to seperate values. Default: ","
<string>
options.EOL | The End of Line character to be used. Default: "\n"
<string>
options.encoding | The encoding to be used for the output file. Default: "utf8"
<bool>
options.raw | Set true
to print all the values within the objects, ignoring keys or first object key mapping.
<string>
options.encoding | The encoding to be used for the output file. Default: "utf8"
Related
🔁 file-line-parse - Parse a file, line by line, to an array of objects.
License
MIT