@react-pakistan/util-functions 1.25.79 → 1.25.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatPhoneDisplay(value: unknown, defaultCountry?: string): string | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatPhoneDisplay = formatPhoneDisplay;
|
|
4
|
+
var libphonenumber_js_1 = require("libphonenumber-js");
|
|
5
|
+
function formatPhoneDisplay(value, defaultCountry) {
|
|
6
|
+
if (value === null || value === undefined)
|
|
7
|
+
return undefined;
|
|
8
|
+
var input = String(value).trim();
|
|
9
|
+
if (input === '')
|
|
10
|
+
return undefined;
|
|
11
|
+
try {
|
|
12
|
+
// First attempt: parse the input as-is (handles +E.164 and numbers with punctuation)
|
|
13
|
+
var pn = (0, libphonenumber_js_1.parsePhoneNumberFromString)(input, defaultCountry);
|
|
14
|
+
// If parse failed and input is digits-only, try parsing as E.164 by prefixing +
|
|
15
|
+
if ((!pn || !pn.isValid()) && /^\d+$/.test(input)) {
|
|
16
|
+
pn = (0, libphonenumber_js_1.parsePhoneNumberFromString)("+".concat(input));
|
|
17
|
+
}
|
|
18
|
+
if (pn && pn.isValid()) {
|
|
19
|
+
return pn.formatInternational();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (_a) {
|
|
23
|
+
// fall through to digits-only fallback
|
|
24
|
+
}
|
|
25
|
+
// Fallback: return digits-only or prefixed with + for long international-like numbers
|
|
26
|
+
var digits = input.replace(/\D/g, '');
|
|
27
|
+
if (!digits)
|
|
28
|
+
return undefined;
|
|
29
|
+
if (digits.length > 12)
|
|
30
|
+
return "+".concat(digits);
|
|
31
|
+
return digits;
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-pakistan/util-functions",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.82",
|
|
4
4
|
"description": "A library of all util functions",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -90,7 +90,8 @@
|
|
|
90
90
|
},
|
|
91
91
|
"resolutions": {
|
|
92
92
|
"js-cookie": "3.0.7",
|
|
93
|
-
"postcss": "8.5.10"
|
|
93
|
+
"postcss": "8.5.10",
|
|
94
|
+
"@react-pakistan/util-functions": "workspace:."
|
|
94
95
|
},
|
|
95
96
|
"engines": {
|
|
96
97
|
"npm": ">=10.0.0",
|