Created
October 7, 2021 19:19
-
-
Save pronitdas/77314e6a89628f424c8b0397401b0cb9 to your computer and use it in GitHub Desktop.
remove duplicates vcf
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
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