TypeScript implementation of STV algorithm without any runtime dependencies.
Add the library into your project using either:
npm add stv
or
yarn add stv
Import it into your project:
import { stv } from 'stv';
To evaluate election using STV, invoke the algorithm by calling the stv(opts)
function:
const results = stv({
seatsToFill: 2,
candidates: ["Wonderwoman", "Superman", "Batman", "Iron Man"],
votes: [
{
weight: 1,
preferences: ["Wonderwoman", "Batman"]
},
{
weight: 1,
preferences: ["Iron Man", "Batman"]
},
{
weight: 1,
preferences: ["Iron Man"]
}
],
report: console.log
});
Currently, the Scottish STV rules are implemented. There may be more variants in the future.
The stv
library is licensed under MIT license.