@react-pakistan/util-functions 1.24.38 → 1.24.40
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.
package/general/format-date.js
CHANGED
|
@@ -14,6 +14,7 @@ var DATE_FORMATS;
|
|
|
14
14
|
})(DATE_FORMATS || (exports.DATE_FORMATS = DATE_FORMATS = {}));
|
|
15
15
|
var formatDate = function (str, format) {
|
|
16
16
|
var _a;
|
|
17
|
+
var _b, _c;
|
|
17
18
|
var dateObj = new Date(str);
|
|
18
19
|
var cleanMonthNumber = dateObj.getMonth() + 1;
|
|
19
20
|
var monthNumberInTwoDigits = String(cleanMonthNumber).length < 2 ? "0".concat(cleanMonthNumber) : cleanMonthNumber;
|
|
@@ -26,9 +27,8 @@ var formatDate = function (str, format) {
|
|
|
26
27
|
_a[DATE_FORMATS.DAY_DD_MM_YYYY] = "".concat((0, get_day_name_1.getDayName)(dateObj
|
|
27
28
|
.getDay()), ", ").concat(dateObj
|
|
28
29
|
.getDate(), " ").concat((0, get_month_name_1.getMonthName)(dateObj.getMonth()), " ").concat(dateObj.getFullYear()),
|
|
29
|
-
_a[DATE_FORMATS.DAY_DD_MM_YY_COMPACT] = "".concat((0, get_day_name_1.getDayName)(dateObj.getDay())
|
|
30
|
-
.
|
|
31
|
-
.getMonth()), " ").concat(String(dateObj.getFullYear()).slice(2, 5)),
|
|
30
|
+
_a[DATE_FORMATS.DAY_DD_MM_YY_COMPACT] = "".concat((_b = (0, get_day_name_1.getDayName)(dateObj.getDay())) === null || _b === void 0 ? void 0 : _b.slice(0, 3), ", ").concat(dateObj.getDate(), " ").concat((0, get_month_name_1.getMonthName)(dateObj
|
|
31
|
+
.getMonth()), " ").concat((_c = String(dateObj.getFullYear())) === null || _c === void 0 ? void 0 : _c.slice(2, 5)),
|
|
32
32
|
_a);
|
|
33
33
|
return dateMap[format];
|
|
34
34
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
2
|
+
interface FormattedPhoneNumber {
|
|
3
|
+
e164: string;
|
|
4
|
+
international: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const formatInternationalPhoneNumber: (phone: string, defaultCountry?: CountryCode) => FormattedPhoneNumber | null;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatInternationalPhoneNumber = void 0;
|
|
4
|
+
var libphonenumber_js_1 = require("libphonenumber-js");
|
|
5
|
+
var formatInternationalPhoneNumber = function (phone, defaultCountry) {
|
|
6
|
+
if (defaultCountry === void 0) { defaultCountry = 'US'; }
|
|
7
|
+
var phoneNumber = (0, libphonenumber_js_1.parsePhoneNumberFromString)(phone, defaultCountry);
|
|
8
|
+
if (phoneNumber && phoneNumber.isValid()) {
|
|
9
|
+
return {
|
|
10
|
+
e164: phoneNumber.format('E.164'),
|
|
11
|
+
international: phoneNumber.formatInternational(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
exports.formatInternationalPhoneNumber = formatInternationalPhoneNumber;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
2
|
+
interface FormattedPhoneNumber {
|
|
3
|
+
e164: string;
|
|
4
|
+
international: string;
|
|
5
|
+
}
|
|
6
|
+
interface Return {
|
|
7
|
+
formatted: FormattedPhoneNumber | null;
|
|
8
|
+
formatNumber: (v: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const usePhoneFormatter: (defaultCountry?: CountryCode) => Return;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePhoneFormatter = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var libphonenumber_js_1 = require("libphonenumber-js");
|
|
6
|
+
var usePhoneFormatter = function (defaultCountry) {
|
|
7
|
+
if (defaultCountry === void 0) { defaultCountry = 'US'; }
|
|
8
|
+
var _a = (0, react_1.useState)(null), formatted = _a[0], setFormatted = _a[1];
|
|
9
|
+
var formatNumber = function (value) {
|
|
10
|
+
var phoneNumber = (0, libphonenumber_js_1.parsePhoneNumberFromString)(value, defaultCountry);
|
|
11
|
+
if (phoneNumber) {
|
|
12
|
+
setFormatted({
|
|
13
|
+
e164: phoneNumber.isValid() ? phoneNumber.format('E.164') : '',
|
|
14
|
+
international: phoneNumber.formatInternational(),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
setFormatted(null);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return { formatted: formatted, formatNumber: formatNumber };
|
|
22
|
+
};
|
|
23
|
+
exports.usePhoneFormatter = usePhoneFormatter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-pakistan/util-functions",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.40",
|
|
4
4
|
"description": "A library of all util functions",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"eslint-plugin-import": "^2.29.1",
|
|
60
60
|
"husky": "^9.0.11",
|
|
61
61
|
"jest": "^29.7.0",
|
|
62
|
+
"libphonenumber-js": "^1.12.13",
|
|
62
63
|
"lint-staged": "^15.2.2",
|
|
63
64
|
"lodash.curry": "^4.1.1",
|
|
64
65
|
"lodash.isequal": "^4.5.0",
|