Election Helpers
docs.md or GH pages for documentation
Read--
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)
string
stateNameHash ⇒ Example
stateNameHash['01']
// returns 'Alabama'
string
getStateFipsFromStateAbbr(stateAbbr) ⇒ Example
getStateFipsFromStateAbbr('CA')
// => '06'
getStateFipsFromStateAbbr('NY')
// => '36'
string
stateAbbrToName(stateAbbr) ⇒ Example
getStateNameFromStateAbbr('AL')
// returns 'Alabama'
string
getStateAbbrFromStateFips(stateFips) ⇒ Example
getStateAbbrFromStateFips('01')
// returns 'AL'
Example
getStateAbbrFromStateFips('36')
// returns 'NY'
Example
getStateAbbrFromStateFips('XX')
// throws an error
string
getStateCodeFromCountyFips(countyFips) ⇒ Example
getStateCodeFromCountyFips('01001')
// returns '01'
Example
getStateCodeFromCountyFips(01000)
// throws Error
Example
getStateCodeFromCountyFips('01')
// throws Error
number
candidateVotePercentage(candidateVote, totalVotes) ⇒ Example
getPercentageOfVotes(100, 200)
// returns 50
Array
sortCandidatesByVotes(candidates, sortFunction) ⇒
string
stateFipsToName(stateFips) ⇒ Example
stateFipsToName('01')
// returns 'Alabama'
string
stateAbbrToFips(stateAbbreviation) ⇒ Example
getStateFipsFromAbbreviation('NY')
// returns '36'
string
stateNameToFips(stateName) ⇒ Example
getStateFipsFromStateName('Alabama')
// returns '01'
array
boundariesAvailableForRaceType(raceType) ⇒ 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