npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

utallig

v1.0.0

Published

Generate numbers used in Norwegian administration

Downloads

31

Readme

utallig

Generate random but valid numbers used in Norwegian government and banking. Useful for making mock data. The library will generate the following:

  • Organization numbers (orgNum) - 9 digit number identifying companies and organizations. Issued by brreg.
  • Bank accounts - 11 number digit identifying a bank account issued by a Norwegian bank.
  • Fødselesnummer (fNum) - 11 digit ID number issued to Norwegian citizens.
  • d-nummer (dNum) - 11 digit temporary ID number issued to people allowed to live and work in Norway.
  • [KID] - Number used to identify customers when paying online

Caveat: The generated numbers are random. Thus it's possible that a generated number is in use by an individual or organization. No attempt is made to avoid this, and there is not way to look up used personal numbers.

Installing

npm install utallig

# or

yarn install utallig

Fødselsnummer and D-nummer:

The two functions work the same way and take the same arguments

import { fNum, dNum } from 'utallig';

const someFNum = fNum();
const someDNum = fNum();

// A random fNum for a male person born between 1979 and 1980, inclusive.
const randomWithOptions = fNum({
  startYear: 1970,
  endYear: 1980,
  gender: 'm',
});

The functions take an options object with the following optional properties:

  • randomFloat - RNG function
  • startYear - The first allowed year to generate number for. The default is 1854, the earliest allowed number in fødselsnummer and d-nummer.
  • endYear - The last allowed year to number for. The default is 2049, the latest allowed number in fødselsnummer and d-nummer. In other words, by default you can get numbers for people not yet born.
  • gender - The gender of the person. This is encoded into the number. By default a random gender is chosen. Valid options are f and m.

Org number

import { orgNum } from 'utallig';

const random = orgNum();

The orgNum function accepts an options object with the following optional properties:

  • randomFloat - RNG function
  • prefix - A string of numbers that will be used as the first digit(s) of the generated org numbers. Useful to get a particular range of numbers.

Account number

The accountNum function accepts an options object with the following optional properties:

  • randomFloat - RNG function
  • registerNumber - A "registry number" for the bank. This is a 4 digit number that identifies the bank that has issued the account. See the Norwegian BIC registry for the list of banks IDs.

KID number

the kid function accepts an options object, with the following optional properties:

  • randomFloat - RNG function
  • length - The length the generated KID number should be. Allowed values are 3-25. By default, a random number in that range is generated.
  • prefix - A number to prefix the generated number with. If using length, the length includes the prefix.
  • algorithm - KID numbers are validated using either mod10(luhn) or mod11 algorithms. By default, a random algorithm is chosen.

Controlling the random generator

By default, the library uses the Math.random() built-in function in JavaScript. It's possible to pass in other random number generators. This can be useful to generate predictable mock data by using a seedable random generator:

import { fNum } from 'utallig';
import seedrandom from 'seedrandom';

const rng = seedrandom('my seed');
const random = fNum({ randomFloat: rng });

Every time this code runs, it generates the same random fNum.

The function passed in as the randomFloat parameter must function the same way as the built int Math.random function. That is, it must be a function that returns a floating point number between 0.0 and 1.0.