{"id":21890071,"url":"https://github.com/ejfox/election-helpers","last_synced_at":"2025-04-15T11:28:01.704Z","repository":{"id":42016139,"uuid":"510422352","full_name":"ejfox/election-helpers","owner":"ejfox","description":"A collection of resources, tools, and patterns for election data analysis and viz","archived":false,"fork":false,"pushed_at":"2024-02-05T17:09:14.000Z","size":16090,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T04:18:00.083Z","etag":null,"topics":["data","elections","helpers"],"latest_commit_sha":null,"homepage":"https://ejfox.github.io/election-helpers/global.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ejfox.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-04T16:01:43.000Z","updated_at":"2022-10-11T22:27:01.000Z","dependencies_parsed_at":"2024-11-28T11:31:43.619Z","dependency_job_id":"84ac55ab-d37d-415d-b5ff-bc2353a21f39","html_url":"https://github.com/ejfox/election-helpers","commit_stats":{"total_commits":29,"total_committers":1,"mean_commits":29.0,"dds":0.0,"last_synced_commit":"45fa1604b05093d1cd13259b9bd5ef615e2e077f"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejfox%2Felection-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejfox%2Felection-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejfox%2Felection-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejfox%2Felection-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ejfox","download_url":"https://codeload.github.com/ejfox/election-helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249060391,"owners_count":21206326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","elections","helpers"],"created_at":"2024-11-28T11:28:34.787Z","updated_at":"2025-04-15T11:28:01.664Z","avatar_url":"https://github.com/ejfox.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Election Helpers\n\n## Read [docs.md](https://github.com/ejfox/election-helpers/blob/master/docs.md) or [GH pages](https://ejfox.github.io/election-helpers/global.html) for documentation \n\n![npm](https://img.shields.io/npm/v/election-helpers?color=%235B70D9) \n\n[View on NPM](https://www.npmjs.com/package/election-helpers)\n\n--\n## Constants\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#stateNameHash\"\u003estateNameHash\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#usBounds\"\u003eusBounds\u003c/a\u003e : \u003ccode\u003e\u003ca href=\"#USBounds\"\u003eUSBounds\u003c/a\u003e\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eThe bounds of the United States.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n## Functions\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#partyNameNormalizer\"\u003epartyNameNormalizer(partyNameString)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eNormalizes a party name string to a standardized format.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#stateAbbrToName\"\u003estateAbbrToName(stateAbbr)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#getStateAbbrFromStateFips\"\u003egetStateAbbrFromStateFips(stateFips)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#getStateCodeFromCountyFips\"\u003egetStateCodeFromCountyFips(countyFips)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eGet the state code from the county fips string\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#candidateVotePercentage\"\u003ecandidateVotePercentage(candidateVote, totalVotes)\u003c/a\u003e ⇒ \u003ccode\u003enumber\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eGiven 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#sortCandidatesByVotes\"\u003esortCandidatesByVotes(candidates, sortFunction)\u003c/a\u003e ⇒ \u003ccode\u003eArray\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eGiven 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#stateFipsToName\"\u003estateFipsToName(stateFips)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#stateAbbrToFips\"\u003estateAbbrToFips(stateAbbreviation)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eGet the state fips code from the abbreviation, like \u0026#39;NY\u0026#39; to \u0026#39;36\u0026#39;\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#stateNameToFips\"\u003estateNameToFips(stateName)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#boundariesAvailableForRaceType\"\u003eboundariesAvailableForRaceType(raceType)\u003c/a\u003e ⇒ \u003ccode\u003earray\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#isBoundaryAvailableForRaceType\"\u003eisBoundaryAvailableForRaceType(raceType, boundaryType)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003c/dl\u003e\n\n## Typedefs\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#USBounds\"\u003eUSBounds\u003c/a\u003e : \u003ccode\u003eObject\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eRepresents the bounds of the United States.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#StatePlaneProjections\"\u003eStatePlaneProjections\u003c/a\u003e : \u003ccode\u003eObject\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eRepresents the state planes and bounds for every state.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#County\"\u003eCounty\u003c/a\u003e : \u003ccode\u003eObject\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eAn array of county names with their corresponding FIPS codes.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003ca name=\"stateNameHash\"\u003e\u003c/a\u003e\n\n## stateNameHash ⇒ \u003ccode\u003estring\u003c/code\u003e\n**Kind**: global constant  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - - The state name  \n**Throws**:\n\n- \u003ccode\u003eError\u003c/code\u003e - If the state fips code is invalid.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| stateFips | \u003ccode\u003estring\u003c/code\u003e | The state fips code. |\n\n**Example**  \n```js\nstateNameHash['01']\n// returns 'Alabama'\n```\n\u003ca name=\"usBounds\"\u003e\u003c/a\u003e\n\n## usBounds : [\u003ccode\u003eUSBounds\u003c/code\u003e](#USBounds)\nThe bounds of the United States.\n\n**Kind**: global constant  \n\u003ca name=\"partyNameNormalizer\"\u003e\u003c/a\u003e\n\n## partyNameNormalizer(partyNameString) ⇒ \u003ccode\u003estring\u003c/code\u003e\nNormalizes a party name string to a standardized format.\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - The normalized party name.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| partyNameString | \u003ccode\u003estring\u003c/code\u003e | The party name string to be normalized. |\n\n**Example**  \n```js\nconst partyName = partyNameNormalizer('R') // returns 'rep'\nconst partyName = partyNameNormalizer('REP') // returns 'rep'\nconst partyName = partyNameNormalizer('Republican') // returns 'rep'\nconst partyName = partyNameNormalizer('republican') // returns 'rep'\n```\n\u003ca name=\"stateAbbrToName\"\u003e\u003c/a\u003e\n\n## stateAbbrToName(stateAbbr) ⇒ \u003ccode\u003estring\u003c/code\u003e\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - - The state name  \n**Throws**:\n\n- \u003ccode\u003eError\u003c/code\u003e - If the state abbreviation is invalid.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| stateAbbr | \u003ccode\u003estring\u003c/code\u003e | Two letter state abbreviation |\n\n**Example**  \n```js\ngetStateNameFromStateAbbr('AL')\n// returns 'Alabama'\n```\n\u003ca name=\"getStateAbbrFromStateFips\"\u003e\u003c/a\u003e\n\n## getStateAbbrFromStateFips(stateFips) ⇒ \u003ccode\u003estring\u003c/code\u003e\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - - The state abbreviation  \n**Throws**:\n\n- \u003ccode\u003eError\u003c/code\u003e - If the state fips code is invalid.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| stateFips | \u003ccode\u003estring\u003c/code\u003e | The state fips code. |\n\n**Example**  \n```js\ngetStateAbbrFromStateFips('01')\n// returns 'AL'\n```\n**Example**  \n```js\ngetStateAbbrFromStateFips('36')\n// returns 'NY'\n```\n**Example**  \n```js\ngetStateAbbrFromStateFips('XX')\n// throws an error\n```\n\u003ca name=\"getStateCodeFromCountyFips\"\u003e\u003c/a\u003e\n\n## getStateCodeFromCountyFips(countyFips) ⇒ \u003ccode\u003estring\u003c/code\u003e\nGet the state code from the county fips string\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - - The state fips code.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| countyFips | \u003ccode\u003estring\u003c/code\u003e | The county fips code. |\n\n**Example**  \n```js\ngetStateCodeFromCountyFips('01001')\n// returns '01'\n```\n**Example**  \n```js\ngetStateCodeFromCountyFips(01000)\n// throws Error\n```\n**Example**  \n```js\ngetStateCodeFromCountyFips('01')\n// throws Error\n```\n\u003ca name=\"candidateVotePercentage\"\u003e\u003c/a\u003e\n\n## candidateVotePercentage(candidateVote, totalVotes) ⇒ \u003ccode\u003enumber\u003c/code\u003e\nGiven 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.\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003enumber\u003c/code\u003e - - The percentage of votes the candidate has received.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| candidateVote | \u003ccode\u003enumber\u003c/code\u003e | The number of votes the candidate has received. |\n| totalVotes | \u003ccode\u003enumber\u003c/code\u003e | The total number of votes in the election. |\n\n**Example**  \n```js\ngetPercentageOfVotes(100, 200)\n// returns 50\n```\n\u003ca name=\"sortCandidatesByVotes\"\u003e\u003c/a\u003e\n\n## sortCandidatesByVotes(candidates, sortFunction) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nGiven 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.\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - - A sorted array of candidate objects.  \n**Throws**:\n\n- \u003ccode\u003eError\u003c/code\u003e - If the candidates array is invalid.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| candidates | \u003ccode\u003eArray\u003c/code\u003e | An array of candidate objects. |\n| sortFunction | \u003ccode\u003efunction\u003c/code\u003e | The function to use to sort the candidates (like d3.descending) |\n\n\u003ca name=\"stateFipsToName\"\u003e\u003c/a\u003e\n\n## stateFipsToName(stateFips) ⇒ \u003ccode\u003estring\u003c/code\u003e\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - - The state name  \n**Throws**:\n\n- \u003ccode\u003eError\u003c/code\u003e - If the state fips code is invalid.\n\n\n| Param | Type |\n| --- | --- |\n| stateFips | \u003ccode\u003estring\u003c/code\u003e | \n\n**Example**  \n```js\nstateFipsToName('01')\n// returns 'Alabama'\n```\n\u003ca name=\"stateAbbrToFips\"\u003e\u003c/a\u003e\n\n## stateAbbrToFips(stateAbbreviation) ⇒ \u003ccode\u003estring\u003c/code\u003e\nGet the state fips code from the abbreviation, like 'NY' to '36'\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - - The state fips code.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| stateAbbreviation | \u003ccode\u003estring\u003c/code\u003e | The state abbreviation. |\n\n**Example**  \n```js\ngetStateFipsFromAbbreviation('NY')\n// returns '36'\n```\n\u003ca name=\"stateNameToFips\"\u003e\u003c/a\u003e\n\n## stateNameToFips(stateName) ⇒ \u003ccode\u003estring\u003c/code\u003e\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - - The state fips code  \n**Throws**:\n\n- \u003ccode\u003eError\u003c/code\u003e - If the state name is invalid.\n\n\n| Param | Type |\n| --- | --- |\n| stateName | \u003ccode\u003estring\u003c/code\u003e | \n\n**Example**  \n```js\ngetStateFipsFromStateName('Alabama')\n// returns '01'\n```\n\u003ca name=\"boundariesAvailableForRaceType\"\u003e\u003c/a\u003e\n\n## boundariesAvailableForRaceType(raceType) ⇒ \u003ccode\u003earray\u003c/code\u003e\n**Kind**: global function  \n**Returns**: \u003ccode\u003earray\u003c/code\u003e - - An array of the available district types  \n\n| Param | Type |\n| --- | --- |\n| raceType | \u003ccode\u003estring\u003c/code\u003e | \n\n**Example**  \n```js\nboundariesAvailableForRaceType('president')\n// returns ['state', 'county']\n```\n**Example**  \n```js\nboundariesAvailableForRaceType('senate')\n// returns ['state']\n```\n**Example**  \n```js\nboundariesAvailableForRaceType('house')\n// returns ['district']\n```\n**Example**  \n```js\nboundariesAvailableForRaceType(2016)\n// returns null\n```\n\u003ca name=\"isBoundaryAvailableForRaceType\"\u003e\u003c/a\u003e\n\n## isBoundaryAvailableForRaceType(raceType, boundaryType)\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| raceType | \u003ccode\u003estring\u003c/code\u003e | The race type, like 'president', 'house', or 'senate' |\n| boundaryType | \u003ccode\u003estring\u003c/code\u003e | The type of boundary, like 'county', 'state', or 'district' |\n\n**Example**  \n```js\nisBoundaryAvailableForRaceType('president', 'county')\n// returns true\n```\n**Example**  \n```js\nisBoundaryAvailableForRaceType('president', 'state')\n// returns true\n```\n**Example**  \n```js\nisBoundaryAvailableForRaceType('president', 'district')\n// returns false\n```\n\u003ca name=\"USBounds\"\u003e\u003c/a\u003e\n\n## USBounds : \u003ccode\u003eObject\u003c/code\u003e\nRepresents the bounds of the United States.\n\n**Kind**: global typedef  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| type | \u003ccode\u003estring\u003c/code\u003e | The type of the feature collection. |\n| features | \u003ccode\u003eArray.\u0026lt;Object\u0026gt;\u003c/code\u003e | The features of the collection. |\n\n\u003ca name=\"StatePlaneProjections\"\u003e\u003c/a\u003e\n\n## StatePlaneProjections : \u003ccode\u003eObject\u003c/code\u003e\nRepresents the state planes and bounds for every state.\n\n**Kind**: global typedef  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| proj | \u003ccode\u003estring\u003c/code\u003e | The projection |\n| rotate | \u003ccode\u003eArray.\u0026lt;number\u0026gt;\u003c/code\u003e | The rotation of the projection. |\n| bounds | \u003ccode\u003eArray.\u0026lt;number\u0026gt;\u003c/code\u003e | The bounds of the projection. |\n| parallels | \u003ccode\u003eArray.\u0026lt;number\u0026gt;\u003c/code\u003e | The parallels of the projection. |\n\n\u003ca name=\"County\"\u003e\u003c/a\u003e\n\n## County : \u003ccode\u003eObject\u003c/code\u003e\nAn array of county names with their corresponding FIPS codes.\n\n**Kind**: global typedef  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| fips_code | \u003ccode\u003enumber\u003c/code\u003e | The FIPS code of the county. |\n| name | \u003ccode\u003estring\u003c/code\u003e | The name of the county. |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fejfox%2Felection-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fejfox%2Felection-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fejfox%2Felection-helpers/lists"}