0

I am trying to convert arrays of objects to csv and write to a file or append if the file already exists. I found a package called "object-to-csv" but it requires Node 8 or higher while I'm on 7.8. It's not an option to upgrade, what alternative method is there for this?

1 Answer 1

1

You could replicate the functionality they've added in their implementation, it's a single file (index.js) of around 141 lines of code, not hard work to lift the implementation and make it work with node 7.

https://github.com/anton-bot/objects-to-csv/blob/master/index.js

Alternatively, you're looking to flatten an object (removing properties) keeping the values as an array, then export the array as a CSV file (using FS, or fs-extra).

Feel free to reach out if I can help further.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried to that, converted it all to work with TypeScript as well but the package "async-csv" also requires Node 8. It's only called on line 138 in index.js, then should I also replicate some code from "async-csv.stringify" as well?
It sounds like you could be headed for a rabbit hole, what about this instead: github.com/miscavage/object-to-csv/blob/master/lib/… a dependency-less package, you'll need to remove the .map() syntax, replace it with something from Underscore.js (underscorejs.org) or Lodash (lodash.com), although it's a bit more effort on your part, the end-result with be compatible with your requirements. To be extra polite, you could even submit your version as a PR and see if they'd consider supporting older versions (they may not, but who knows).
Thanks for the help! I'll try this out on Monday.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.