Skip to content

Commit

Permalink
Add bin to debug personnummer
Browse files Browse the repository at this point in the history
  • Loading branch information
frozzare committed Mar 23, 2023
1 parent ecd98e5 commit be117b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions bin/personnummer
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env node

const fs = require("fs");
const Personnummer = fs.existsSync(`${__dirname}/../dist/cjs/index.js`)
? require(`${__dirname}/../dist/cjs/index.js`)
: require(`${__dirname}/../src/index.ts`);

const main = () => {
const argv = process.argv.slice(2);
if (argv.length < 1) {
console.log("Usage: npx personnummer <personnummer>");
return;
}

try {
const pnr = Personnummer.parse(argv[0]);
console.log(` Short format: ${pnr.format()}
Long format: ${pnr.format(true)}
Age: ${pnr.getAge()}
Sex: ${pnr.isMale() ? "male" : "female"}
Coordination number: ${pnr.isCoordinationNumber()}
Interim number: ${pnr.isInterimNumber()}`);
} catch (err) {
console.log(err);
console.log("Invalid personal identity number provided");
}
};

main();
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"type": "git",
"url": "git://github.com/personnummer/js.git"
},
"bin": {
"personnummer": "bin/personnummer"
},
"files": [
"dist/**/*"
],
Expand Down

0 comments on commit be117b1

Please # to comment.