@react-pakistan/util-functions 1.24.81 → 1.24.83
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.d.ts +2 -1
- package/general/format-date.js +10 -0
- package/general/get-month-number.d.ts +13 -0
- package/general/get-month-number.js +29 -0
- package/general/index.d.ts +1 -0
- package/general/index.js +1 -0
- package/package.json +1 -1
package/general/format-date.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare enum DATE_FORMATS {
|
|
|
3
3
|
DD_MM = "DD_MM",
|
|
4
4
|
YYYY_MM_DD = "YYYY_MM_DD",
|
|
5
5
|
DAY_DD_MM_YYYY = "DAY_DD_MM_YYYY",
|
|
6
|
-
DAY_DD_MM_YY_COMPACT = "DAY_DD_MM_YY_COMPACT"
|
|
6
|
+
DAY_DD_MM_YY_COMPACT = "DAY_DD_MM_YY_COMPACT",
|
|
7
|
+
HH_MM_AM_PM = "HH_MM_AM_PM"
|
|
7
8
|
}
|
|
8
9
|
export declare const formatDate: (str: string, format: DATE_FORMATS) => string;
|
package/general/format-date.js
CHANGED
|
@@ -10,6 +10,7 @@ var DATE_FORMATS;
|
|
|
10
10
|
DATE_FORMATS["YYYY_MM_DD"] = "YYYY_MM_DD";
|
|
11
11
|
DATE_FORMATS["DAY_DD_MM_YYYY"] = "DAY_DD_MM_YYYY";
|
|
12
12
|
DATE_FORMATS["DAY_DD_MM_YY_COMPACT"] = "DAY_DD_MM_YY_COMPACT";
|
|
13
|
+
DATE_FORMATS["HH_MM_AM_PM"] = "HH_MM_AM_PM";
|
|
13
14
|
})(DATE_FORMATS || (exports.DATE_FORMATS = DATE_FORMATS = {}));
|
|
14
15
|
var formatDate = function (str, format) {
|
|
15
16
|
var _a;
|
|
@@ -23,12 +24,21 @@ var formatDate = function (str, format) {
|
|
|
23
24
|
var dateNumberInTowDigits = String(cleanDateNumber).length < 2
|
|
24
25
|
? "0".concat(cleanDateNumber)
|
|
25
26
|
: cleanDateNumber;
|
|
27
|
+
// Format time for HH:MM AM/PM
|
|
28
|
+
var hours = dateObj.getHours();
|
|
29
|
+
var minutes = dateObj.getMinutes();
|
|
30
|
+
var ampm = hours >= 12 ? 'PM' : 'AM';
|
|
31
|
+
hours = hours % 12;
|
|
32
|
+
hours = hours ? hours : 12; // the hour '0' should be '12'
|
|
33
|
+
var minutesInTwoDigits = minutes < 10 ? "0".concat(minutes) : minutes;
|
|
34
|
+
var hoursInTwoDigits = hours < 10 ? "0".concat(hours) : hours;
|
|
26
35
|
var dateMap = (_a = {},
|
|
27
36
|
_a[DATE_FORMATS.LOCALE_DATE] = dateObj.toLocaleDateString(),
|
|
28
37
|
_a[DATE_FORMATS.DD_MM] = "".concat(dateObj.getDate(), " ").concat((0, get_month_name_1.getMonthName)(dateObj.getMonth())),
|
|
29
38
|
_a[DATE_FORMATS.YYYY_MM_DD] = "".concat(dateObj.getFullYear(), "-").concat(monthNumberInTwoDigits, "-").concat(dateNumberInTowDigits),
|
|
30
39
|
_a[DATE_FORMATS.DAY_DD_MM_YYYY] = "".concat((0, get_day_name_1.getDayName)(dateObj.getDay()), ", ").concat(dateObj.getDate(), " ").concat((0, get_month_name_1.getMonthName)(dateObj.getMonth()), " ").concat(dateObj.getFullYear()),
|
|
31
40
|
_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.getMonth()), " ").concat((_c = String(dateObj.getFullYear())) === null || _c === void 0 ? void 0 : _c.slice(2, 5)),
|
|
41
|
+
_a[DATE_FORMATS.HH_MM_AM_PM] = "".concat(hoursInTwoDigits, ":").concat(minutesInTwoDigits, " ").concat(ampm),
|
|
32
42
|
_a);
|
|
33
43
|
return dateMap[format];
|
|
34
44
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface IMonthNameMap {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
[key: string]: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const monthNameMap: IMonthNameMap;
|
|
8
|
+
/**
|
|
9
|
+
* Get the UTC month number (0-11) from a month name
|
|
10
|
+
* @param monthName - The name of the month (case-insensitive)
|
|
11
|
+
* @returns The UTC month number (0-11), or -1 if the month name is invalid
|
|
12
|
+
*/
|
|
13
|
+
export declare const getMonthNumber: (monthName: string) => number;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMonthNumber = exports.monthNameMap = void 0;
|
|
4
|
+
exports.monthNameMap = {
|
|
5
|
+
january: 0,
|
|
6
|
+
february: 1,
|
|
7
|
+
march: 2,
|
|
8
|
+
april: 3,
|
|
9
|
+
may: 4,
|
|
10
|
+
june: 5,
|
|
11
|
+
july: 6,
|
|
12
|
+
august: 7,
|
|
13
|
+
september: 8,
|
|
14
|
+
october: 9,
|
|
15
|
+
november: 10,
|
|
16
|
+
december: 11,
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Get the UTC month number (0-11) from a month name
|
|
20
|
+
* @param monthName - The name of the month (case-insensitive)
|
|
21
|
+
* @returns The UTC month number (0-11), or -1 if the month name is invalid
|
|
22
|
+
*/
|
|
23
|
+
var getMonthNumber = function (monthName) {
|
|
24
|
+
var normalizedName = monthName.toLowerCase().trim();
|
|
25
|
+
return exports.monthNameMap[normalizedName] !== undefined
|
|
26
|
+
? exports.monthNameMap[normalizedName]
|
|
27
|
+
: -1;
|
|
28
|
+
};
|
|
29
|
+
exports.getMonthNumber = getMonthNumber;
|
package/general/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export * from './get-day-name';
|
|
|
33
33
|
export * from './get-full-name';
|
|
34
34
|
export * from './get-href';
|
|
35
35
|
export * from './get-month-name';
|
|
36
|
+
export * from './get-month-number';
|
|
36
37
|
export * from './get-number-of-days-in-month';
|
|
37
38
|
export * from './get-pathname';
|
|
38
39
|
export * from './get-week-day';
|
package/general/index.js
CHANGED
|
@@ -49,6 +49,7 @@ __exportStar(require("./get-day-name"), exports);
|
|
|
49
49
|
__exportStar(require("./get-full-name"), exports);
|
|
50
50
|
__exportStar(require("./get-href"), exports);
|
|
51
51
|
__exportStar(require("./get-month-name"), exports);
|
|
52
|
+
__exportStar(require("./get-month-number"), exports);
|
|
52
53
|
__exportStar(require("./get-number-of-days-in-month"), exports);
|
|
53
54
|
__exportStar(require("./get-pathname"), exports);
|
|
54
55
|
__exportStar(require("./get-week-day"), exports);
|