Election Helpers
Read docs.md or GH pages for documentation
--
Functions
- getStateFipsFromStateAbbr(stateAbbr) ⇒
string
- stateAbbrToName(stateAbbr) ⇒
string
- getStateAbbrFromStateFips(stateFips) ⇒
string
- getStateCodeFromCountyFips(countyFips) ⇒
string
-
Get the state code from the county fips string
- candidateVotePercentage(candidateVote, totalVotes) ⇒
number
-
Given the absolute number of votes a candidate has received, and the total number of votes in the election, returns the percentage of votes the candidate has received.
- sortCandidatesByVotes(candidates, sortFunction) ⇒
Array
-
Given an array of candidate objects, returns a sorted array of candidate objects, sorted by the number of votes they have received with the specified sort function.
- stateFipsToName(stateFips) ⇒
string
- stateAbbrToFips(stateAbbreviation) ⇒
string
-
Get the state fips code from the abbreviation, like 'NY' to '36'
- stateNameToFips(stateName) ⇒
string
- boundariesAvailableForRaceType(raceType) ⇒
array
- isBoundaryAvailableForRaceType(raceType, boundaryType)
stateNameHash ⇒ string
Example
stateNameHash['01']
// returns 'Alabama'
getStateFipsFromStateAbbr(stateAbbr) ⇒ string
Example
getStateFipsFromStateAbbr('CA')
// => '06'
getStateFipsFromStateAbbr('NY')
// => '36'
stateAbbrToName(stateAbbr) ⇒ string
Example
getStateNameFromStateAbbr('AL')
// returns 'Alabama'
getStateAbbrFromStateFips(stateFips) ⇒ string
Example
getStateAbbrFromStateFips('01')
// returns 'AL'
Example
getStateAbbrFromStateFips('36')
// returns 'NY'
Example
getStateAbbrFromStateFips('XX')
// throws an error
getStateCodeFromCountyFips(countyFips) ⇒ string
Example
getStateCodeFromCountyFips('01001')
// returns '01'
Example
getStateCodeFromCountyFips(01000)
// throws Error
Example
getStateCodeFromCountyFips('01')
// throws Error
candidateVotePercentage(candidateVote, totalVotes) ⇒ number
Example
getPercentageOfVotes(100, 200)
// returns 50
sortCandidatesByVotes(candidates, sortFunction) ⇒ Array
stateFipsToName(stateFips) ⇒ string
Example
stateFipsToName('01')
// returns 'Alabama'
stateAbbrToFips(stateAbbreviation) ⇒ string
Example
getStateFipsFromAbbreviation('NY')
// returns '36'
stateNameToFips(stateName) ⇒ string
Example
getStateFipsFromStateName('Alabama')
// returns '01'
boundariesAvailableForRaceType(raceType) ⇒ array
Example
boundariesAvailableForRaceType('president')
// returns ['state', 'county']
Example
boundariesAvailableForRaceType('senate')
// returns ['state']
Example
boundariesAvailableForRaceType('house')
// returns ['district']
Example
boundariesAvailableForRaceType(2016)
// returns null
isBoundaryAvailableForRaceType(raceType, boundaryType)
Example
isBoundaryAvailableForRaceType('president', 'county')
// returns true
Example
isBoundaryAvailableForRaceType('president', 'state')
// returns true
Example
isBoundaryAvailableForRaceType('president', 'district')
// returns false