New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

lets-make-csvs

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lets-make-csvs

Let's make csv!

latest
npmnpm
Version
0.0.10
Version published
Maintainers
3
Created
Source

lets-make-csvs

Let's make CSV's from row objects

What

I wanted to create an iterative CSV, one row at a time. But I also want ot add properties.

This module will make a CSV one row at a time. It will also modify the CSV header as it goes. Because it uses Node pipes and buffers, it can handle super large files.

Usage

npm install lets-make-csvs

Use a github token, because this module is probably private

example

const async = require('async')
let lmcsv = require("lets-make-csvs")

let csv = new lmcsv("test.csv")


let myobj = [{
  "id": 1,
  "first_name": "Hartley",
  "last_name": "Mulvenna",
  "email": "hmulvenna0@delicious.com",
  "gender": "Male",
  "ip_address": "6.25.240.135",
  "hobbies": ["fishing", "camping", "hiking"]
}, {
  "id": 2,
  "first_name": "Antonio",
  "last_name": "Pigne",
  "email": "apigne1@feedburner.com",
  "gender": "Male",
  "ip_address": "102.234.210.24",
  "hobbies": ["bowling", "music"],
  "farm animals":{
    "pigs":3,
    "cows":{
      "male":2,
      "female":1
    },
    "horses":1
  }
}, {
  "id": 3,
  "first_name": "Gamaliel",
  "last_name": "Graser",
  "email": "ggraser2@nymag.com",
  "SAT score": 1420
}, {
  "id": 4,
  "first_name": "Celestyna",
  "last_name": "Pawels",
  "email": "cpawels3@home.pl",
  "gender": "Female",
  "ip_address": "18.17.253.197",
  "age": 22
}, {
  "id": 5,
  "first_name": "Mommy",
  "last_name": "Caitlin",
  "email": "mcaitlin4@smh.com.au",
  "gender": "Female",
  "ip_address": "213.145.160.242"
}, {
  "id": 6,
  "first_name": "Nettle",
  "last_name": "Mordey",
  "email": "nmordey5@ox.ac.uk",
  "gender": "Female",
  "ip_address": "178.58.2.233",
  "occupation":"Engineer"
}]

async.eachSeries(myobj, function eachRow(row, cb) {
  csv.writeRow(row, function(err) {
    if (err) return cb(err)
    return cb(null)
  })
}, function endEachRow(err) {
  if (err) throw err
  console.log("done")
})

output:

"id","first_name","last_name","email","gender","ip_address","hobbies","activites","crimes","age"
"1","Hartley","Mulvenna","hmulvenna0@delicious.com","Male","6.25.240.135","["fishing","camping","hiking"]
"2","Antonio","Pigne","apigne1@feedburner.com","Male","102.234.210.24"," ","["bowling","crime"]
"3","Gamaliel","Graser","ggraser2@nymag.com","Male","32.18.140.241"," "," ","{"theft":"misdemeanor","treason":"felony","attempted murder":"misdemeanor"}
"4","Celestyna","Pawels","cpawels3@home.pl","Female","18.17.253.197"," "," "," ","22"
"5","Mommy","Caitlin","mcaitlin4@smh.com.au","Female","213.145.160.242"," "," "," "," "
"6","Nettle","Mordey","nmordey5@ox.ac.uk","Female","178.58.2.233"," "," "," "," "

CSV result:

Open the result in your Excel or Google Sheets and you should see something like this:

idfirst_namelast_nameemailgenderip_addresshobbiesfarm animalsSAT scoreageoccupation
1HartleyMulvennahmulvenna0@delicious.comMale6.25.240.135["fishing","camping","hiking"]
2AntonioPigneapigne1@feedburner.comMale102.234.210.24["bowling","music"]{"pigs":3,"cows":{"male":2,"female":1},"horses":1}
3GamalielGraserggraser2@nymag.com1420
4CelestynaPawelscpawels3@home.plFemale18.17.253.19722
5MommyCaitlinmcaitlin4@smh.com.auFemale213.145.160.242
6NettleMordeynmordey5@ox.ac.ukFemale178.58.2.233Engineer

Todo:

  • Array method

FAQs

Package last updated on 15 Feb 2019

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