/us-abbreviations

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

Primary LanguageJavaScript

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', 'times');

convertStatesToTimesStyle('Texas');
    => 'Texas'

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

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

convertStatesToTimesStyle('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`

'times' – New York Times 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