Skip to content

Instantly share code, notes, and snippets.

@jsejcksn
Last active May 14, 2019 06:22
Show Gist options
  • Save jsejcksn/2ef093ebe25a75fbadf416acf56ee977 to your computer and use it in GitHub Desktop.
Save jsejcksn/2ef093ebe25a75fbadf416acf56ee977 to your computer and use it in GitHub Desktop.
1Password 1pif data parser Node.js module
#!/usr/bin/env node
// cli usage: `node 1p-parser.js input.1pif`
'use strict';
const getJSON = require('1pif-to-json');
(async () => {
const items = await getJSON(process.argv.slice(2)[0]);
console.log(`${items.length} items`);
})();
'use strict';
const fs = require('fs');
const readline = require('readline');
async function getJSON (pathTo1pifFile) {
const lines = [];
const rl = readline.createInterface({
input: fs.createReadStream(pathTo1pifFile),
crlfDelay: Infinity
});
for await (const line of rl) {
if (line.startsWith('{')) {
lines.push(JSON.parse(line));
}
}
return lines;
}
module.exports = getJSON;
{
"name": "1pif-to-json",
"version": "1.0.0",
"description": "",
"engines": {
"node": ">=12.0.0"
},
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jesse Jackson <npm@jcksn.org> (https://jcksn.org)",
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment