Package Exports
- convert-region
- convert-region/dist/index.js
- convert-region/dist/index.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (convert-region) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
convert-region
A simple utility to convert region abbreviations to full names and vice-versa. Built with Typescript, and incredibly small.
Story
I found myself building an application with location data being return from an existing API as abbreviations but, for presentation's sake, I needed full state names. I ended up writing a utility locally within my project, and ultimately decided to publish. Check out my website if you want.
Usage
To use, install the package:
pnpm (recommended)
pnpm add convert-region
npm
npm install convert-region
yarn
yarn add convert-region
Then import it into your project:
import { convertRegion } from 'convert-region';
From there, pass in the full name or abbreviation of one of the regions below and it will return the match. For example:
convertRegion('NY');
will return New York
, and:
convertRegion('New York');
will return NY
.
Types
While the convertRegion
function accepts any string value, this newest version exports a type for the regions, and a union type for validating possible input. You can import them like so:
import type { RegionInput, Regions } from 'convert-region';
And use them to validate your input.
const region: RegionInput = 'NY';