https://github.com/pranavrajs/timezone-phone-codes
A simple library to return telephone codes based on timezone
https://github.com/pranavrajs/timezone-phone-codes
Last synced: 3 months ago
JSON representation
A simple library to return telephone codes based on timezone
- Host: GitHub
- URL: https://github.com/pranavrajs/timezone-phone-codes
- Owner: pranavrajs
- Created: 2024-09-21T15:08:31.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-23T17:47:02.000Z (about 1 year ago)
- Last Synced: 2025-08-26T12:54:12.475Z (3 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/timezone-phone-codes
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Timezone Phone Codes
A lightweight, easy-to-use library for retrieving telephone country codes based on timezone, with full TypeScript support.
## Features
- Get phone country codes by timezone
- Zero dependencies
## Installation
You can install this package using npm, yarn, or pnpm:
```bash
# npm
npm install timezone-phone-codes
# yarn
yarn add timezone-phone-codes
# pnpm
pnpm add timezone-phone-codes
```
## Usage
Here's a basic example of how to use the library:
```typescript
import { getPhoneCodeByTimezone } from 'timezone-phone-codes';
const phoneCode = getPhoneCodeByTimezone('America/New_York');
console.log(phoneCode); // Output: +1
const unknownTimezone = getPhoneCodeByTimezone('Unknown/Timezone');
console.log(unknownTimezone); // Output: null
```
## API
```ts
getPhoneCodeByTimezone(timezone: string): string | null
```
Returns the phone country code for the given timezone. If the timezone is not recognized, it returns `null`.
## Supported Timezones
This library supports a wide range of timezones. Here are a few examples:
- America/New_York: +1
- Europe/London: +44
- Asia/Tokyo: +81
- Australia/Sydney: +61
## Testing
To run the tests:
```bash
pnpm test
```
To run the tests with coverage:
```bash
pnpm coverage
```