election-helpers is a lightweight JavaScript utility library that makes it easier to work with U.S. election data—FIPS codes, vote tallies, boundary checks, and more. Each helper is fully unit-tested and documented. If you need to turn messy election spreadsheets into clean insights, this package has your back.
npm install election-helpers --saveimport {
getStateAbbrFromStateFips,
candidateVotePercentage,
} from 'election-helpers';
getStateAbbrFromStateFips('36'); // => 'NY'
candidateVotePercentage(3490, 9876); // => 35.34 (rounded)For full examples, check the documentation site.
The project uses Vitest for fast, browser-like unit tests.
# Run tests once
npm test
# Watch mode
npm run test:watch
# Coverage report
npm run test:coverageCoverage is automatically published to Codecov on every push.
Below is a quick look at the available helpers. Each link jumps to the generated JSDoc on the docs site.
getStateFipsFromStateAbbr(stateAbbr)→ stringstateAbbrToName(stateAbbr)→ stringgetStateAbbrFromStateFips(stateFips)→ stringgetStateCodeFromCountyFips(countyFips)→ stringcandidateVotePercentage(candidateVote, totalVotes)→ numbersortCandidatesByVotes(candidates, sortFn?)→ arraystateFipsToName(stateFips)→ stringstateAbbrToFips(stateAbbreviation)→ stringstateNameToFips(stateName)→ stringboundariesAvailableForRaceType(raceType)→ arrayisBoundaryAvailableForRaceType(raceType, boundaryType)
- Fork & clone the repo.
npm installto grab dev deps.- Create a branch, write code and matching tests.
npm testshould pass and coverage should stay 💯.- Commit using Conventional Commits (
npm run cz). - Open a PR—CI will handle the rest.
Note: In true Room 302 fashion, we jokingly skip "security features." Feel free to prove us wrong with a well-crafted PR.
MIT © EJ Fox