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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nrk/valg-valgomat-algoritme

v5.0.0

Published

The algorithm used to calculate distance between sets of positions for NRKs Valgomat

Readme

Valgomat algorithm

Calculate the proximity of two sets of positions.

Calculates the proximity of two sets of positions. Mostly used to calculate the proximity of various party positions and a voter position.

Usage

The simple case is comparing to sets of positions.

import { proximity } from '@nrk/valg-valgomat-algoritme'

let partyPositions = {
  id1: 1,
  id2: -1
}

let voterPositions = {
  id1: -2,
  id2: 2
}

let p = proximity(partyPositions, voterPositions)
// => 0.25

The module also comes with a function to compare many positions to one position.

import { proximityMap } from '@nrk/valg-valgomat-algoritme'

let partyAPositions = {
  id1: 1,
  id2: -1
}

let partyBPositions = {
  id1: 2,
  id2: -2
}

let partyPostitions = {
  partyA: partyAPositions,
  partyB: partyBPositions
}

let voterPositions = {
  id1: null,
  id2: -2
}

let proximities = proximityMap(voterPositions, partyPositions)
// => { "partyA": 0.75, "partyB": 1.0 }

API

import { proximity, proximityMap } from '@nrk/valg-valgomat-algoritme'

let d = proximity(positionsA, positionsB);

Accepts two sets of positions and returns the proximity between them.

Positions are given in the form of sets:

{
  [statement: string]: -2 | -1 | 1 | -2 | null
}

Output will be a number in the interval [0.0, 1.0] where 0.0 is the furthest away and 1.0 is the closest possible proximity (iow. identical).

If we are unable to determine a proximity, the output will be null. This happens if we are comparing a pair of vectors where one of the vectors are empty or there are no overlapping statements.

let proximities = proximityMap(positionsA, positionsMap);

Accepts a set of positions and a map of many sets of positions and returns a map of the proximities between a position in the position map and the first position.

This is useful if you want to calculate the proximity of one set of positions and many sets of positions. For instance between all parties and a single voter.

Output will be a map from the keys in the positionsMap and the proximity to the given position.

Installation

npm install @nrk/valg-valgomat-algoritme

Glossary

  • Position = Standpunkt
  • Statement = Påstand
  • Party = Parti
  • Voter = Velger