Created
August 7, 2020 06:04
-
-
Save fadeenk/9a87afd7718ba9e0af730700b115ca8c to your computer and use it in GitHub Desktop.
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 csvFilePath='./password.csv' | |
const csv = require('csvtojson'); | |
const fs = require('fs'); | |
function getUrl(record) { | |
if (record.URL !== '') return record.URL; | |
if (record.url !== '') return record.url; | |
return record['URL:']; | |
} | |
const additonalFields = ['previous', 'old', 'email', 'Backup', 'Service Tag', 'Login', 'Note', 'EmployeeID', 'account ID', 'URLK', 'Game', 'service'] | |
function getFields(record) { | |
let fieldsString = ''; | |
additonalFields.forEach((field) => { | |
if (record[field] && record[field] !== '') { | |
fieldsString += field + ': ' + record[field] + '\n'; | |
} | |
}); | |
return fieldsString.trim(); | |
} | |
function escapeCSVString(str) { | |
return `"${str.replace(/"/g, '""')}"` | |
} | |
function bCupToWarden(record) { | |
return { | |
folder: record['!group_id'], | |
favorite: '', | |
type: 'login', | |
name: record.title, | |
notes: '', | |
fields: escapeCSVString(getFields(record)), | |
login_uri: getUrl(record), | |
login_username: record.username, | |
login_password: escapeCSVString(record.password), | |
login_totp: '', | |
} | |
} | |
csv() | |
.fromFile(csvFilePath) | |
.then((result)=>{ | |
let csv = 'folder,' + | |
'favorite,' + | |
'type,' + | |
'name,' + | |
'notes,' + | |
'fields,' + | |
'login_uri,' + | |
'login_username,' + | |
'login_password,' + | |
'login_totp\n'; | |
result.map(bCupToWarden).forEach((record) => { | |
csv += record.folder+ ',' + | |
record.favorite+ ',' + | |
record.type+ ',' + | |
record.name+ ',' + | |
record.notes+ ',' + | |
record.fields+ ',' + | |
record.login_uri+ ',' + | |
record.login_username+ ',' + | |
record.login_password+ ',' + | |
record.login_totp+ '\n'; | |
}); | |
fs.writeFileSync('./bitWardenPasswords.csv', csv); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment