Last active
March 9, 2021 03:10
-
-
Save eaton/4baae2733e00e3b4956bf0b8f27245ae to your computer and use it in GitHub Desktop.
11ty CSVtoJSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// full API options at https://github.com/Keyang/node-csvtojson | |
const csv = require('csvtojson'); | |
// Commonly-tweaked defaults | |
const options = { | |
delimiter: ",", | |
trim: true, | |
ignoreEmpty: false, | |
flatKeys: false, | |
checkColumn: false, | |
noheader: false, | |
headers: [] | |
}; | |
// Add CSV to list of data file types | |
module.exports.eleventyConfig.addDataExtension('csv', contents => csv(options) | |
.fromString(contents) | |
.then(result => { return result }) | |
); | |
// Pull in file data | |
const jsonArray = await csv(options).fromFile(myCSVFilePath); | |
// Pull in remote data | |
const request=require('request') | |
const jsonArray = await csv().fromStream(request.get('http://mywebsite.com/mycsvfile.csv')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment