npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kennitalajs

v1.1.1

Published

Validation for an Icelandic kennitala (social security number)

Downloads

75

Readme

Kennitalajs

Validation for an Icelandic kennitala (social security number)

Getting started:

Install with npm (npm install kennitalajs) or:

<!-- HTML -->
<script type="text/javascript" src="https://unpkg.com/kennitalajs@latest/kennitala.min.js"></script>

<script type="text/javascript">
    var test = new Kennitala(2202863399);

    console.log(test);
</script>
//Nodejs

require('kennitalajs/kennitala');
//or
import 'kennitalajs/kennitala';

var test = new Kennitala(2202863399);
console.log(test);

Accepted types:

//Kennitalajs accepts all types of possible kt formats
var type1 = 2202863399; //Integer
var type2 = '2202863399'; //String
var type3 = '220286-3399'; //String with the widely used hyphen

// I do however reccommend storing the kennitala in a string format since integers cant start with a zero

Validating a persons kennitala

var kennitala = new Kennitala(2202863399);
//kennitala returns:
{
    valid: true, //<----------- Tells us if the kennitala is valid
    type: 'person', //<-------- Tells us if kennitala belongs to a person or a company
    age: 22, //<--------------- The person/company age in years
    msAge: 694383374545, //<--- Time in milliseconds since birth/company was founded
    birthdayToday: true, //<--- Tells us if the person/company has a birthday today
    kt: 2202863399 //<--------- The kennitala as a integer
};

Validating a company kennitala

var kennitala = new Kennitala('521110-0660');
//kennitala returns:
{
    valid: true,
    type: 'company',
    age: 5,
    msAge: 174515150922,
    birthdayToday: true,
    kt: 5211100660
};

Create a fake (but valid) kennitala

var kennitala = new Kennitala('fake');
//kennitala returns:
{
    valid: true,
    ......
};

Invalid date examples

We can recieve 5 possible reasons for when the kennitala is not valid:

Kennitala can be too short

var kennitala = new Kennitala(22028633);

//kennitala returns:
{
    valid: false,
    reason: 'Kennitala is too short',
    errorCode: 1
};

Something is wrong with digits 1 and 2

XXxxxxxxxx:

var kennitala = new Kennitala(3202863399);

kennitala returns:
{
    valid: false,
    reason: 'Birthdate is out of range (digits 1 and 2)',
    errorCode: 2
};

Something is wrong with digits 3 and 4

xxXXxxxxxx

var kennitala = new Kennitala(2222863399);
//kennitala returns:
{
    valid: false,
    reason: 'Month digits are out of range (digits 3 and 4)',
    errorCode: 3
};

xxxxXXXxxx Digits 5,6,7 and 8 can be anything so we cant validate them


Something is wrong with digit number 9

xxxxxxxxXx

var kennitala = new Kennitala(2202863349);
//kennitala returns:
{
  valid: false,
    reason: 'Digit 9 is not valid. Read about "Níundi stafurinn" here: https://is.wikipedia.org/wiki/Kennitala',
    errorCode: 4
};

Something is wrong with digit number 10

xxxxxxxxxX

//
var kennitala = new Kennitala(2202863393);

//kennitala returns:
{
    valid: false,
    reason: 'Century digit out of range (digit 10)',
    errorCode: 5
};