Skip to content

Instantly share code, notes, and snippets.

@pronitdas
Created October 7, 2021 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pronitdas/77314e6a89628f424c8b0397401b0cb9 to your computer and use it in GitHub Desktop.
Save pronitdas/77314e6a89628f424c8b0397401b0cb9 to your computer and use it in GitHub Desktop.
remove duplicates vcf
const csv = require('csv-parser')
const fs = require('fs')
var vCardJS = require('vcards-js');
let outputStream = fs.createWriteStream('new_contacts.vcf', 'utf8');
let inputStream = fs.createReadStream('new_contacts.csv', 'utf8');
let allContacts = []
inputStream
.pipe(csv())
.on('data', function (row) {
allContacts.push(row)
})
.on('end', function () {
console.log('No more rows!');
const contactWithNumbers = allContacts.filter(c => {
return c['Home Phone'] || c['Business Phone'] || c['Mobile Phone']
})
contactWithNumbers.forEach(c => {
var vCard = vCardJS();
vCard.firstName = c['First Name']
vCard.lastName = c['Last Name']
vCard.homePhone = c['Home Phone']
vCard.businessPhone = c['Business Phone']
vCard.mobilePhone = c['Mobile Phone']
outputStream.write(vCard.getFormattedString())
})
console.log(contactWithNumbers.length)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment