convert-region
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

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';

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i convert-region

    Weekly Downloads

    10

    Version

    2.0.3

    License

    MIT

    Unpacked Size

    13.5 kB

    Total Files

    5

    Last publish

    Collaborators

    • thejessewinton