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!
Using npm:
npm install guess-calling-code
Using yarn:
yarn add guess-calling-code
This library can be used in both browser and Node.js environments.
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)
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)
import guessCallingCode from "guess-calling-code";
const callingCode = guessCallingCode(); // example output: "1" (for United States users)
This function returns the calling code as a string based on the user's current time zone city.
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.
Curious about how it works? Check out this blog post.