@nickgraffis/us-states
v0.0.3
Published
🗺 Useful operations for working with US states and their abbreviations.
Readme
A set of functions for working with US states.
Installation
Node
yarn add @nickgraffis/us-statesor use npm or pnpm
CDN
<script src="https://unpkg.com/@nickgraffis/us-states@latest/dist/us-states.min.js"></script>Usage
The two main functions are autocomplete and states. Both take a single argument, query, which is a string and both return a state object with the following properties:
name: The name of the stateabv: The state's abbreviationcode: The state's numerical code
import { autocomplete, states } from '@nickgraffis/us-states'
// Autocomplete
autocomplete('mar') // { name: 'Maryland', abv: 'MD', code: '24' }
// also works
autocomplete('md') // { name: 'Maryland', abv: 'MD', code: '24' }
// States
states('MD') // { name: 'Maryland', abv: 'MD', code: '24' }
// also works
states('Maryland') // { name: 'Maryland', abv: 'MD', code: '24' }There are also more specific functions for getting the state's name, abbreviation, and numerical code.
stateNameToAbbreviation: Takes a state name and returns the abbreviationstateAbbreviationToName: Takes a state abbreviation and returns the namestateAbbreviationToCode: Takes a state abbreviation and returns the numerical codestateCodeToName: Takes a state numerical code and returns the namestateCodeToAbbreviation: Takes a state numerical code and returns the abbreviationstateNameToCode: Takes a state name and returns the numerical code
Each of these returns the state object.
