Skip to content

Client-side resolution for acquiring the user's dialing code enables seamless phone number input within browsers, and this library is also compatible with Node.js!

License

Notifications You must be signed in to change notification settings

AstraSurge/guess-calling-code

Repository files navigation

guess-calling-code

npm FOSSA Status Codecov

Client-side resolution for acquiring the user's dialing code enables seamless phone number input within browsers, and this library is also compatible with Node.js!

Install

Using npm:

npm install guess-calling-code

Using yarn:

yarn add guess-calling-code

Usage

This library can be used in both browser and Node.js environments.

Browser Usage

First, include the library in your HTML file:

<script src="https://cdn.jsdelivr.net/npm/guess-calling-code/dist/index.umd.js"></script>

Then, in your JavaScript code:

const guessCallingCode = window.guessCallingCode;
const callingCode = guessCallingCode(); // example output: "1" (for United States users)

Node.js Usage

npm install guess-calling-code

or

yarn add guess-calling-code

Then, in your JavaScript code:

const guessCallingCode = require("guess-calling-code");
const callingCode = guessCallingCode(); // example output: "1" (for United States users)

TypeScript Usage

import guessCallingCode from "guess-calling-code";
const callingCode = guessCallingCode(); // example output: "1" (for United States users)

API

guessCallingCode(): string | undefined

This function returns the calling code as a string based on the user's current time zone city.

Support

If you have any questions or need help, please open an issue on the GitHub repository, and we will do our best to assist you.

Further Reading

Curious about how it works? Check out this blog post.

License

LICENSE (MIT)