hermannbjorgvin / kennitala Goto Github PK
View Code? Open in Web Editor NEWIcelandic national ID (kennitölur) utilities for servers and clients.
License: MIT License
Icelandic national ID (kennitölur) utilities for servers and clients.
License: MIT License
Hi it would be awesome if you could typescript support for kennitala
According to skra.is, the twoRandomDigits
should be from 20 to 99:
Næstu tveir tölustafir hafa enga merkingu og er þeim úthlutað í röð frá og með 20
However the numbers generated in kennitala.generatePerson
are:
var twoRandomDigits = "" + Math.floor(Math.random() * 10) + Math.floor(Math.random() * 10)
This rule is also not followed in evaluate
.
Hi, there is a bug/problem here. The package doesn't support the new "gerviþjóðskrá".
https://www.skra.is/um-okkur/frettir/frett/2020/10/13/Ny-utgafa-af-gervigognum-thjodskrar/
Those fake kennitala's have got either 14 or 15 in char 7-8. The package assumes 20 at the lowest.
Veit ekki afhverju en alltaf þegar ég slæ inn 240397 22x
fær ég alltaf isPerson(...)
sem true
.
The isPerson
validation does not account for invalid dates. I see the current code simply checks that the day is <= 31
, but 310222 for instance is not a valid date, and hence not a valid kennitala.
Would have to parse the date and validate it.
One way to do it:
const isValid = isNaN(new Date('2022-02-31').getTime())
Related to #16
The national id 1337991337
passes isValid
and isPerson
checks.
const { isPerson, isValid } = require('kennitala')
const nationalId = '1337991337'
console.log('isValid(nationalId)', isValid(nationalId))
console.log('isPerson(nationalId)', isPerson(nationalId))
Foreigners get an "invalid" nationalId once registered, which this library will mark as invalid.
It might be better to validate the nationalId, but specify the origin as foreign.
So isPerson(<foreign_national_id>)
would return
...
origin: foreign
and isPerson(<native_national_id>)
would return
...
origin: native
What's your thought on this?
(This would require a major release bump)
The last digit is the century, so I would think that future proofing for all upcoming centuries is not correct, that is, I would expect the last digit for a person to only be valid if it is 0 or 9. What do you think about this @HermannBjorgvin ?
In #6 you confirmed that the 7-8th digit should start at 20, and fixed the generator.
But isPerson
returns true for the 7-8th numbers below 20.
For instance 070222-0000
returns true
, but is invalid.
Lenti í því þegar ég var að athuga hvort einhver væri orðinn 18 ára að kóðinn sem skilar aldri getur gefið nýjan aldur degi fyrir afmælisdag. Dæmi:
var kennitala = require("kennitala")
var today = new Date()
var kt = kennitala.generatePerson(new Date(today.getFullYear()-18, today.getMonth(), today.getDate()+1))
var info = kennitala.info(kt)
info.age
console.log(today)
console.log(kt)
console.log(info)
Þessi aðili ætti að vera 17 ára, en kennitala
skilar 18
Úr þessu kemur:
>>> Thu Feb 18 2021 10:31:35 GMT+0000 (Greenwich Mean Time)
>>> "1902037780"
>>> Object
age: 18
birthday: Wed Feb 19 2003 00:00:00 GMT+0000 (Greenwich Mean Time)
birthdayReadable: "Wed Feb 19 2003"
kt: "1902037780"
type: "person"
valid: true
Add exception for known test case kennitala of ficticious individuals used to test systems (prufumenn).
My main concern is if this will break test cases that rely on prufumenn, would we even want to disqualify those kennitölur since they are still correct.
It's a non breaking change that would affect only test cases but the question is if that's something that's desireable. This library can't validate whether a kennitala is a real person only if it's computationally correct. Would this bring ambiguity to the library?
Sound off if you have an opinion on this. I'm leaning towards not implementing this but I'm not sure.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.