@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.
@@ -0,0 +1,200 @@
1
+ //#region src/format.ts
2
+ /**
3
+ * A utility function that formats a Date object into a string in the format "YYYY-MM-DD".
4
+ *
5
+ * @remarks
6
+ * This function takes a Date object as input and returns a string representation of the date in the "YYYY-MM-DD" format.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const date = new Date(2024, 0, 15); // January 15, 2024
11
+ * const formattedDate = formatYYYYMMDD(date); // formattedDate will be "2024-01-15"
12
+ * const formattedDateWithCustomSeparator = formatYYYYMMDD(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "2024/01/15"
13
+ * ```
14
+ *
15
+ * @param date - The Date object to be formatted.
16
+ * @param options - Optional configuration for formatting the date, including a custom separator.
17
+ * @returns A string representing the formatted date in "YYYY-MM-DD" format.
18
+ */
19
+ function formatYYYYMMDD(date, options) {
20
+ const year = date.getFullYear();
21
+ const month = String(date.getMonth() + 1).padStart(2, "0");
22
+ const day = String(date.getDate()).padStart(2, "0");
23
+ const separator = options?.separator ?? "-";
24
+ return `${year}${separator}${month}${separator}${day}`;
25
+ }
26
+ /**
27
+ * A utility function that formats a Date object into a string in the format "MM-DD-YYYY".
28
+ *
29
+ * @remarks
30
+ * This function takes a Date object as input and returns a string representation of the date in the "MM-DD-YYYY" format.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const date = new Date(2024, 0, 15); // January 15, 2024
35
+ * const formattedDate = formatMMDDYYYY(date); // formattedDate will be "01-15-2024"
36
+ * const formattedDateWithCustomSeparator = formatMMDDYYYY(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "01/15/2024"
37
+ * ```
38
+ *
39
+ * @param date - The Date object to be formatted.
40
+ * @param options - Optional configuration for formatting the date, including a custom separator.
41
+ * @returns A string representing the formatted date in "MM-DD-YYYY" format.
42
+ */
43
+ function formatMMDDYYYY(date, options) {
44
+ const month = String(date.getMonth() + 1).padStart(2, "0");
45
+ const day = String(date.getDate()).padStart(2, "0");
46
+ const year = date.getFullYear();
47
+ const separator = options?.separator ?? "-";
48
+ return `${month}${separator}${day}${separator}${year}`;
49
+ }
50
+ /**
51
+ * A utility function that formats a Date object into a string in the format "DD-MM-YYYY".
52
+ *
53
+ * @remarks
54
+ * This function takes a Date object as input and returns a string representation of the date in the "DD-MM-YYYY" format.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const date = new Date(2024, 0, 15); // January 15, 2024
59
+ * const formattedDate = formatDDMMYYYY(date); // formattedDate will be "15-01-2024"
60
+ * const formattedDateWithCustomSeparator = formatDDMMYYYY(date, { separator: "/" }); // formattedDateWithCustomSeparator will be "15/01/2024"
61
+ * ```
62
+ *
63
+ * @param date - The Date object to be formatted.
64
+ * @param options - Optional configuration for formatting the date, including a custom separator.
65
+ * @returns A string representing the formatted date in "DD-MM-YYYY" format.
66
+ */
67
+ function formatDDMMYYYY(date, options) {
68
+ const day = String(date.getDate()).padStart(2, "0");
69
+ const month = String(date.getMonth() + 1).padStart(2, "0");
70
+ const year = date.getFullYear();
71
+ const separator = options?.separator ?? "-";
72
+ return `${day}${separator}${month}${separator}${year}`;
73
+ }
74
+ /**
75
+ * A utility function that formats a Date object into a string in the format "YYYY-MM-DD HH:mm:ss".
76
+ *
77
+ * @remarks
78
+ * This function formats the date portion using the configured separator and appends
79
+ * a time component in 24-hour format separated by spaces.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const date = new Date(2024, 0, 15, 13, 45, 30);
84
+ * const formattedDate = formatYYYYMMDDHHmmss(date); // formattedDate will be "2024-01-15 13:45:30"
85
+ * ```
86
+ *
87
+ * @param date - The Date object to be formatted.
88
+ * @param options - Optional configuration for formatting the date, including a custom separator.
89
+ * @returns A string representing the formatted date in "YYYY-MM-DD HH:mm:ss" format.
90
+ */
91
+ function formatYYYYMMDDHHmmss(date, options) {
92
+ const year = date.getFullYear();
93
+ const month = String(date.getMonth() + 1).padStart(2, "0");
94
+ const day = String(date.getDate()).padStart(2, "0");
95
+ const hours = String(date.getHours()).padStart(2, "0");
96
+ const minutes = String(date.getMinutes()).padStart(2, "0");
97
+ const seconds = String(date.getSeconds()).padStart(2, "0");
98
+ const separator = options?.separator ?? "-";
99
+ return `${year}${separator}${month}${separator}${day} ${hours}:${minutes}:${seconds}`;
100
+ }
101
+ /**
102
+ * A utility function that formats a Date object into a string in the format "YYYY-MM-DDTHH:mm:ss".
103
+ *
104
+ * @remarks
105
+ * This function formats the date portion using the configured separator and appends
106
+ * a time component in 24-hour format separated by a "T" character.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const date = new Date(2024, 0, 15, 13, 45, 30);
111
+ * const formattedDate = formatYYYYMMDDTHHMMSS(date); // formattedDate will be "2024-01-15T13:45:30"
112
+ * ```
113
+ *
114
+ * @param date - The Date object to be formatted.
115
+ * @param options - Optional configuration for formatting the date, including a custom separator.
116
+ * @returns A string representing the formatted date in "YYYY-MM-DDTHH:mm:ss" format.
117
+ */
118
+ function formatYYYYMMDDTHHMMSS(date, options) {
119
+ const year = date.getFullYear();
120
+ const month = String(date.getMonth() + 1).padStart(2, "0");
121
+ const day = String(date.getDate()).padStart(2, "0");
122
+ const hours = String(date.getHours()).padStart(2, "0");
123
+ const minutes = String(date.getMinutes()).padStart(2, "0");
124
+ const seconds = String(date.getSeconds()).padStart(2, "0");
125
+ const separator = options?.separator ?? "-";
126
+ return `${year}${separator}${month}${separator}${day}T${hours}:${minutes}:${seconds}`;
127
+ }
128
+ /**
129
+ * A utility function that formats a Date object into a string based on the specified format.
130
+ *
131
+ * @remarks
132
+ * 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.
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * const date = new Date(2024, 0, 15); // January 15, 2024
137
+ * const formattedDate1 = formatDate(date, "YYYY-MM-DD"); // formattedDate1 will be "2024-01-15"
138
+ * const formattedDate2 = formatDate(date, "MM-DD-YYYY"); // formattedDate2 will be "01-15-2024"
139
+ * const formattedDate3 = formatDate(date, "DD-MM-YYYY"); // formattedDate3 will be "15-01-2024"
140
+ * const formattedDate4 = formatDate(date, "YYYYMMDD"); // formattedDate4 will be "20240115"
141
+ * const formattedDate5 = formatDate(date, "YYYY/MM/DD"); // formattedDate5 will be "2024/01/15"
142
+ * const formattedDateWithCustomSeparator = formatDate(date, "YYYY-MM-DD", { separator: "/" }); // formattedDateWithCustomSeparator will be "2024/01/15"
143
+ * ```
144
+ *
145
+ * @param date - The Date object to be formatted.
146
+ * @param format - The desired format for the output string.
147
+ * @param options - Optional configuration for formatting the date, including a custom separator.
148
+ * @returns A string representing the formatted date in the specified format.
149
+ * @throws Will throw an error if the specified format is not supported.
150
+ */
151
+ function formatDate(date, format, options) {
152
+ switch (format) {
153
+ case "YYYY-MM-DD": return formatYYYYMMDD(date, options);
154
+ case "MM-DD-YYYY": return formatMMDDYYYY(date, options);
155
+ case "DD-MM-YYYY": return formatDDMMYYYY(date, options);
156
+ case "YYYY/MM/DD": return formatYYYYMMDD(date, {
157
+ separator: "/",
158
+ ...options
159
+ });
160
+ case "MM/DD/YYYY": return formatMMDDYYYY(date, {
161
+ separator: "/",
162
+ ...options
163
+ });
164
+ case "DD/MM/YYYY": return formatDDMMYYYY(date, {
165
+ separator: "/",
166
+ ...options
167
+ });
168
+ case "YYYY.MM.DD": return formatYYYYMMDD(date, {
169
+ separator: ".",
170
+ ...options
171
+ });
172
+ case "MM.DD.YYYY": return formatMMDDYYYY(date, {
173
+ separator: ".",
174
+ ...options
175
+ });
176
+ case "DD.MM.YYYY": return formatDDMMYYYY(date, {
177
+ separator: ".",
178
+ ...options
179
+ });
180
+ case "YYYYMMDD": return formatYYYYMMDD(date, {
181
+ separator: "",
182
+ ...options
183
+ });
184
+ case "MMDDYYYY": return formatMMDDYYYY(date, {
185
+ separator: "",
186
+ ...options
187
+ });
188
+ case "DDMMYYYY": return formatDDMMYYYY(date, {
189
+ separator: "",
190
+ ...options
191
+ });
192
+ case "YYYY-MM-DD HH:mm:ss": return formatYYYYMMDDHHmmss(date, options);
193
+ case "YYYY-MM-DDTHH:mm:ss": return formatYYYYMMDDTHHMMSS(date, options);
194
+ default: throw new Error(`Unsupported date format: ${String(format)}`);
195
+ }
196
+ }
197
+
198
+ //#endregion
199
+ export { formatDDMMYYYY, formatDate, formatMMDDYYYY, formatYYYYMMDD, formatYYYYMMDDHHmmss, formatYYYYMMDDTHHMMSS };
200
+ //# sourceMappingURL=format.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.mjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n 🗲 Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n// cspell:ignore YYYYMMDDTHHMMSS\n\nexport interface FormatDateOptions {\n /**\n * The separator to use between the year, month, and day components of the date.\n *\n * @remarks\n * 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 (\"-\").\n *\n * @example\n * ```ts\n * const date = new Date(2024, 0, 15); // January 15, 2024\n * const formattedDate = formatYYYYMMDD(date, { separator: \"/\" }); // formattedDate will be \"2024/01/15\"\n * ```\n *\n * @defaultValue \"-\"\n */\n separator?: string;\n}\n\n/**\n * A utility function that formats a Date object into a string in the format \"YYYY-MM-DD\".\n *\n * @remarks\n * This function takes a Date object as input and returns a string representation of the date in the \"YYYY-MM-DD\" format.\n *\n * @example\n * ```ts\n * const date = new Date(2024, 0, 15); // January 15, 2024\n * const formattedDate = formatYYYYMMDD(date); // formattedDate will be \"2024-01-15\"\n * const formattedDateWithCustomSeparator = formatYYYYMMDD(date, { separator: \"/\" }); // formattedDateWithCustomSeparator will be \"2024/01/15\"\n * ```\n *\n * @param date - The Date object to be formatted.\n * @param options - Optional configuration for formatting the date, including a custom separator.\n * @returns A string representing the formatted date in \"YYYY-MM-DD\" format.\n */\nexport function formatYYYYMMDD(\n date: Date,\n options?: FormatDateOptions\n): string {\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const separator = options?.separator ?? \"-\";\n\n return `${year}${separator}${month}${separator}${day}`;\n}\n\n/**\n * A utility function that formats a Date object into a string in the format \"MM-DD-YYYY\".\n *\n * @remarks\n * This function takes a Date object as input and returns a string representation of the date in the \"MM-DD-YYYY\" format.\n *\n * @example\n * ```ts\n * const date = new Date(2024, 0, 15); // January 15, 2024\n * const formattedDate = formatMMDDYYYY(date); // formattedDate will be \"01-15-2024\"\n * const formattedDateWithCustomSeparator = formatMMDDYYYY(date, { separator: \"/\" }); // formattedDateWithCustomSeparator will be \"01/15/2024\"\n * ```\n *\n * @param date - The Date object to be formatted.\n * @param options - Optional configuration for formatting the date, including a custom separator.\n * @returns A string representing the formatted date in \"MM-DD-YYYY\" format.\n */\nexport function formatMMDDYYYY(\n date: Date,\n options?: FormatDateOptions\n): string {\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const year = date.getFullYear();\n const separator = options?.separator ?? \"-\";\n\n return `${month}${separator}${day}${separator}${year}`;\n}\n\n/**\n * A utility function that formats a Date object into a string in the format \"DD-MM-YYYY\".\n *\n * @remarks\n * This function takes a Date object as input and returns a string representation of the date in the \"DD-MM-YYYY\" format.\n *\n * @example\n * ```ts\n * const date = new Date(2024, 0, 15); // January 15, 2024\n * const formattedDate = formatDDMMYYYY(date); // formattedDate will be \"15-01-2024\"\n * const formattedDateWithCustomSeparator = formatDDMMYYYY(date, { separator: \"/\" }); // formattedDateWithCustomSeparator will be \"15/01/2024\"\n * ```\n *\n * @param date - The Date object to be formatted.\n * @param options - Optional configuration for formatting the date, including a custom separator.\n * @returns A string representing the formatted date in \"DD-MM-YYYY\" format.\n */\nexport function formatDDMMYYYY(\n date: Date,\n options?: FormatDateOptions\n): string {\n const day = String(date.getDate()).padStart(2, \"0\");\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const year = date.getFullYear();\n const separator = options?.separator ?? \"-\";\n\n return `${day}${separator}${month}${separator}${year}`;\n}\n\n/**\n * A utility function that formats a Date object into a string in the format \"YYYY-MM-DD HH:mm:ss\".\n *\n * @remarks\n * This function formats the date portion using the configured separator and appends\n * a time component in 24-hour format separated by spaces.\n *\n * @example\n * ```ts\n * const date = new Date(2024, 0, 15, 13, 45, 30);\n * const formattedDate = formatYYYYMMDDHHmmss(date); // formattedDate will be \"2024-01-15 13:45:30\"\n * ```\n *\n * @param date - The Date object to be formatted.\n * @param options - Optional configuration for formatting the date, including a custom separator.\n * @returns A string representing the formatted date in \"YYYY-MM-DD HH:mm:ss\" format.\n */\nexport function formatYYYYMMDDHHmmss(\n date: Date,\n options?: FormatDateOptions\n): string {\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const hours = String(date.getHours()).padStart(2, \"0\");\n const minutes = String(date.getMinutes()).padStart(2, \"0\");\n const seconds = String(date.getSeconds()).padStart(2, \"0\");\n const separator = options?.separator ?? \"-\";\n\n return `${year}${separator}${month}${separator}${day} ${hours}:${minutes}:${seconds}`;\n}\n\n/**\n * A utility function that formats a Date object into a string in the format \"YYYY-MM-DDTHH:mm:ss\".\n *\n * @remarks\n * This function formats the date portion using the configured separator and appends\n * a time component in 24-hour format separated by a \"T\" character.\n *\n * @example\n * ```ts\n * const date = new Date(2024, 0, 15, 13, 45, 30);\n * const formattedDate = formatYYYYMMDDTHHMMSS(date); // formattedDate will be \"2024-01-15T13:45:30\"\n * ```\n *\n * @param date - The Date object to be formatted.\n * @param options - Optional configuration for formatting the date, including a custom separator.\n * @returns A string representing the formatted date in \"YYYY-MM-DDTHH:mm:ss\" format.\n */\nexport function formatYYYYMMDDTHHMMSS(\n date: Date,\n options?: FormatDateOptions\n): string {\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const hours = String(date.getHours()).padStart(2, \"0\");\n const minutes = String(date.getMinutes()).padStart(2, \"0\");\n const seconds = String(date.getSeconds()).padStart(2, \"0\");\n const separator = options?.separator ?? \"-\";\n\n return `${year}${separator}${month}${separator}${day}T${hours}:${minutes}:${seconds}`;\n}\n\n/**\n * A utility function that formats a Date object into a string based on the specified format.\n *\n * @remarks\n * 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.\n *\n * @example\n * ```ts\n * const date = new Date(2024, 0, 15); // January 15, 2024\n * const formattedDate1 = formatDate(date, \"YYYY-MM-DD\"); // formattedDate1 will be \"2024-01-15\"\n * const formattedDate2 = formatDate(date, \"MM-DD-YYYY\"); // formattedDate2 will be \"01-15-2024\"\n * const formattedDate3 = formatDate(date, \"DD-MM-YYYY\"); // formattedDate3 will be \"15-01-2024\"\n * const formattedDate4 = formatDate(date, \"YYYYMMDD\"); // formattedDate4 will be \"20240115\"\n * const formattedDate5 = formatDate(date, \"YYYY/MM/DD\"); // formattedDate5 will be \"2024/01/15\"\n * const formattedDateWithCustomSeparator = formatDate(date, \"YYYY-MM-DD\", { separator: \"/\" }); // formattedDateWithCustomSeparator will be \"2024/01/15\"\n * ```\n *\n * @param date - The Date object to be formatted.\n * @param format - The desired format for the output string.\n * @param options - Optional configuration for formatting the date, including a custom separator.\n * @returns A string representing the formatted date in the specified format.\n * @throws Will throw an error if the specified format is not supported.\n */\nexport function formatDate(\n date: Date,\n format:\n | \"YYYY-MM-DD\"\n | \"MM-DD-YYYY\"\n | \"DD-MM-YYYY\"\n | \"YYYY/MM/DD\"\n | \"MM/DD/YYYY\"\n | \"DD/MM/YYYY\"\n | \"YYYY.MM.DD\"\n | \"MM.DD.YYYY\"\n | \"DD.MM.YYYY\"\n | \"YYYYMMDD\"\n | \"MMDDYYYY\"\n | \"DDMMYYYY\"\n | \"YYYY-MM-DD HH:mm:ss\"\n | \"YYYY-MM-DDTHH:mm:ss\",\n options?: FormatDateOptions\n): string {\n switch (format) {\n case \"YYYY-MM-DD\":\n return formatYYYYMMDD(date, options);\n case \"MM-DD-YYYY\":\n return formatMMDDYYYY(date, options);\n case \"DD-MM-YYYY\":\n return formatDDMMYYYY(date, options);\n case \"YYYY/MM/DD\":\n return formatYYYYMMDD(date, { separator: \"/\", ...options });\n case \"MM/DD/YYYY\":\n return formatMMDDYYYY(date, { separator: \"/\", ...options });\n case \"DD/MM/YYYY\":\n return formatDDMMYYYY(date, { separator: \"/\", ...options });\n case \"YYYY.MM.DD\":\n return formatYYYYMMDD(date, { separator: \".\", ...options });\n case \"MM.DD.YYYY\":\n return formatMMDDYYYY(date, { separator: \".\", ...options });\n case \"DD.MM.YYYY\":\n return formatDDMMYYYY(date, { separator: \".\", ...options });\n case \"YYYYMMDD\":\n return formatYYYYMMDD(date, { separator: \"\", ...options });\n case \"MMDDYYYY\":\n return formatMMDDYYYY(date, { separator: \"\", ...options });\n case \"DDMMYYYY\":\n return formatDDMMYYYY(date, { separator: \"\", ...options });\n case \"YYYY-MM-DD HH:mm:ss\":\n return formatYYYYMMDDHHmmss(date, options);\n case \"YYYY-MM-DDTHH:mm:ss\":\n return formatYYYYMMDDTHHMMSS(date, options);\n default:\n throw new Error(`Unsupported date format: ${String(format)}`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuDA,SAAgB,eACd,MACA,SACQ;CACR,MAAM,OAAO,KAAK,aAAa;CAC/B,MAAM,QAAQ,OAAO,KAAK,UAAU,GAAG,EAAE,CAAC,SAAS,GAAG,IAAI;CAC1D,MAAM,MAAM,OAAO,KAAK,SAAS,CAAC,CAAC,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AAS,CAAC;EAC5D,KAAK,WACH,QAAO,eAAe,MAAM;GAAE,WAAW;GAAI,GAAG;GAAS,CAAC;EAC5D,KAAK,WACH,QAAO,eAAe,MAAM;GAAE,WAAW;GAAI,GAAG;GAAS,CAAC;EAC5D,KAAK,sBACH,QAAO,qBAAqB,MAAM,QAAQ;EAC5C,KAAK,sBACH,QAAO,sBAAsB,MAAM,QAAQ;EAC7C,QACE,OAAM,IAAI,MAAM,4BAA4B,OAAO,OAAO,GAAG"}
package/dist/index.cjs ADDED
@@ -0,0 +1,12 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_format = require('./format.cjs');
3
+ const require_validate = require('./validate.cjs');
4
+
5
+ exports.formatDDMMYYYY = require_format.formatDDMMYYYY;
6
+ exports.formatDate = require_format.formatDate;
7
+ exports.formatMMDDYYYY = require_format.formatMMDDYYYY;
8
+ exports.formatYYYYMMDD = require_format.formatYYYYMMDD;
9
+ exports.formatYYYYMMDDHHmmss = require_format.formatYYYYMMDDHHmmss;
10
+ exports.formatYYYYMMDDTHHMMSS = require_format.formatYYYYMMDDTHHMMSS;
11
+ exports.isValidDateString = require_validate.isValidDateString;
12
+ exports.isValidTimestamp = require_validate.isValidTimestamp;
@@ -0,0 +1,3 @@
1
+ import { FormatDateOptions, formatDDMMYYYY, formatDate, formatMMDDYYYY, formatYYYYMMDD, formatYYYYMMDDHHmmss, formatYYYYMMDDTHHMMSS } from "./format.cjs";
2
+ import { isValidDateString, isValidTimestamp } from "./validate.cjs";
3
+ export { FormatDateOptions, formatDDMMYYYY, formatDate, formatMMDDYYYY, formatYYYYMMDD, formatYYYYMMDDHHmmss, formatYYYYMMDDTHHMMSS, isValidDateString, isValidTimestamp };
@@ -0,0 +1,3 @@
1
+ import { FormatDateOptions, formatDDMMYYYY, formatDate, formatMMDDYYYY, formatYYYYMMDD, formatYYYYMMDDHHmmss, formatYYYYMMDDTHHMMSS } from "./format.mjs";
2
+ import { isValidDateString, isValidTimestamp } from "./validate.mjs";
3
+ export { FormatDateOptions, formatDDMMYYYY, formatDate, formatMMDDYYYY, formatYYYYMMDD, formatYYYYMMDDHHmmss, formatYYYYMMDDTHHMMSS, isValidDateString, isValidTimestamp };
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import { formatDDMMYYYY, formatDate, formatMMDDYYYY, formatYYYYMMDD, formatYYYYMMDDHHmmss, formatYYYYMMDDTHHMMSS } from "./format.mjs";
2
+ import { isValidDateString, isValidTimestamp } from "./validate.mjs";
3
+
4
+ export { formatDDMMYYYY, formatDate, formatMMDDYYYY, formatYYYYMMDD, formatYYYYMMDDHHmmss, formatYYYYMMDDTHHMMSS, isValidDateString, isValidTimestamp };
@@ -0,0 +1,44 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/validate.ts
4
+ /**
5
+ * Validates if a given timestamp is a valid Unix timestamp.
6
+ *
7
+ * @remarks
8
+ * A valid Unix timestamp is a non-negative integer that represents the number of seconds since January 1, 1970 (the Unix epoch).
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * isValidTimestamp(1700000000); // true
13
+ * isValidTimestamp(-100); // false
14
+ * isValidTimestamp(3.14); // false
15
+ * ```
16
+ *
17
+ * @param timestamp - The timestamp to validate.
18
+ * @returns `true` if the timestamp is valid, `false` otherwise.
19
+ */
20
+ function isValidTimestamp(timestamp) {
21
+ return Number.isInteger(timestamp) && timestamp >= 0;
22
+ }
23
+ /**
24
+ * Validates if a given date string is a valid date.
25
+ *
26
+ * @remarks
27
+ * A valid date string is one that can be parsed into a valid JavaScript `Date` object.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * isValidDateString("2024-01-15"); // true
32
+ * isValidDateString("invalid-date"); // false
33
+ * ```
34
+ *
35
+ * @param date - The date string to validate.
36
+ * @returns `true` if the date string is valid, `false` otherwise.
37
+ */
38
+ function isValidDateString(date) {
39
+ return !Number.isNaN(new Date(date).getTime());
40
+ }
41
+
42
+ //#endregion
43
+ exports.isValidDateString = isValidDateString;
44
+ exports.isValidTimestamp = isValidTimestamp;
@@ -0,0 +1,37 @@
1
+ //#region src/validate.d.ts
2
+ /**
3
+ * Validates if a given timestamp is a valid Unix timestamp.
4
+ *
5
+ * @remarks
6
+ * A valid Unix timestamp is a non-negative integer that represents the number of seconds since January 1, 1970 (the Unix epoch).
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isValidTimestamp(1700000000); // true
11
+ * isValidTimestamp(-100); // false
12
+ * isValidTimestamp(3.14); // false
13
+ * ```
14
+ *
15
+ * @param timestamp - The timestamp to validate.
16
+ * @returns `true` if the timestamp is valid, `false` otherwise.
17
+ */
18
+ declare function isValidTimestamp(timestamp: number): boolean;
19
+ /**
20
+ * Validates if a given date string is a valid date.
21
+ *
22
+ * @remarks
23
+ * A valid date string is one that can be parsed into a valid JavaScript `Date` object.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * isValidDateString("2024-01-15"); // true
28
+ * isValidDateString("invalid-date"); // false
29
+ * ```
30
+ *
31
+ * @param date - The date string to validate.
32
+ * @returns `true` if the date string is valid, `false` otherwise.
33
+ */
34
+ declare function isValidDateString(date: string): boolean;
35
+ //#endregion
36
+ export { isValidDateString, isValidTimestamp };
37
+ //# sourceMappingURL=validate.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.cts","names":[],"sources":["../src/validate.ts"],"mappings":";;AAkCA;;;;;AAmBA;;;;;;;;;;iBAnBgB,gBAAA,CAAiB,SAAA;;;;;;;;;;;;;;;;iBAmBjB,iBAAA,CAAkB,IAAA"}
@@ -0,0 +1,37 @@
1
+ //#region src/validate.d.ts
2
+ /**
3
+ * Validates if a given timestamp is a valid Unix timestamp.
4
+ *
5
+ * @remarks
6
+ * A valid Unix timestamp is a non-negative integer that represents the number of seconds since January 1, 1970 (the Unix epoch).
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isValidTimestamp(1700000000); // true
11
+ * isValidTimestamp(-100); // false
12
+ * isValidTimestamp(3.14); // false
13
+ * ```
14
+ *
15
+ * @param timestamp - The timestamp to validate.
16
+ * @returns `true` if the timestamp is valid, `false` otherwise.
17
+ */
18
+ declare function isValidTimestamp(timestamp: number): boolean;
19
+ /**
20
+ * Validates if a given date string is a valid date.
21
+ *
22
+ * @remarks
23
+ * A valid date string is one that can be parsed into a valid JavaScript `Date` object.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * isValidDateString("2024-01-15"); // true
28
+ * isValidDateString("invalid-date"); // false
29
+ * ```
30
+ *
31
+ * @param date - The date string to validate.
32
+ * @returns `true` if the date string is valid, `false` otherwise.
33
+ */
34
+ declare function isValidDateString(date: string): boolean;
35
+ //#endregion
36
+ export { isValidDateString, isValidTimestamp };
37
+ //# sourceMappingURL=validate.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.mts","names":[],"sources":["../src/validate.ts"],"mappings":";;AAkCA;;;;;AAmBA;;;;;;;;;;iBAnBgB,gBAAA,CAAiB,SAAA;;;;;;;;;;;;;;;;iBAmBjB,iBAAA,CAAkB,IAAA"}
@@ -0,0 +1,42 @@
1
+ //#region src/validate.ts
2
+ /**
3
+ * Validates if a given timestamp is a valid Unix timestamp.
4
+ *
5
+ * @remarks
6
+ * A valid Unix timestamp is a non-negative integer that represents the number of seconds since January 1, 1970 (the Unix epoch).
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isValidTimestamp(1700000000); // true
11
+ * isValidTimestamp(-100); // false
12
+ * isValidTimestamp(3.14); // false
13
+ * ```
14
+ *
15
+ * @param timestamp - The timestamp to validate.
16
+ * @returns `true` if the timestamp is valid, `false` otherwise.
17
+ */
18
+ function isValidTimestamp(timestamp) {
19
+ return Number.isInteger(timestamp) && timestamp >= 0;
20
+ }
21
+ /**
22
+ * Validates if a given date string is a valid date.
23
+ *
24
+ * @remarks
25
+ * A valid date string is one that can be parsed into a valid JavaScript `Date` object.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * isValidDateString("2024-01-15"); // true
30
+ * isValidDateString("invalid-date"); // false
31
+ * ```
32
+ *
33
+ * @param date - The date string to validate.
34
+ * @returns `true` if the date string is valid, `false` otherwise.
35
+ */
36
+ function isValidDateString(date) {
37
+ return !Number.isNaN(new Date(date).getTime());
38
+ }
39
+
40
+ //#endregion
41
+ export { isValidDateString, isValidTimestamp };
42
+ //# sourceMappingURL=validate.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.mjs","names":[],"sources":["../src/validate.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n 🗲 Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Validates if a given timestamp is a valid Unix timestamp.\n *\n * @remarks\n * A valid Unix timestamp is a non-negative integer that represents the number of seconds since January 1, 1970 (the Unix epoch).\n *\n * @example\n * ```ts\n * isValidTimestamp(1700000000); // true\n * isValidTimestamp(-100); // false\n * isValidTimestamp(3.14); // false\n * ```\n *\n * @param timestamp - The timestamp to validate.\n * @returns `true` if the timestamp is valid, `false` otherwise.\n */\nexport function isValidTimestamp(timestamp: number): boolean {\n return Number.isInteger(timestamp) && timestamp >= 0;\n}\n\n/**\n * Validates if a given date string is a valid date.\n *\n * @remarks\n * A valid date string is one that can be parsed into a valid JavaScript `Date` object.\n *\n * @example\n * ```ts\n * isValidDateString(\"2024-01-15\"); // true\n * isValidDateString(\"invalid-date\"); // false\n * ```\n *\n * @param date - The date string to validate.\n * @returns `true` if the date string is valid, `false` otherwise.\n */\nexport function isValidDateString(date: string): boolean {\n return !Number.isNaN(new Date(date).getTime());\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkCA,SAAgB,iBAAiB,WAA4B;AAC3D,QAAO,OAAO,UAAU,UAAU,IAAI,aAAa;;;;;;;;;;;;;;;;;AAkBrD,SAAgB,kBAAkB,MAAuB;AACvD,QAAO,CAAC,OAAO,MAAM,IAAI,KAAK,KAAK,CAAC,SAAS,CAAC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@stryke/date",
3
+ "version": "0.0.2",
4
+ "private": false,
5
+ "description": "A utility package that helps with date manipulation and formatting.",
6
+ "repository": {
7
+ "type": "github",
8
+ "url": "https://github.com/storm-software/stryke.git",
9
+ "directory": "packages/date"
10
+ },
11
+ "type": "module",
12
+ "exports": {
13
+ ".": { "import": "./dist/index.mjs", "require": "./dist/index.cjs" },
14
+ "./format": {
15
+ "import": "./dist/format.mjs",
16
+ "require": "./dist/format.cjs"
17
+ },
18
+ "./validate": {
19
+ "import": "./dist/validate.mjs",
20
+ "require": "./dist/validate.cjs"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "main": "./dist/index.cjs",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/index.d.cts",
27
+ "devDependencies": { "@types/node": "^24.13.2", "tsdown": "^0.21.10" },
28
+ "publishConfig": { "access": "public" },
29
+ "gitHead": "3dcaa5327786a7939dba470d7cc24d773d2a95f5"
30
+ }