Kennitala
Icelandic social security number (kennitölur) utilities for servers and clients.
Install with npm:
npm install kennitala
Install with yarn:
yarn add kennitala
Examples
const kennitala = require('kennitala');
kennitala.isValid('3108962099');
kennitala.isValid('8281249124');
More examples
const kennitala = require('kennitala');
kennitala.info('3108962099');
{
kt: '3108962099',
valid: true,
type: 'person',
birthday: 1996-08-31T00:00:00.000Z,
birthdayReadable: 'Sat Aug 31 1996',
age: 22
}
kennitala.isPerson('3108962099');
kennitala.isPerson('601010-0890');
kennitala.isPerson(3108962099);
kennitala.isPerson('31^_^08!!96LOL20T_T99');
kennitala.isCompany('6010100890');
kennitala.isCompany('601010-0890');
kennitala.isCompany(3108962099);
kennitala.format('310896DIRTYSSID2099');
kennitala.format('3108962099', '-apple pie-');
kennitala.format('3108962099', '');
kennitala.clean(3108962099);
API documentation
kennitala.isValid([string, int]);
returns boolean
Checks if kennitala checksum is correct for either a person or company
If passed a string with non-digit characters included it removes them before validating
kennitala.info([string, int]);
returns object with relevant information about this kennitala
{
kennitala: char(10),
valid: boolean,
type: enum("company", "person")
age: int,
birthday: Date object,
birthdayReadable: Human readable Date String
}
kennitala.isPerson([string, int]);
returns boolean
Checks if kennitala checksum is correct and if day of birth is between 1-31
If passed a string with non-digit characters included it removes them before validating
kennitala.isCompany([string, int]);
returns boolean
Checks if kennitala checksum is correct and if day of birth is between 41-71
If passed a string with non-digit characters included it removes them before validating
kennitala.format([string, int], ?[string]);
returns string
Ensures datatype is string, then matches and removes all non-digit characters
and adds a traditional '-' spacer between 6th and 7th digit. This can be customized
with an optional 2nd parameter.
kennitala.clean([string, int]);
returns string
Ensures datatype is string, then matches and removes all non-digit characters.
Does not ensure the remaining string is 10 characters or that the kennitala is valid
kennitala.generatePerson([date]);
returns string
Takes Date object as a parameter and returns a new kennitala for a person
kennitala.generateCompany([date]);
returns string
Takes Date object as a parameter and returns a new kennitala for a company
Testing
Uses Mocha for testing. In order to execute the tests, you need to run npm install -g mocha
first. Once you've done that
you can open up a command line and point it to the root directory of the project. From there you should be able to type either npm test
or simply mocha
to run the tests.
Building
To build the project, you can type npm run dist
, which minifies the script and generates a source map, and places both in the dist/
folder.
Since Oct 2nd 2018 we are proudly sponsored in part by BrowserStack which sponsors thousands of open source projects. The plan is to implement automated testing for older browsers which will give us and our users good overview of the support they can expect for older browsers and operating systems.
I am using BrowserStack to easily test this library accross different browsers and operating systems from the comfort of my personal Linux machines, no need to set up a Windows or MacOS machine for testing.