15 lines
568 B
TypeScript
15 lines
568 B
TypeScript
import { CountryCode, getExampleNumber } from "libphonenumber-js";
|
|
import examples from "libphonenumber-js/examples.mobile.json";
|
|
import { getCountryCallingCode } from "libphonenumber-js/max";
|
|
|
|
export default function getPhoneMask(countryCode: CountryCode) {
|
|
let example = getExampleNumber(
|
|
countryCode,
|
|
examples
|
|
)!.formatInternational();
|
|
const callingCode = getCountryCallingCode(countryCode);
|
|
const callingCodeLen = callingCode.length + 1;
|
|
example = example.slice(callingCodeLen).trim();
|
|
return example.replace(/\d/g, "0");
|
|
}
|