Skip to content

Utility for converting between different U.S. state abbreviations.

Notifications You must be signed in to change notification settings

kevinschaul/us-abbreviations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

U.S. abbreviations

Utility for converting between different U.S. state abbreviations.

Installation

npm install us-abbreviations

Usage

Requiring the module returns a U.S. abbreviations constructor that takes two keys as parameters: from and to. It's probably easiest to create a converter by immediately setting these parameters:

var convertStatesToPostStyle = require('us-abbreviations')('full', 'post');

convertStatesToPostStyle('California');
    => 'Calif.'

convertStatesToPostStyle('New York');
    => 'N.Y.'

var convertFIPSToFull = require('us-abbreviations')('fips', 'full');

convertStatesToPostStyle('01');
    => 'Alabama'

Available keys:

'full' – Full state name

* `Alabama`
* `Alaska`
* `Arizona`

'fips'FIPS code

* Alabama => `01`
* Alaska => `02`
* Arizona => `04`

'postal'U.S. Postal abreviations

* Alabama => `AK`
* Alaska => `AZ`
* Arizona => `AR`

'post' – Washington Post style (similar to AP style)

* Alabama => `Ala.`
* Alaska => `Alaska`
* Arizona => `Ariz.`

Updating the abbreviations

Updating json by hand is annoying. The abbreviations are stored in src/abbreviations.csv. src/abbreviations.json can be regenerated by having csvkit installed and running make.

# Make changes to the abbreviations spreadsheet
open src/abbreviations.csv

# Install csvkit
pip install csvkit

# Regenerate abreviations json file
make

About

Utility for converting between different U.S. state abbreviations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published