@molopos/shared 2.0.0 → 2.0.1
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/date/index.d.ts +39 -0
- package/date/index.js +114 -0
- package/index.d.ts +3 -0
- package/index.js +1 -0
- package/package.json +1 -1
package/date/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DateLike, Numberlike } from "../index";
|
|
2
|
+
/**
|
|
3
|
+
* Format a date to a string
|
|
4
|
+
* @param date - The date to format (e.g. "2026-01-01", "2026-01-01T00:00:00.000Z", etc.)
|
|
5
|
+
* @param locale - The locale to use (e.g. "en-US", "it-IT", "fr-FR", etc.)
|
|
6
|
+
* @returns The formatted date (e.g. "1 Jan 2026", "1 Jan 2026 00:00", etc.)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* formateDate("2026-01-01", "en-US"); // "1 Jan 2026"
|
|
10
|
+
*/
|
|
11
|
+
export declare const formateDate: (date: Date, locale: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Format a date to a string
|
|
14
|
+
* @param date - The date to format (e.g. "2026-01-01", "2026-01-01T00:00:00.000Z", etc.)
|
|
15
|
+
* @param locale - The locale to use (e.g. "en-US", "it-IT", "fr-FR", etc.)
|
|
16
|
+
* @returns The formatted date (e.g. "1 Jan 2026", "1 Jan 2026 00:00", etc.)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* formateddLLLyyyy("2026-01-01", "en-US"); // "1 Jan 2026"
|
|
20
|
+
*/
|
|
21
|
+
export declare const formateddLLLyyyy: (date: DateLike, locale: string) => string;
|
|
22
|
+
export declare const formateYYDDMM: (date: Date, locale: string) => string;
|
|
23
|
+
export declare const formateHHmm: (date: Date, locale: string) => string;
|
|
24
|
+
export declare const formatDateToUtc: (date: Date) => string;
|
|
25
|
+
export declare const formatDateDDMMYYToUtc: (date: Date, locale: string) => string;
|
|
26
|
+
export declare const formateToT: (date: Date) => string;
|
|
27
|
+
export declare const dateTimeNowUtc: () => Date;
|
|
28
|
+
export declare const formateToCccc: (date: Date, locale: string) => string;
|
|
29
|
+
export declare const formateTodd: (date: Date, locale: string) => string;
|
|
30
|
+
export declare const formateToLLLL: (date: Date, locale: string) => string;
|
|
31
|
+
export declare const formateToRFC2822: (date: Date, locale: string) => string;
|
|
32
|
+
export declare const formateToyyyy: (date: Date) => string;
|
|
33
|
+
export declare const viewYyformateToYyyy: (date: Date) => string;
|
|
34
|
+
export declare const addDaysToTimeNowUtcDate: (dayNumber: number) => Date;
|
|
35
|
+
export declare const formateMMLongDate: (date: Date, locale: string) => string;
|
|
36
|
+
export declare const formateDDDate: (date: Date, lang: string) => string;
|
|
37
|
+
export declare const formateddLLDate: (date: Date, lang: string) => string;
|
|
38
|
+
export declare const formateDDDateISO: (date: Date, locale: string) => string;
|
|
39
|
+
export declare const formateToUnixIntegerddLLLyyyy: (date: Numberlike, locale: string) => string;
|
package/date/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formateToUnixIntegerddLLLyyyy = exports.formateDDDateISO = exports.formateddLLDate = exports.formateDDDate = exports.formateMMLongDate = exports.addDaysToTimeNowUtcDate = exports.viewYyformateToYyyy = exports.formateToyyyy = exports.formateToRFC2822 = exports.formateToLLLL = exports.formateTodd = exports.formateToCccc = exports.dateTimeNowUtc = exports.formateToT = exports.formatDateDDMMYYToUtc = exports.formatDateToUtc = exports.formateHHmm = exports.formateYYDDMM = exports.formateddLLLyyyy = exports.formateDate = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
const luxon_1 = require("luxon");
|
|
6
|
+
/**
|
|
7
|
+
* Format a date to a string
|
|
8
|
+
* @param date - The date to format (e.g. "2026-01-01", "2026-01-01T00:00:00.000Z", etc.)
|
|
9
|
+
* @param locale - The locale to use (e.g. "en-US", "it-IT", "fr-FR", etc.)
|
|
10
|
+
* @returns The formatted date (e.g. "1 Jan 2026", "1 Jan 2026 00:00", etc.)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* formateDate("2026-01-01", "en-US"); // "1 Jan 2026"
|
|
14
|
+
*/
|
|
15
|
+
const formateDate = (date, locale) => {
|
|
16
|
+
let dateReturn = null;
|
|
17
|
+
const todaysDate = new Date();
|
|
18
|
+
const currentYear = todaysDate.getFullYear();
|
|
19
|
+
const dateInit = luxon_1.DateTime.fromISO(String(date));
|
|
20
|
+
const dateYear = Number(dateInit.toFormat("yyyy"));
|
|
21
|
+
const todayNowDateFormatted = (0, exports.formatDateToUtc)(date);
|
|
22
|
+
const todayDateFormatted = (0, exports.formatDateToUtc)(todaysDate);
|
|
23
|
+
if (todayNowDateFormatted === todayDateFormatted) {
|
|
24
|
+
dateReturn = dateInit.setLocale(locale).toRelative();
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
if (currentYear === dateYear) {
|
|
28
|
+
dateReturn = dateInit.setLocale(locale).toFormat("dd LLL HH:mm");
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
dateReturn = (0, exports.formatDateDDMMYYToUtc)(date, locale);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return dateReturn;
|
|
35
|
+
};
|
|
36
|
+
exports.formateDate = formateDate;
|
|
37
|
+
/**
|
|
38
|
+
* Format a date to a string
|
|
39
|
+
* @param date - The date to format (e.g. "2026-01-01", "2026-01-01T00:00:00.000Z", etc.)
|
|
40
|
+
* @param locale - The locale to use (e.g. "en-US", "it-IT", "fr-FR", etc.)
|
|
41
|
+
* @returns The formatted date (e.g. "1 Jan 2026", "1 Jan 2026 00:00", etc.)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* formateddLLLyyyy("2026-01-01", "en-US"); // "1 Jan 2026"
|
|
45
|
+
*/
|
|
46
|
+
const formateddLLLyyyy = (date, locale) => {
|
|
47
|
+
const dateInit = luxon_1.DateTime.fromISO(String(date));
|
|
48
|
+
return dateInit.setLocale(locale).toFormat("dd LLL yyyy");
|
|
49
|
+
};
|
|
50
|
+
exports.formateddLLLyyyy = formateddLLLyyyy;
|
|
51
|
+
const formateYYDDMM = (date, locale) => {
|
|
52
|
+
const dateInit = luxon_1.DateTime.fromISO(String(date));
|
|
53
|
+
return dateInit.setLocale(locale).toFormat("ff");
|
|
54
|
+
};
|
|
55
|
+
exports.formateYYDDMM = formateYYDDMM;
|
|
56
|
+
const formateHHmm = (date, locale) => {
|
|
57
|
+
const dateInit = luxon_1.DateTime.fromISO(String(date));
|
|
58
|
+
return dateInit.setLocale(locale).toFormat("t");
|
|
59
|
+
};
|
|
60
|
+
exports.formateHHmm = formateHHmm;
|
|
61
|
+
const formatDateToUtc = (date) => (0, date_fns_1.format)(date, "dd-MM-yyyy");
|
|
62
|
+
exports.formatDateToUtc = formatDateToUtc;
|
|
63
|
+
const formatDateDDMMYYToUtc = (date, locale) => {
|
|
64
|
+
const dateInit = luxon_1.DateTime.fromISO(String(date));
|
|
65
|
+
return dateInit.setLocale(locale).toFormat("D");
|
|
66
|
+
};
|
|
67
|
+
exports.formatDateDDMMYYToUtc = formatDateDDMMYYToUtc;
|
|
68
|
+
const formateToT = (date) => luxon_1.DateTime.fromJSDate(date).toFormat("T");
|
|
69
|
+
exports.formateToT = formateToT;
|
|
70
|
+
const dateTimeNowUtc = () => luxon_1.DateTime.utc().toJSDate();
|
|
71
|
+
exports.dateTimeNowUtc = dateTimeNowUtc;
|
|
72
|
+
const formateToCccc = (date, locale) => luxon_1.DateTime.fromISO(String(date)).setLocale(locale).toFormat("cccc");
|
|
73
|
+
exports.formateToCccc = formateToCccc;
|
|
74
|
+
const formateTodd = (date, locale) => luxon_1.DateTime.fromISO(String(date)).setLocale(locale).toFormat("dd");
|
|
75
|
+
exports.formateTodd = formateTodd;
|
|
76
|
+
const formateToLLLL = (date, locale) => luxon_1.DateTime.fromISO(String(date)).setLocale(locale).toFormat("LLLL");
|
|
77
|
+
exports.formateToLLLL = formateToLLLL;
|
|
78
|
+
const formateToRFC2822 = (date, locale) => luxon_1.DateTime.fromISO(String(date)).setLocale(locale).toFormat("DDDD");
|
|
79
|
+
exports.formateToRFC2822 = formateToRFC2822;
|
|
80
|
+
const formateToyyyy = (date) => luxon_1.DateTime.fromISO(String(date)).toFormat("yyyy");
|
|
81
|
+
exports.formateToyyyy = formateToyyyy;
|
|
82
|
+
const viewYyformateToYyyy = (date) => {
|
|
83
|
+
const todaysDate = new Date();
|
|
84
|
+
const currentYear = todaysDate.getFullYear();
|
|
85
|
+
const dateYear = Number(luxon_1.DateTime.fromISO(String(date)).toFormat("yyyy"));
|
|
86
|
+
return currentYear === dateYear ? null : `- ${dateYear}`;
|
|
87
|
+
};
|
|
88
|
+
exports.viewYyformateToYyyy = viewYyformateToYyyy;
|
|
89
|
+
const addDaysToTimeNowUtcDate = (dayNumber) => luxon_1.DateTime.utc().plus({ days: dayNumber }).toJSDate();
|
|
90
|
+
exports.addDaysToTimeNowUtcDate = addDaysToTimeNowUtcDate;
|
|
91
|
+
const formateMMLongDate = (date, locale) => {
|
|
92
|
+
return luxon_1.DateTime.fromJSDate(date)
|
|
93
|
+
.setLocale(locale)
|
|
94
|
+
.toLocaleString({ month: "long" });
|
|
95
|
+
};
|
|
96
|
+
exports.formateMMLongDate = formateMMLongDate;
|
|
97
|
+
const formateDDDate = (date, lang) => {
|
|
98
|
+
return luxon_1.DateTime.fromJSDate(date).setLocale(lang).toFormat("DD");
|
|
99
|
+
};
|
|
100
|
+
exports.formateDDDate = formateDDDate;
|
|
101
|
+
const formateddLLDate = (date, lang) => {
|
|
102
|
+
return luxon_1.DateTime.fromJSDate(date).setLocale(lang).toFormat("dd LLL");
|
|
103
|
+
};
|
|
104
|
+
exports.formateddLLDate = formateddLLDate;
|
|
105
|
+
const formateDDDateISO = (date, locale) => {
|
|
106
|
+
const dateInit = luxon_1.DateTime.fromISO(String(date));
|
|
107
|
+
return dateInit.setLocale(locale).toFormat("DD");
|
|
108
|
+
};
|
|
109
|
+
exports.formateDDDateISO = formateDDDateISO;
|
|
110
|
+
const formateToUnixIntegerddLLLyyyy = (date, locale) => {
|
|
111
|
+
const dateInit = luxon_1.DateTime.fromSeconds(Number(date));
|
|
112
|
+
return dateInit.setLocale(locale).toFormat("dd LLL yyyy");
|
|
113
|
+
};
|
|
114
|
+
exports.formateToUnixIntegerddLLLyyyy = formateToUnixIntegerddLLLyyyy;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./date"), exports);
|
|
17
18
|
__exportStar(require("./enum"), exports);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.
|
|
1
|
+
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.1","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"date-fns":"^4.1.0","luxon":"^3.7.2"}}
|