padloc To Keepaas
`app.js`
```js
const fs =require('fs')
const {getRecords} = require('./helpers')
const filename= 'My_Vault_2024-05-13.csv'
// const filename= 'test.csv'
const outputDataFile = "output.xml"
let outputData=""
outputData+=`
Root
48
True
null
null
padloc
containing prev padloc database
48
True
null
null
`
const records = getRecords(filename)
// function to map names of keys to match that of keepaas ones
const mapObjects=(obj)=>{
const newObj={}
for(let key of Object.keys(obj)){
if(obj[key].length===0){
continue;
}
// console.log('key to be mapped: ',key, ' value: ', obj[key])
switch(key){
case 'name': newObj['Title']=obj['name']; break;
case 'tags' : newObj['Tags']= obj['tags']; break;
case 'Username' : newObj['UserName'] = obj['Username']; break;
case 'Email Address' : newObj['Email'] = obj[key]; break;
case 'Plain Text' : newObj['Notes'] = obj[key]; break;
case 'Name' : newObj['UserName'] = obj[key]; break;
default : newObj[key] = obj[key]
}
}
// console.log('newObj: ',newObj)
return newObj;
}
// function to add escape sequqnce for reserved characters in xml
const mapValueForXML=(str)=>{
let newStr= str.replace(/"/g,'')
newStr = newStr.replace(/&/g,'&')
newStr = newStr.replace(//g,'>')
newStr = newStr.replace(/"/g,'"')
newStr = newStr.replace(/'/g,''')
return newStr
}
for(let record of records){
const tags= record.tags.replace(/"/g,'')
let tagsXML=''
if(tags.length===0){
tagsXML=''
}
else{
tagsXML=`${tags}`
}
outputData+=`
0
${tagsXML}
`
const mappedRecord = mapObjects(record)
// console.log('')
for(let key in mappedRecord){
// console.log('')
if(key==='Password'){
outputData+=`
${key}
${ mapValueForXML(mappedRecord[key]) }
`
continue
}
outputData+=`
${key}
${ mapValueForXML(mappedRecord[key]) }
`
}
outputData+=`
True
0
`
}
outputData+=`
`
fs.writeFileSync(outputDataFile,outputData)
```
`helpers.js`
```js
const fs =require('fs')
const getRecords=(filename)=>{
const data =fs.readFileSync(filename,{encoding : 'utf8'})
// normal, quotes
let state="normal"
const lines= data.split('\n')
// console.log('lines: ',lines)
// extracting headings and also removing last character ie \r from the line
let headings= lines[0].slice(0,lines[0].length-1).split(',')
console.log('headings: ',headings)
let valuei=0
let str=``
const parseLine=(line,obj)=>{
// parsing character by character
for(let i=0;i