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

schulze.js

v0.2.1

Published

Schulze method JavaScript implementation.

Downloads

15

Readme

schulze.js

Schulze method, JavaScript implementation, while tie breaking is not implemented.

Installation

with NodeJS:

npm install --save schulze.js

in borwser: download schulze.min.js and include it in your HTML with following:

<script src="<path-to-your>/schulze.min.js"></script>

or, from a CDN:

<script src="https://cdn.jsdelivr.net/gh/zbryikt/[email protected]/dist/schulze.min.js"/>

Sample Usage

var fs = require("fs");
var schulze = require("schulze.js")
var inputOptions = {}, outputOptions = {};
var vote = new schulze();
vote.fromCsv(fs.readFileSync("<your-csv-file>").toString(), inputOptions)
  .then(function(obj) { /* obj: see below. */
    var csv = vote.toCsv(outputOptions);
  });

members in the resolved object:

  • candidates - candidate list with additional information:
    • name: candidate name
    • idx: candidate input order
    • rank: final ranking of this candidate.
    • count: count of win
  • pairPreferenceMatrix: 2D Matrix for pairwise preference strength against every possible pair between candidates.
    • byIndex: matrix ordered by candidate index when input.
    • byRank: matrix ordered by candidate calculated ranking.

API

  • toGrid(option): format pairwise-preference-matrix of schulze result into human-readable grid.
    • option:
      • byIndex: use index-ordered matrix if true, otherise use rank-ordered matrix. default false
  • toCsv(option): format candidates and their rank with CSV format.
    • option:
      • sort: sort candidates by their rank. default false ( in input order )
  • fromCsv(CSVString, importOption) - import data in CSV format
  • fromArray(2DArray, importOption) - import data directly as an 2D array
  • fromArraySync(2DArray, importOption) - import data directly as an 2D array. Synchronized version.
  • fromJson(json, importOption) - import data in JSON defined as described below.

Import Options

  • isRowBased: one ballot per row if true. default true. See next section for more examples.
  • higherIsBetter: higher input value means better if set to true. default true
    • true: Judge prefers A more then B if score of A > score of B
    • false: Judge prefers B more then A if score of A > score of B
  • showWarning: warning for any unparsable input. default true

Sample Input Format

Row Based CSV: one ballot / rank preference per row.

Judge, Cand1,Cand2,Cand3
JudgeA,    1,    2,    3
JudgeB,    2,    1,    1
JudgeC,    3,    4,    1

Column Based CSV: one ballot / rank preference per column.

Item, JudgeA,JudgeB,JudgeC
Cand1,     1,     2,     3
Cand2,     2      1,     4
Cand3,     3,     1,     1

2DArray: similar to CSV format but in a parsed JS 2D Array.

[
  ["Candidates", "JudgeA", "JudgeB", "JudgeC"],
  ["Cand1", 1, 2, 3],
  ["Cand2", 2, 1, 1],
  ["Cand3", 3, 4, 1]
]

JSON:

{
  scores: {
    "JudgeA": [1,2,3],
    "JudgeB": [2,1,1],
    "JudgeC": [3,4,1],
  }, candidates: [
    "Cand1", "Cand2", "Cand3"
  ]
}

Test Data Set

You can use tool/dataset-generator.ls to generate some test dataset. usage:

lsc tool/dataset-generator.ls -- -h

Currently there are several datasets available under dataset folder:

  • rand-c5-j5 - generated with lsc tool/dataset-generator -- -c 5 -j 5 -r true
  • rand-c7-j100 - generated with lsc tool/dataset-generator -- -c 7 -j 100 -r true
  • rand-c32-j10 - generated with lsc tool/dataset-generator -- -c 32 -j 10 -r true
  • rand-c200-j20 - generated with lsc tool/dataset-generator -- -c 200 -j 20
  • simple - handcrafted simple dataset with 3 candidates, 3 judges.
  • wiki-schulze-method - scenario in Example section of Wikipedia: Schulze Method
  • .. and some other datasets under dataset/dev folder working in progress.

Todo List

  • Tie breaking
  • publish in NPM

Reference

License

MIT