Translate area codes to zip codes. A utility for looking up postal codes in the US.
npm install areacode-to-zipcodeThis library provides a simple utility to look up a US ZIP code by area code.
Clone this repository and install dependencies:
``sh`
npm install areacode-to-zipcode
Import the functions and use them in your TypeScript or JavaScript project:
`typescript
import { getZipcodeFromAreaCode, getDataFromAreaCode } from './lib';
const zip = getZipcodeFromAreaCode(212); // '10024'
console.log(zip);
const data = getDataFromAreaCode(212);
/*
{
city: "New York City",
state: "NY",
zipCode: "10024",
country: "US"
}
*/
console.log(data);
`
If the area code is not found, the functions return null.
- areaCode: The US area code as a number.
- Returns: The corresponding ZIP code as a string, or null if not found.
- areaCode: The US area code as a number.
- Returns: An object with city, state, zipCode, and country fields, or null if not found.
Run tests with:
`sh`
npm test
Area code to ZIP code mappings are stored in lib/data.json`.