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)
This project uses modern tooling to ensure code quality:
# Run all quality checks (format, lint, test)
npm run check
# Individual checks
npm run format:check # Check code formatting
npm run lint # Run ESLint
npm run lint:fix # Auto-fix linting issues
npm run format # Format all code
npm test # Run testsTypeScript type definitions are included for better IDE support and autocomplete, even though the library is written in JavaScript.
We welcome contributions! Please see CONTRIBUTING.md for detailed guidelines.
Quick start:
- Fork & clone the repo
npm installto grab dev deps- Create a branch, write code and matching tests
npm run checkto ensure quality standards- 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