Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikaello/norwegian-national-id-validator
Validate Norwegian national identity numbers
https://github.com/mikaello/norwegian-national-id-validator
social-security-number ssn-validation validator
Last synced: 2 months ago
JSON representation
Validate Norwegian national identity numbers
- Host: GitHub
- URL: https://github.com/mikaello/norwegian-national-id-validator
- Owner: mikaello
- License: mit
- Created: 2017-02-16T21:10:24.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-04-08T02:02:18.000Z (9 months ago)
- Last Synced: 2024-04-14T12:56:00.538Z (9 months ago)
- Topics: social-security-number, ssn-validation, validator
- Language: TypeScript
- Homepage: https://mikaello.github.io/norwegian-national-id-validator
- Size: 1.4 MB
- Stars: 24
- Watchers: 4
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# norwegian-national-id-validator
[![Travis build status](https://travis-ci.org/mikaello/norwegian-national-id-validator.svg?branch=master)](https://travis-ci.org/mikaello/norwegian-national-id-validator)
[![npm](https://img.shields.io/npm/v/norwegian-national-id-validator.svg?style=flat-square)](https://www.npmjs.com/package/norwegian-national-id-validator)Validate Norwegian national identity numbers ([birth number](https://en.wikipedia.org/wiki/National_identification_number#Norway) ([fødselsnummer](https://no.wikipedia.org/wiki/F%C3%B8dselsnummer)), D-number, H-number and FH-number).
The NPM module is ES5, but TypeScript and Flow types is also exported. Types for Flow is generated with [Flowgen](https://github.com/joarwilk/flowgen).
## Installation
Install the package via `npm`:
```
npm install --save norwegian-national-id-validator
```or
```
yarn add norwegian-national-id-validator
```## Usage
This package exports a functional and object-oriented API for your convenience.
### Object-oriented API
```js
import { NorwegianId } from 'norwegian-national-id-validator';const validation = NorwegianId('29029600013');
console.log(validation.isValid())
// => trueconsole.log(validation.isBirthNumber())
// => trueconsole.log(validation.isDNumber())
// => falseconsole.log(validation.isHNumber())
// => falseconsole.log(validation.isFhNumber())
// => falseconsole.log(validation.isMale())
// => falseconsole.log(validation.isFemale())
// => trueconsole.log(validation.age())
// => 24console.log(validation.birthDate())
// => Thu Feb 29 1996 [...]
```### Functional API
#### validateNorwegianIdNumber(value)
This function checks if the given value is a valid Norwegian national identity number. Returns `true` for valid, and `false` for invalid ID-number.
**Examples**
```js
import { validateNorwegianIdNumber } from 'norwegian-national-id-validator';validateNorwegianIdNumber('29029900157');
// => falsevalidateNorwegianIdNumber('29029600013');
// => true
```#### possibleAgeOfPersonWithIdNumber(value)
This function 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).
**Examples**
```js
import { possibleAgeOfPersonWithIdNumber } from 'norwegian-national-id-validator';possibleAgeOfPersonWithIdNumber('03111590925');
// => 1possibleAgeOfPersonWithIdNumber('03110175225');
// => 15
```## Documentation
Apart from this README, you can find details and examples of using the SDK in the following places:
- [SDK Documentation](docs/README.md)
- [Examples](examples/)## Tests
To run the tests for this module:
```
npm test
```## Other relevant projects
- [Censorbot by Vipps](https://github.com/vippsas/vipps-developers/tree/master/housekeeping/censorbot)
Censorbot looks for patterns in numbers containing 11 digits posted in Slack, using this package.- [ng-input-validators](https://github.com/hansamaligamage/ng-input-validations/tree/master/input-validations)
Code samples for Angular.- [cobraz/norwegian-ssn-graphql-scalar](https://github.com/cobraz/norwegian-ssn-graphql-scalar)
Custom GraphQL scalar type that utilizes this library.## License
[MIT](LICENSE)