@stryke/date 0.0.2
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/CHANGELOG.md +9 -0
- package/LICENSE +201 -0
- package/README.md +298 -0
- package/dist/format.cjs +206 -0
- package/dist/format.d.cts +135 -0
- package/dist/format.d.cts.map +1 -0
- package/dist/format.d.mts +135 -0
- package/dist/format.d.mts.map +1 -0
- package/dist/format.mjs +200 -0
- package/dist/format.mjs.map +1 -0
- package/dist/index.cjs +12 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +4 -0
- package/dist/validate.cjs +44 -0
- package/dist/validate.d.cts +37 -0
- package/dist/validate.d.cts.map +1 -0
- package/dist/validate.d.mts +37 -0
- package/dist/validate.d.mts.map +1 -0
- package/dist/validate.mjs +42 -0
- package/dist/validate.mjs.map +1 -0
- package/package.json +30 -0
package/dist/format.cjs
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/format.ts
|
|
4
|
+
/**
|
|
5
|
+
* A utility function that formats a Date object into a string in the format "YYYY-MM-DD".
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This function takes a Date object as input and returns a string representation of the date in the "YYYY-MM-DD" format.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
13
|
+
* const formattedDate = formatYYYYMMDD(date); // formattedDate will be "2024-01-15"
|
|
14
|
+
* const formattedDateWithCustomSeparator = formatYYYYMMDD(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "2024/01/15"
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param date - The Date object to be formatted.
|
|
18
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
19
|
+
* @returns A string representing the formatted date in "YYYY-MM-DD" format.
|
|
20
|
+
*/
|
|
21
|
+
function formatYYYYMMDD(date, options) {
|
|
22
|
+
const year = date.getFullYear();
|
|
23
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
24
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
25
|
+
const separator = options?.separator ?? "-";
|
|
26
|
+
return `${year}${separator}${month}${separator}${day}`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A utility function that formats a Date object into a string in the format "MM-DD-YYYY".
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* This function takes a Date object as input and returns a string representation of the date in the "MM-DD-YYYY" format.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
37
|
+
* const formattedDate = formatMMDDYYYY(date); // formattedDate will be "01-15-2024"
|
|
38
|
+
* const formattedDateWithCustomSeparator = formatMMDDYYYY(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "01/15/2024"
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param date - The Date object to be formatted.
|
|
42
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
43
|
+
* @returns A string representing the formatted date in "MM-DD-YYYY" format.
|
|
44
|
+
*/
|
|
45
|
+
function formatMMDDYYYY(date, options) {
|
|
46
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
47
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
48
|
+
const year = date.getFullYear();
|
|
49
|
+
const separator = options?.separator ?? "-";
|
|
50
|
+
return `${month}${separator}${day}${separator}${year}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A utility function that formats a Date object into a string in the format "DD-MM-YYYY".
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* This function takes a Date object as input and returns a string representation of the date in the "DD-MM-YYYY" format.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
61
|
+
* const formattedDate = formatDDMMYYYY(date); // formattedDate will be "15-01-2024"
|
|
62
|
+
* const formattedDateWithCustomSeparator = formatDDMMYYYY(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "15/01/2024"
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @param date - The Date object to be formatted.
|
|
66
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
67
|
+
* @returns A string representing the formatted date in "DD-MM-YYYY" format.
|
|
68
|
+
*/
|
|
69
|
+
function formatDDMMYYYY(date, options) {
|
|
70
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
71
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
72
|
+
const year = date.getFullYear();
|
|
73
|
+
const separator = options?.separator ?? "-";
|
|
74
|
+
return `${day}${separator}${month}${separator}${year}`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A utility function that formats a Date object into a string in the format "YYYY-MM-DD HH:mm:ss".
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* This function formats the date portion using the configured separator and appends
|
|
81
|
+
* a time component in 24-hour format separated by spaces.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const date = new Date(2024, 0, 15, 13, 45, 30);
|
|
86
|
+
* const formattedDate = formatYYYYMMDDHHmmss(date); // formattedDate will be "2024-01-15 13:45:30"
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @param date - The Date object to be formatted.
|
|
90
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
91
|
+
* @returns A string representing the formatted date in "YYYY-MM-DD HH:mm:ss" format.
|
|
92
|
+
*/
|
|
93
|
+
function formatYYYYMMDDHHmmss(date, options) {
|
|
94
|
+
const year = date.getFullYear();
|
|
95
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
96
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
97
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
98
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
99
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
100
|
+
const separator = options?.separator ?? "-";
|
|
101
|
+
return `${year}${separator}${month}${separator}${day} ${hours}:${minutes}:${seconds}`;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A utility function that formats a Date object into a string in the format "YYYY-MM-DDTHH:mm:ss".
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* This function formats the date portion using the configured separator and appends
|
|
108
|
+
* a time component in 24-hour format separated by a "T" character.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const date = new Date(2024, 0, 15, 13, 45, 30);
|
|
113
|
+
* const formattedDate = formatYYYYMMDDTHHMMSS(date); // formattedDate will be "2024-01-15T13:45:30"
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @param date - The Date object to be formatted.
|
|
117
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
118
|
+
* @returns A string representing the formatted date in "YYYY-MM-DDTHH:mm:ss" format.
|
|
119
|
+
*/
|
|
120
|
+
function formatYYYYMMDDTHHMMSS(date, options) {
|
|
121
|
+
const year = date.getFullYear();
|
|
122
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
123
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
124
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
125
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
126
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
127
|
+
const separator = options?.separator ?? "-";
|
|
128
|
+
return `${year}${separator}${month}${separator}${day}T${hours}:${minutes}:${seconds}`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A utility function that formats a Date object into a string based on the specified format.
|
|
132
|
+
*
|
|
133
|
+
* @remarks
|
|
134
|
+
* This function takes a Date object and a format string as input and returns a string representation of the date in the specified format. It also accepts optional configuration for customizing the separator used in the date string.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
139
|
+
* const formattedDate1 = formatDate(date, "YYYY-MM-DD"); // formattedDate1 will be "2024-01-15"
|
|
140
|
+
* const formattedDate2 = formatDate(date, "MM-DD-YYYY"); // formattedDate2 will be "01-15-2024"
|
|
141
|
+
* const formattedDate3 = formatDate(date, "DD-MM-YYYY"); // formattedDate3 will be "15-01-2024"
|
|
142
|
+
* const formattedDate4 = formatDate(date, "YYYYMMDD"); // formattedDate4 will be "20240115"
|
|
143
|
+
* const formattedDate5 = formatDate(date, "YYYY/MM/DD"); // formattedDate5 will be "2024/01/15"
|
|
144
|
+
* const formattedDateWithCustomSeparator = formatDate(date, "YYYY-MM-DD", { separator: "/" }); // formattedDateWithCustomSeparator will be "2024/01/15"
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* @param date - The Date object to be formatted.
|
|
148
|
+
* @param format - The desired format for the output string.
|
|
149
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
150
|
+
* @returns A string representing the formatted date in the specified format.
|
|
151
|
+
* @throws Will throw an error if the specified format is not supported.
|
|
152
|
+
*/
|
|
153
|
+
function formatDate(date, format, options) {
|
|
154
|
+
switch (format) {
|
|
155
|
+
case "YYYY-MM-DD": return formatYYYYMMDD(date, options);
|
|
156
|
+
case "MM-DD-YYYY": return formatMMDDYYYY(date, options);
|
|
157
|
+
case "DD-MM-YYYY": return formatDDMMYYYY(date, options);
|
|
158
|
+
case "YYYY/MM/DD": return formatYYYYMMDD(date, {
|
|
159
|
+
separator: "/",
|
|
160
|
+
...options
|
|
161
|
+
});
|
|
162
|
+
case "MM/DD/YYYY": return formatMMDDYYYY(date, {
|
|
163
|
+
separator: "/",
|
|
164
|
+
...options
|
|
165
|
+
});
|
|
166
|
+
case "DD/MM/YYYY": return formatDDMMYYYY(date, {
|
|
167
|
+
separator: "/",
|
|
168
|
+
...options
|
|
169
|
+
});
|
|
170
|
+
case "YYYY.MM.DD": return formatYYYYMMDD(date, {
|
|
171
|
+
separator: ".",
|
|
172
|
+
...options
|
|
173
|
+
});
|
|
174
|
+
case "MM.DD.YYYY": return formatMMDDYYYY(date, {
|
|
175
|
+
separator: ".",
|
|
176
|
+
...options
|
|
177
|
+
});
|
|
178
|
+
case "DD.MM.YYYY": return formatDDMMYYYY(date, {
|
|
179
|
+
separator: ".",
|
|
180
|
+
...options
|
|
181
|
+
});
|
|
182
|
+
case "YYYYMMDD": return formatYYYYMMDD(date, {
|
|
183
|
+
separator: "",
|
|
184
|
+
...options
|
|
185
|
+
});
|
|
186
|
+
case "MMDDYYYY": return formatMMDDYYYY(date, {
|
|
187
|
+
separator: "",
|
|
188
|
+
...options
|
|
189
|
+
});
|
|
190
|
+
case "DDMMYYYY": return formatDDMMYYYY(date, {
|
|
191
|
+
separator: "",
|
|
192
|
+
...options
|
|
193
|
+
});
|
|
194
|
+
case "YYYY-MM-DD HH:mm:ss": return formatYYYYMMDDHHmmss(date, options);
|
|
195
|
+
case "YYYY-MM-DDTHH:mm:ss": return formatYYYYMMDDTHHMMSS(date, options);
|
|
196
|
+
default: throw new Error(`Unsupported date format: ${String(format)}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
exports.formatDDMMYYYY = formatDDMMYYYY;
|
|
202
|
+
exports.formatDate = formatDate;
|
|
203
|
+
exports.formatMMDDYYYY = formatMMDDYYYY;
|
|
204
|
+
exports.formatYYYYMMDD = formatYYYYMMDD;
|
|
205
|
+
exports.formatYYYYMMDDHHmmss = formatYYYYMMDDHHmmss;
|
|
206
|
+
exports.formatYYYYMMDDTHHMMSS = formatYYYYMMDDTHHMMSS;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
//#region src/format.d.ts
|
|
2
|
+
interface FormatDateOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The separator to use between the year, month, and day components of the date.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* This option allows you to specify a custom separator character or string to be used when formatting the date. The default separator is a hyphen ("-").
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
12
|
+
* const formattedDate = formatYYYYMMDD(date, { separator: "/" }); // formattedDate will be "2024/01/15"
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @defaultValue "-"
|
|
16
|
+
*/
|
|
17
|
+
separator?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A utility function that formats a Date object into a string in the format "YYYY-MM-DD".
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* This function takes a Date object as input and returns a string representation of the date in the "YYYY-MM-DD" format.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
28
|
+
* const formattedDate = formatYYYYMMDD(date); // formattedDate will be "2024-01-15"
|
|
29
|
+
* const formattedDateWithCustomSeparator = formatYYYYMMDD(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "2024/01/15"
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param date - The Date object to be formatted.
|
|
33
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
34
|
+
* @returns A string representing the formatted date in "YYYY-MM-DD" format.
|
|
35
|
+
*/
|
|
36
|
+
declare function formatYYYYMMDD(date: Date, options?: FormatDateOptions): string;
|
|
37
|
+
/**
|
|
38
|
+
* A utility function that formats a Date object into a string in the format "MM-DD-YYYY".
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* This function takes a Date object as input and returns a string representation of the date in the "MM-DD-YYYY" format.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
46
|
+
* const formattedDate = formatMMDDYYYY(date); // formattedDate will be "01-15-2024"
|
|
47
|
+
* const formattedDateWithCustomSeparator = formatMMDDYYYY(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "01/15/2024"
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param date - The Date object to be formatted.
|
|
51
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
52
|
+
* @returns A string representing the formatted date in "MM-DD-YYYY" format.
|
|
53
|
+
*/
|
|
54
|
+
declare function formatMMDDYYYY(date: Date, options?: FormatDateOptions): string;
|
|
55
|
+
/**
|
|
56
|
+
* A utility function that formats a Date object into a string in the format "DD-MM-YYYY".
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* This function takes a Date object as input and returns a string representation of the date in the "DD-MM-YYYY" format.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
64
|
+
* const formattedDate = formatDDMMYYYY(date); // formattedDate will be "15-01-2024"
|
|
65
|
+
* const formattedDateWithCustomSeparator = formatDDMMYYYY(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "15/01/2024"
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @param date - The Date object to be formatted.
|
|
69
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
70
|
+
* @returns A string representing the formatted date in "DD-MM-YYYY" format.
|
|
71
|
+
*/
|
|
72
|
+
declare function formatDDMMYYYY(date: Date, options?: FormatDateOptions): string;
|
|
73
|
+
/**
|
|
74
|
+
* A utility function that formats a Date object into a string in the format "YYYY-MM-DD HH:mm:ss".
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* This function formats the date portion using the configured separator and appends
|
|
78
|
+
* a time component in 24-hour format separated by spaces.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const date = new Date(2024, 0, 15, 13, 45, 30);
|
|
83
|
+
* const formattedDate = formatYYYYMMDDHHmmss(date); // formattedDate will be "2024-01-15 13:45:30"
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @param date - The Date object to be formatted.
|
|
87
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
88
|
+
* @returns A string representing the formatted date in "YYYY-MM-DD HH:mm:ss" format.
|
|
89
|
+
*/
|
|
90
|
+
declare function formatYYYYMMDDHHmmss(date: Date, options?: FormatDateOptions): string;
|
|
91
|
+
/**
|
|
92
|
+
* A utility function that formats a Date object into a string in the format "YYYY-MM-DDTHH:mm:ss".
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* This function formats the date portion using the configured separator and appends
|
|
96
|
+
* a time component in 24-hour format separated by a "T" character.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const date = new Date(2024, 0, 15, 13, 45, 30);
|
|
101
|
+
* const formattedDate = formatYYYYMMDDTHHMMSS(date); // formattedDate will be "2024-01-15T13:45:30"
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @param date - The Date object to be formatted.
|
|
105
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
106
|
+
* @returns A string representing the formatted date in "YYYY-MM-DDTHH:mm:ss" format.
|
|
107
|
+
*/
|
|
108
|
+
declare function formatYYYYMMDDTHHMMSS(date: Date, options?: FormatDateOptions): string;
|
|
109
|
+
/**
|
|
110
|
+
* A utility function that formats a Date object into a string based on the specified format.
|
|
111
|
+
*
|
|
112
|
+
* @remarks
|
|
113
|
+
* This function takes a Date object and a format string as input and returns a string representation of the date in the specified format. It also accepts optional configuration for customizing the separator used in the date string.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
118
|
+
* const formattedDate1 = formatDate(date, "YYYY-MM-DD"); // formattedDate1 will be "2024-01-15"
|
|
119
|
+
* const formattedDate2 = formatDate(date, "MM-DD-YYYY"); // formattedDate2 will be "01-15-2024"
|
|
120
|
+
* const formattedDate3 = formatDate(date, "DD-MM-YYYY"); // formattedDate3 will be "15-01-2024"
|
|
121
|
+
* const formattedDate4 = formatDate(date, "YYYYMMDD"); // formattedDate4 will be "20240115"
|
|
122
|
+
* const formattedDate5 = formatDate(date, "YYYY/MM/DD"); // formattedDate5 will be "2024/01/15"
|
|
123
|
+
* const formattedDateWithCustomSeparator = formatDate(date, "YYYY-MM-DD", { separator: "/" }); // formattedDateWithCustomSeparator will be "2024/01/15"
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @param date - The Date object to be formatted.
|
|
127
|
+
* @param format - The desired format for the output string.
|
|
128
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
129
|
+
* @returns A string representing the formatted date in the specified format.
|
|
130
|
+
* @throws Will throw an error if the specified format is not supported.
|
|
131
|
+
*/
|
|
132
|
+
declare function formatDate(date: Date, format: "YYYY-MM-DD" | "MM-DD-YYYY" | "DD-MM-YYYY" | "YYYY/MM/DD" | "MM/DD/YYYY" | "DD/MM/YYYY" | "YYYY.MM.DD" | "MM.DD.YYYY" | "DD.MM.YYYY" | "YYYYMMDD" | "MMDDYYYY" | "DDMMYYYY" | "YYYY-MM-DD HH:mm:ss" | "YYYY-MM-DDTHH:mm:ss", options?: FormatDateOptions): string;
|
|
133
|
+
//#endregion
|
|
134
|
+
export { FormatDateOptions, formatDDMMYYYY, formatDate, formatMMDDYYYY, formatYYYYMMDD, formatYYYYMMDDHHmmss, formatYYYYMMDDTHHMMSS };
|
|
135
|
+
//# sourceMappingURL=format.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.cts","names":[],"sources":["../src/format.ts"],"mappings":";UAoBiB,iBAAA;EAAA;;;;;AAmCjB;;;;;;;;;EApBE,SAAA;AAAA;;;;;;;;;;AA8EF;;;;;;;;iBA1DgB,cAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,iBAAA;;AAqFZ;;;;;;;;;;AAgCA;;;;;;iBA1FgB,cAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,iBAAA;;;;AA8HZ;;;;;;;;;;;;;;iBAnGgB,cAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,iBAAA;;;;;;;;;;;;;;;;;;iBA2BI,oBAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,iBAAA;;;;;;;;;;;;;;;;;;iBA8BI,qBAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;iBAoCI,UAAA,CACd,IAAA,EAAM,IAAA,EACN,MAAA,+NAeA,OAAA,GAAU,iBAAA"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
//#region src/format.d.ts
|
|
2
|
+
interface FormatDateOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The separator to use between the year, month, and day components of the date.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* This option allows you to specify a custom separator character or string to be used when formatting the date. The default separator is a hyphen ("-").
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
12
|
+
* const formattedDate = formatYYYYMMDD(date, { separator: "/" }); // formattedDate will be "2024/01/15"
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @defaultValue "-"
|
|
16
|
+
*/
|
|
17
|
+
separator?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A utility function that formats a Date object into a string in the format "YYYY-MM-DD".
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* This function takes a Date object as input and returns a string representation of the date in the "YYYY-MM-DD" format.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
28
|
+
* const formattedDate = formatYYYYMMDD(date); // formattedDate will be "2024-01-15"
|
|
29
|
+
* const formattedDateWithCustomSeparator = formatYYYYMMDD(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "2024/01/15"
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param date - The Date object to be formatted.
|
|
33
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
34
|
+
* @returns A string representing the formatted date in "YYYY-MM-DD" format.
|
|
35
|
+
*/
|
|
36
|
+
declare function formatYYYYMMDD(date: Date, options?: FormatDateOptions): string;
|
|
37
|
+
/**
|
|
38
|
+
* A utility function that formats a Date object into a string in the format "MM-DD-YYYY".
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* This function takes a Date object as input and returns a string representation of the date in the "MM-DD-YYYY" format.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
46
|
+
* const formattedDate = formatMMDDYYYY(date); // formattedDate will be "01-15-2024"
|
|
47
|
+
* const formattedDateWithCustomSeparator = formatMMDDYYYY(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "01/15/2024"
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param date - The Date object to be formatted.
|
|
51
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
52
|
+
* @returns A string representing the formatted date in "MM-DD-YYYY" format.
|
|
53
|
+
*/
|
|
54
|
+
declare function formatMMDDYYYY(date: Date, options?: FormatDateOptions): string;
|
|
55
|
+
/**
|
|
56
|
+
* A utility function that formats a Date object into a string in the format "DD-MM-YYYY".
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* This function takes a Date object as input and returns a string representation of the date in the "DD-MM-YYYY" format.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
64
|
+
* const formattedDate = formatDDMMYYYY(date); // formattedDate will be "15-01-2024"
|
|
65
|
+
* const formattedDateWithCustomSeparator = formatDDMMYYYY(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "15/01/2024"
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @param date - The Date object to be formatted.
|
|
69
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
70
|
+
* @returns A string representing the formatted date in "DD-MM-YYYY" format.
|
|
71
|
+
*/
|
|
72
|
+
declare function formatDDMMYYYY(date: Date, options?: FormatDateOptions): string;
|
|
73
|
+
/**
|
|
74
|
+
* A utility function that formats a Date object into a string in the format "YYYY-MM-DD HH:mm:ss".
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* This function formats the date portion using the configured separator and appends
|
|
78
|
+
* a time component in 24-hour format separated by spaces.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const date = new Date(2024, 0, 15, 13, 45, 30);
|
|
83
|
+
* const formattedDate = formatYYYYMMDDHHmmss(date); // formattedDate will be "2024-01-15 13:45:30"
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @param date - The Date object to be formatted.
|
|
87
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
88
|
+
* @returns A string representing the formatted date in "YYYY-MM-DD HH:mm:ss" format.
|
|
89
|
+
*/
|
|
90
|
+
declare function formatYYYYMMDDHHmmss(date: Date, options?: FormatDateOptions): string;
|
|
91
|
+
/**
|
|
92
|
+
* A utility function that formats a Date object into a string in the format "YYYY-MM-DDTHH:mm:ss".
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* This function formats the date portion using the configured separator and appends
|
|
96
|
+
* a time component in 24-hour format separated by a "T" character.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const date = new Date(2024, 0, 15, 13, 45, 30);
|
|
101
|
+
* const formattedDate = formatYYYYMMDDTHHMMSS(date); // formattedDate will be "2024-01-15T13:45:30"
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @param date - The Date object to be formatted.
|
|
105
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
106
|
+
* @returns A string representing the formatted date in "YYYY-MM-DDTHH:mm:ss" format.
|
|
107
|
+
*/
|
|
108
|
+
declare function formatYYYYMMDDTHHMMSS(date: Date, options?: FormatDateOptions): string;
|
|
109
|
+
/**
|
|
110
|
+
* A utility function that formats a Date object into a string based on the specified format.
|
|
111
|
+
*
|
|
112
|
+
* @remarks
|
|
113
|
+
* This function takes a Date object and a format string as input and returns a string representation of the date in the specified format. It also accepts optional configuration for customizing the separator used in the date string.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const date = new Date(2024, 0, 15); // January 15, 2024
|
|
118
|
+
* const formattedDate1 = formatDate(date, "YYYY-MM-DD"); // formattedDate1 will be "2024-01-15"
|
|
119
|
+
* const formattedDate2 = formatDate(date, "MM-DD-YYYY"); // formattedDate2 will be "01-15-2024"
|
|
120
|
+
* const formattedDate3 = formatDate(date, "DD-MM-YYYY"); // formattedDate3 will be "15-01-2024"
|
|
121
|
+
* const formattedDate4 = formatDate(date, "YYYYMMDD"); // formattedDate4 will be "20240115"
|
|
122
|
+
* const formattedDate5 = formatDate(date, "YYYY/MM/DD"); // formattedDate5 will be "2024/01/15"
|
|
123
|
+
* const formattedDateWithCustomSeparator = formatDate(date, "YYYY-MM-DD", { separator: "/" }); // formattedDateWithCustomSeparator will be "2024/01/15"
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @param date - The Date object to be formatted.
|
|
127
|
+
* @param format - The desired format for the output string.
|
|
128
|
+
* @param options - Optional configuration for formatting the date, including a custom separator.
|
|
129
|
+
* @returns A string representing the formatted date in the specified format.
|
|
130
|
+
* @throws Will throw an error if the specified format is not supported.
|
|
131
|
+
*/
|
|
132
|
+
declare function formatDate(date: Date, format: "YYYY-MM-DD" | "MM-DD-YYYY" | "DD-MM-YYYY" | "YYYY/MM/DD" | "MM/DD/YYYY" | "DD/MM/YYYY" | "YYYY.MM.DD" | "MM.DD.YYYY" | "DD.MM.YYYY" | "YYYYMMDD" | "MMDDYYYY" | "DDMMYYYY" | "YYYY-MM-DD HH:mm:ss" | "YYYY-MM-DDTHH:mm:ss", options?: FormatDateOptions): string;
|
|
133
|
+
//#endregion
|
|
134
|
+
export { FormatDateOptions, formatDDMMYYYY, formatDate, formatMMDDYYYY, formatYYYYMMDD, formatYYYYMMDDHHmmss, formatYYYYMMDDTHHMMSS };
|
|
135
|
+
//# sourceMappingURL=format.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.mts","names":[],"sources":["../src/format.ts"],"mappings":";UAoBiB,iBAAA;EAAA;;;;;AAmCjB;;;;;;;;;EApBE,SAAA;AAAA;;;;;;;;;;AA8EF;;;;;;;;iBA1DgB,cAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,iBAAA;;AAqFZ;;;;;;;;;;AAgCA;;;;;;iBA1FgB,cAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,iBAAA;;;;AA8HZ;;;;;;;;;;;;;;iBAnGgB,cAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,iBAAA;;;;;;;;;;;;;;;;;;iBA2BI,oBAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,iBAAA;;;;;;;;;;;;;;;;;;iBA8BI,qBAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;iBAoCI,UAAA,CACd,IAAA,EAAM,IAAA,EACN,MAAA,+NAeA,OAAA,GAAU,iBAAA"}
|