Created
June 29, 2024 12:17
-
-
Save proteye/92982f318d3bef5884c5af8cc9724691 to your computer and use it in GitHub Desktop.
Fix names of Bitwarden passwords
This file contains hidden or 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 fs = require("fs"); | |
const url = require("url"); | |
function fixBitwardenJson() { | |
const filePath = process.argv[2]; | |
if (!filePath || !fs.existsSync(filePath)) return; | |
let jsonData = null; | |
let count = 0; | |
fs.readFile(filePath, "utf8", function (err, data) { | |
if (err) throw err; | |
jsonData = JSON.parse(data); | |
for (let i = 0; i < jsonData.items.length; i++) { | |
const item = jsonData.items[i]; | |
if (!item.name || item.name === "--") { | |
const uri = item.login.uris.length > 0 ? item.login.uris[0].uri : null; | |
if (uri) { | |
const uriArr = url.parse(uri).hostname.replace("www.", "").split("."); | |
uriArr.pop(); | |
item.name = uriArr.join("."); | |
count += 1; | |
} | |
} | |
} | |
fs.writeFile( | |
"bitwarden_fixed.json", | |
JSON.stringify(jsonData), | |
"utf8", | |
() => { | |
console.log("count of renames:", count); | |
} | |
); | |
}); | |
} | |
fixBitwardenJson(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment