election-utils
This module provides various utility functions for dealing with AP election data.
Install
npm install --save election-utils
API Reference
Note: currently the API is rather verbose and somewhat unintuitive. This will probably change in the future.
Standardize
import { Standardize } from 'election-utils';
# Standardize.expand.state(stateAbbreviation)
Expands a state abbreviation to its title-case name. stateAbbreviation is case-insensitive.
Standardize.expand.state('nh');
# Standardize.collapse.state(stateName)
Collapse a state name to its abbreviation. stateName is case-insensitive.
Standardize.collapse.state('new hampshire');
# Standardize.expand.party(partyAbbreviation)
Expands a party abbreviation to its title-case name. partyAbbreviation is case-insensitive.
Standardize.expand.party('dem');
# Standardize.collapse.party(partyName)
Collapse a party name to its abbreviation. partyName is case-insensitive.
Standardize.collapse.party('democratic');
# Standardize.raceType(raceType, invert)
Convert race type to its appropriate name. Set invert to true to convert back to what AP gives us.
Standardize.raceType('Caucus');
Standardize.raceType('Primary');
Standardize.raceType('Caucuses', true);