Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@digitalarkivet/nin-validator
Advanced tools
Readme
This is a validator/parser for norwegian national identity numbers, written in Typescript.
Basic usage is very simple:
import validateNin from "@digitalarkivet/nin-validator"
// The default export accepts birth numbers and D-numbers
if(!validateNin(someNin)) {
throw "Invalid NIN"
}
To extract more information, use parseNin
. Then, you have the option to specify which number types to accept. The export ALL_NIN_TYPES
include rarely-used types like H-numbers and FH-numbers, while DEFAULT_NIN_TYPES
include birth number and D number. You can also mix-and-match by using NinNumberType
directly.
import {parseNin, ALL_NIN_TYPES, DEFAULT_NIN_TYPES, NinNumberType} from "@digitalarkivet/nin-validator"
const {info, error} = parseNin(someNin)
// Is the same as
const {info, error} = parseNin(someNin, ...DEFAULT_NIN_TYPES)
// Or, to can accept all types (very rarely what you want)
const {info, error} = parseNin(someNin, ...ALL_NIN_TYPES)
// Or, to accept specific types
const {info, error} = parseNin(someNin, NinNumberType.BirthNumber, NinNumberType.HNumber)
The info
key will be undefined
on error.
On success, it contains an object with gender
, dateOfBirth
, numberType
, and isTestNumber
keys.
The error
key will contain a NinValidationError
on error, and be undefined
on success.
The Gender
enum uses the ISO/IEC 5218 codes:
parseNin
will return Not known
for FH-numbers, and in the future for "new" national identification numbers that do not carry gender information.
A JS date, midnight on the date of birth, in local time.
Contains undefined
for FH numbers.
One of the NinNumberType
values. This is a Typescript enum, backed by a string.
This flag is set to true if the number originates from "Tenor", the test utility of the norwegian tax authority.
Since Arkivverket has no reason to exclude test numbers from production use (they will not occur in real archives, and if they do, we want to display them), test numbers can not be rejected when validating a nin with nin-validator.
A NinValidationError
is one of a predefined set of error codes, saying which check failed.
FORMAT
means the input string is not 11 digits.CHECKSUM
means the checksum validation failedDATE
means the date does not exist (leap year?), or the century code did not match the individual part of the nin.INVALID_TYPE
means the nin is valid, but the type is not one of the allowed types passed to parseNin()
The test data for birth numbers, D numbers and H-numbers is synthetically generated.
The test data for "tenor test numbers" is generated by Tenor.
FAQs
Validating and parsing norwegian national identity numbers in Typescript
The npm package @digitalarkivet/nin-validator receives a total of 1 weekly downloads. As such, @digitalarkivet/nin-validator popularity was classified as not popular.
We found that @digitalarkivet/nin-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.