🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

test-nino

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-nino

The fastest UK National Insurance number generator (nino). Generates a random valid UK NI number in accordance with NIM39110 guidelines on Gov.uk

1.1.2
Source
npm
Version published
Weekly downloads
894
-17.98%
Maintainers
1
Weekly downloads
 
Created
Source

test-nino

The fastest random UK National Insurance number generator.

  • Getting Started
  • Available functions
  • How fast can it be?
  • What is a valid UK National Insurance number?

Getting Started

Install

npm i test-nino

Import

// ESM/TypeScript
import * as testNino from 'test-nino';

// CommonJS
const testNino = require('test-nino');

// Deno
import * as testNino from 'https://deno.land/x/test_nino@X.X.X';

Available functions

There are 2 available functions exposed:

random

To generate a single valid NINO, you can simply run the random function:

const nino = testNino.random();
// Returns a valid UK National Insurance number e.g. AA000000A

Warning: it is not guaranteed that you couldn't generate the same NINO more than once using this method. If you require a unique NINO every time, I suggest you use the incremental generator

incremental

This method is best if you want to ensure you don't generate a duplicate NINO and utilises a JavaScript Generator to enumerate through all possible valid UK NI numbers AA000000A-ZY999999D (there are 1,492,000,000 in total).

The generator will enumerate on prefix, number and then suffix.

// Create a generator instance
const uniqueNiGenerator = testNino.incremental();

for(let i = 0; i <= 10000000; i++) {
    uniqueNiGenerator.next()
    // Returns the next instance from the generator
    // on the 1st iteration it will return { value: 'AA000000A', done: false }
    // on the 2nd iteration it will return { value: 'AA000000B', done: false }
    // ...
    // on the 10000000th iteration it will return { value: 'AC500000A', done: false }
}

The done property will only return true once all possible combinations have been enumerated (with the value ZY999999D).

How fast can it be?

Here is how test-nino's random function fares against other packages:

packageRun 1Run 2Run 3AverageOps/sec
fake-nino3,2013,2143,2133,209186,955
random_uk_nino2,4972,4592,4302,460243,902
test-nino1,1481,1841,1501,161516,943

Benchmarks ran on an i7 3.0Ghz with 16GB RAM, using Node 16. All times for runs and averages are recorded in milliseconds for 10,000,000 runs

As you can see, test-nino is more than 2x faster than the next fastest random NI number generator

What makes it so fast?

Other packages use loops which go through the process of Generate random NINO > is it valid? > no > repeat, until a valid nino is given.

This costs precious CPU time and blocks the Node Event Loop.

test-nino is made different and instead stores the complete list of valid prefixes which are then picked at random. No loops, so this gives the random function a BigO complexity of O(1)

What is a valid UK National Insurance number?

To cite the rules at the time of implementation from Gov.uk:

A NINO is made up of 2 letters, 6 numbers and a final letter, which is always A, B, C, or D.

It looks something like this: QQ 12 34 56 A

All prefixes are valid except:

  • The characters D, F, I, Q, U, and V are not used as either the first or >second letter of a NINO prefix.
  • The letter O is not used as the second letter of a prefix.
  • Prefixes BG, GB, KN, NK, NT, TN and ZZ are not to be used

Keywords

nino

FAQs

Package last updated on 01 Oct 2022

Did you know?

Socket

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.

Install

Related posts