Skip to content

๐Ÿ—บ Useful operations for working with US states and their abbreviations.

License

Notifications You must be signed in to change notification settings

nickgraffis/us-states

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jul 15, 2022
10ee6a3 ยท Jul 15, 2022

History

3 Commits
Jul 15, 2022
Jul 15, 2022
Jul 15, 2022
Jul 15, 2022
Jul 15, 2022
Jul 15, 2022
Jul 15, 2022
Jul 15, 2022
Jul 15, 2022
Jul 15, 2022
Jul 15, 2022

Repository files navigation

A set of functions for working with US states.

Installation

Node

yarn add @nickgraffis/us-states

or 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 state
  • abv: The state's abbreviation
  • code: 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 abbreviation
  • stateAbbreviationToName: Takes a state abbreviation and returns the name
  • stateAbbreviationToCode: Takes a state abbreviation and returns the numerical code
  • stateCodeToName: Takes a state numerical code and returns the name
  • stateCodeToAbbreviation: Takes a state numerical code and returns the abbreviation
  • stateNameToCode: Takes a state name and returns the numerical code

Each of these returns the state object.

About

๐Ÿ—บ Useful operations for working with US states and their abbreviations.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published