Skip to content

Latest commit

 

History

History
235 lines (145 loc) · 4.88 KB

File metadata and controls

235 lines (145 loc) · 4.88 KB

norwegian-national-id-validator

norwegian-national-id-validator

Table of contents

Enumerations

Functions

Functions

NorwegianId

Const NorwegianId(idNumber): Object

Object-oriented API for Norwegian National ID Validator

example

import { NorwegianId } from 'norwegian-national-id-validator';

const valid = NorwegianId('0000000000');

Parameters

Name Type Description
idNumber string norwegian social security number

Returns

Object

Name Type
age () => number | undefined
idNumber string
isBirthNumber () => boolean
isDNumber () => boolean
isFemale () => boolean
isFhNumber () => boolean
isHNumber () => boolean
isMale () => boolean
isValid () => boolean
birthDate () => Date | undefined

diffYears

Private diffYears(startDate, endDate): number

Calculated the difference betweeen two dates.

Parameters

Name Type Description
startDate Date Date instance
endDate Date Date instance

Returns

number


getGender

getGender(elevenDigits): Gender | undefined

Returns the gender based of ID number. Returns undefined when no gender information is available.

Parameters

Name Type Description
elevenDigits string ID number

Returns

Gender | undefined


idNumberContainsBirthDate

idNumberContainsBirthDate(elevenDigits): boolean

Check if idNumber contains birth date

Parameters

Name Type Description
elevenDigits string idNumber

Returns

boolean


isValidCheckDigits

Private isValidCheckDigits(elevenDigits): boolean

Parameters

Name Type
elevenDigits string

Returns

boolean


isValidDate

isValidDate(date, expectedYear, expectedMonth, expectedDay): boolean

Checks if a date is valid against another

Parameters

Name Type Description
date Date Date instance
expectedYear string
expectedMonth string
expectedDay string

Returns

boolean


possibleAgeOfPersonWithIdNumber

possibleAgeOfPersonWithIdNumber(elevenDigits): number | undefined

Returns the age of a person with given Norwegian national identity number. Returns undefined when birth date could not be determined (e.g. for FH-numbers and invalid ID-numbers).

Parameters

Name Type Description
elevenDigits string Identification number

Returns

number | undefined


possibleAgesOfPersonWithIdNumber

possibleAgesOfPersonWithIdNumber(elevenDigits): number[]

Find possible age of person based of ID number

Parameters

Name Type Description
elevenDigits string Identification number

Returns

number[]


validateNorwegianIdNumber

validateNorwegianIdNumber(idNumber): boolean

Checks if the given value is a valid Norwegian national identity number.

example

import { validateNorwegianIdNumber } from 'norwegian-national-id-validator';
const valid = validateNorwegianIdNumber(0000000000);

Parameters

Name Type Description
idNumber string social security number

Returns

boolean

true for valid, and false for invalid ID number.


possibleBirthDateOfIdNumber

possibleBirthDateOfIdNumber(elevenDigits): Date | undefined

Returns the birth date of a person with the given Norwegian national identity number as Date object. Returns undefined when birth date could not be determined (e.g. for FH-numbers and invalid ID-numbers).

Parameters

Name Type Description
elevenDigits string Identification number

Returns

Date | undefined