superjs-core 0.1.0
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/dist/async/index.d.ts +44 -0
- package/dist/async/index.js +88 -0
- package/dist/async/index.js.map +1 -0
- package/dist/collection/index.d.ts +75 -0
- package/dist/collection/index.js +140 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/core/index.d.ts +95 -0
- package/dist/core/index.js +272 -0
- package/dist/core/index.js.map +1 -0
- package/dist/crypto/index.d.ts +78 -0
- package/dist/crypto/index.js +147 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/date/index.d.ts +203 -0
- package/dist/date/index.js +282 -0
- package/dist/date/index.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1505 -0
- package/dist/index.js.map +1 -0
- package/dist/io/index.d.ts +39 -0
- package/dist/io/index.js +110 -0
- package/dist/io/index.js.map +1 -0
- package/dist/math/index.d.ts +117 -0
- package/dist/math/index.js +104 -0
- package/dist/math/index.js.map +1 -0
- package/dist/path/index.d.ts +81 -0
- package/dist/path/index.js +134 -0
- package/dist/path/index.js.map +1 -0
- package/dist/string/index.d.ts +91 -0
- package/dist/string/index.js +146 -0
- package/dist/string/index.js.map +1 -0
- package/dist/type/index.d.ts +87 -0
- package/dist/type/index.js +109 -0
- package/dist/type/index.js.map +1 -0
- package/package.json +103 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when a date value is invalid.
|
|
3
|
+
*/
|
|
4
|
+
declare class InvalidDateError extends Error {
|
|
5
|
+
constructor(input: unknown);
|
|
6
|
+
}
|
|
7
|
+
interface DateDiff {
|
|
8
|
+
years: number;
|
|
9
|
+
months: number;
|
|
10
|
+
days: number;
|
|
11
|
+
hours: number;
|
|
12
|
+
minutes: number;
|
|
13
|
+
seconds: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Formats a Date to a string using the given format pattern.
|
|
17
|
+
*
|
|
18
|
+
* Supported tokens:
|
|
19
|
+
* - `YYYY` — 4-digit year
|
|
20
|
+
* - `YY` — 2-digit year
|
|
21
|
+
* - `MMMM` — full month name
|
|
22
|
+
* - `MMM` — abbreviated month name
|
|
23
|
+
* - `MM` — 2-digit month (01–12)
|
|
24
|
+
* - `DD` — 2-digit day (01–31)
|
|
25
|
+
* - `HH` — 2-digit hours (00–23)
|
|
26
|
+
* - `mm` — 2-digit minutes
|
|
27
|
+
* - `ss` — 2-digit seconds
|
|
28
|
+
* - `SSS` — milliseconds
|
|
29
|
+
*
|
|
30
|
+
* @param date - The date to format.
|
|
31
|
+
* @param format - The format string (default `'YYYY-MM-DD'`).
|
|
32
|
+
* @returns The formatted date string.
|
|
33
|
+
*/
|
|
34
|
+
declare function formatDate(date: Date, format?: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Parses a date from a string, number (timestamp in ms), or Date object.
|
|
37
|
+
*
|
|
38
|
+
* Supported string formats:
|
|
39
|
+
* - ISO (`YYYY-MM-DD`, `YYYY-MM-DDTHH:mm:ss`)
|
|
40
|
+
* - `DD/MM/YYYY` or `DD-MM-YYYY`
|
|
41
|
+
* - `DD MMM YYYY` or `DD MMMM YYYY`
|
|
42
|
+
* - Unix timestamp (milliseconds)
|
|
43
|
+
*
|
|
44
|
+
* @param input - The value to parse.
|
|
45
|
+
* @returns A valid Date object.
|
|
46
|
+
* @throws {InvalidDateError} If the input cannot be parsed.
|
|
47
|
+
*/
|
|
48
|
+
declare function parseDate(input: string | number | Date): Date;
|
|
49
|
+
/**
|
|
50
|
+
* Computes the difference between two dates.
|
|
51
|
+
*
|
|
52
|
+
* @param date1 - Start date.
|
|
53
|
+
* @param date2 - End date.
|
|
54
|
+
* @returns An object with years, months, days, hours, minutes, seconds.
|
|
55
|
+
* @throws {InvalidDateError} If either date is invalid.
|
|
56
|
+
*/
|
|
57
|
+
declare function dateDiff(date1: Date, date2: Date): DateDiff;
|
|
58
|
+
/**
|
|
59
|
+
* Adds days to a date.
|
|
60
|
+
*
|
|
61
|
+
* @param date - The original date.
|
|
62
|
+
* @param days - Number of days to add (negative to subtract).
|
|
63
|
+
* @returns A new Date.
|
|
64
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
65
|
+
*/
|
|
66
|
+
declare function addDays(date: Date, days: number): Date;
|
|
67
|
+
/**
|
|
68
|
+
* Adds months to a date. Handles month-end overflow (e.g., Jan 31 + 1 month
|
|
69
|
+
* becomes Feb 28).
|
|
70
|
+
*
|
|
71
|
+
* @param date - The original date.
|
|
72
|
+
* @param months - Number of months to add (negative to subtract).
|
|
73
|
+
* @returns A new Date.
|
|
74
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
75
|
+
*/
|
|
76
|
+
declare function addMonths(date: Date, months: number): Date;
|
|
77
|
+
/**
|
|
78
|
+
* Adds years to a date. Handles leap-year overflow (e.g., Feb 29 + 1 year
|
|
79
|
+
* becomes Feb 28).
|
|
80
|
+
*
|
|
81
|
+
* @param date - The original date.
|
|
82
|
+
* @param years - Number of years to add (negative to subtract).
|
|
83
|
+
* @returns A new Date.
|
|
84
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
85
|
+
*/
|
|
86
|
+
declare function addYears(date: Date, years: number): Date;
|
|
87
|
+
/**
|
|
88
|
+
* Returns the start of the day (00:00:00.000) for the given date.
|
|
89
|
+
*
|
|
90
|
+
* @param date - The date.
|
|
91
|
+
* @returns A new Date set to midnight.
|
|
92
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
93
|
+
*/
|
|
94
|
+
declare function startOfDay(date: Date): Date;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the end of the day (23:59:59.999) for the given date.
|
|
97
|
+
*
|
|
98
|
+
* @param date - The date.
|
|
99
|
+
* @returns A new Date set to the last millisecond of the day.
|
|
100
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
101
|
+
*/
|
|
102
|
+
declare function endOfDay(date: Date): Date;
|
|
103
|
+
/**
|
|
104
|
+
* Returns the first moment of the month for the given date.
|
|
105
|
+
*
|
|
106
|
+
* @param date - The date.
|
|
107
|
+
* @returns A new Date set to the start of the month.
|
|
108
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
109
|
+
*/
|
|
110
|
+
declare function startOfMonth(date: Date): Date;
|
|
111
|
+
/**
|
|
112
|
+
* Returns the last moment of the month for the given date.
|
|
113
|
+
*
|
|
114
|
+
* @param date - The date.
|
|
115
|
+
* @returns A new Date set to the end of the month.
|
|
116
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
117
|
+
*/
|
|
118
|
+
declare function endOfMonth(date: Date): Date;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the first moment of the year for the given date.
|
|
121
|
+
*
|
|
122
|
+
* @param date - The date.
|
|
123
|
+
* @returns A new Date set to Jan 1 00:00:00.000.
|
|
124
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
125
|
+
*/
|
|
126
|
+
declare function startOfYear(date: Date): Date;
|
|
127
|
+
/**
|
|
128
|
+
* Returns the last moment of the year for the given date.
|
|
129
|
+
*
|
|
130
|
+
* @param date - The date.
|
|
131
|
+
* @returns A new Date set to Dec 31 23:59:59.999.
|
|
132
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
133
|
+
*/
|
|
134
|
+
declare function endOfYear(date: Date): Date;
|
|
135
|
+
/**
|
|
136
|
+
* Checks if the date falls on a weekend (Saturday or Sunday).
|
|
137
|
+
*
|
|
138
|
+
* @param date - The date to check.
|
|
139
|
+
* @returns Whether the date is a weekend.
|
|
140
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
141
|
+
*/
|
|
142
|
+
declare function isWeekend(date: Date): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Checks if a year is a leap year.
|
|
145
|
+
*
|
|
146
|
+
* @param year - The year to check.
|
|
147
|
+
* @returns Whether the year is a leap year.
|
|
148
|
+
*/
|
|
149
|
+
declare function isLeapYear(year: number): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Checks if `date1` is before `date2`.
|
|
152
|
+
*
|
|
153
|
+
* @param date1 - First date.
|
|
154
|
+
* @param date2 - Second date.
|
|
155
|
+
* @returns Whether `date1` is before `date2`.
|
|
156
|
+
* @throws {InvalidDateError} If either date is invalid.
|
|
157
|
+
*/
|
|
158
|
+
declare function isBefore(date1: Date, date2: Date): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Checks if `date1` is after `date2`.
|
|
161
|
+
*
|
|
162
|
+
* @param date1 - First date.
|
|
163
|
+
* @param date2 - Second date.
|
|
164
|
+
* @returns Whether `date1` is after `date2`.
|
|
165
|
+
* @throws {InvalidDateError} If either date is invalid.
|
|
166
|
+
*/
|
|
167
|
+
declare function isAfter(date1: Date, date2: Date): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Checks if a date is within the inclusive range [start, end].
|
|
170
|
+
*
|
|
171
|
+
* @param date - The date to check.
|
|
172
|
+
* @param start - Start of the range.
|
|
173
|
+
* @param end - End of the range.
|
|
174
|
+
* @returns Whether the date is between start and end.
|
|
175
|
+
* @throws {InvalidDateError} If any date is invalid.
|
|
176
|
+
*/
|
|
177
|
+
declare function isBetween(date: Date, start: Date, end: Date): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Checks if a date is a business day (Monday to Friday).
|
|
180
|
+
*
|
|
181
|
+
* @param date - The date to check.
|
|
182
|
+
* @returns Whether the date is a business day.
|
|
183
|
+
*/
|
|
184
|
+
declare function isBusinessDay(date: Date): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Adds business days (skipping weekends) to a date.
|
|
187
|
+
*
|
|
188
|
+
* @param date - The starting date.
|
|
189
|
+
* @param days - Number of business days to add (negative to subtract).
|
|
190
|
+
* @returns A new Date.
|
|
191
|
+
* @throws {InvalidDateError} If the input date is invalid.
|
|
192
|
+
*/
|
|
193
|
+
declare function addBusinessDays(date: Date, days: number): Date;
|
|
194
|
+
/**
|
|
195
|
+
* Calculates age in years from a birth date.
|
|
196
|
+
*
|
|
197
|
+
* @param birthDate - The date of birth.
|
|
198
|
+
* @returns The age in years.
|
|
199
|
+
* @throws {InvalidDateError} If the birth date is invalid.
|
|
200
|
+
*/
|
|
201
|
+
declare function calculateAge(birthDate: Date): number;
|
|
202
|
+
|
|
203
|
+
export { type DateDiff, InvalidDateError, addBusinessDays, addDays, addMonths, addYears, calculateAge, dateDiff, endOfDay, endOfMonth, endOfYear, formatDate, isAfter, isBefore, isBetween, isBusinessDay, isLeapYear, isWeekend, parseDate, startOfDay, startOfMonth, startOfYear };
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// src/date/index.ts
|
|
2
|
+
var InvalidDateError = class extends Error {
|
|
3
|
+
constructor(input) {
|
|
4
|
+
super(`Invalid date: ${String(input)}`);
|
|
5
|
+
this.name = "InvalidDateError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var MONTH_NAMES_SHORT = [
|
|
9
|
+
"Jan",
|
|
10
|
+
"Feb",
|
|
11
|
+
"Mar",
|
|
12
|
+
"Apr",
|
|
13
|
+
"May",
|
|
14
|
+
"Jun",
|
|
15
|
+
"Jul",
|
|
16
|
+
"Aug",
|
|
17
|
+
"Sep",
|
|
18
|
+
"Oct",
|
|
19
|
+
"Nov",
|
|
20
|
+
"Dec"
|
|
21
|
+
];
|
|
22
|
+
var MONTH_NAMES_FULL = [
|
|
23
|
+
"January",
|
|
24
|
+
"February",
|
|
25
|
+
"March",
|
|
26
|
+
"April",
|
|
27
|
+
"May",
|
|
28
|
+
"June",
|
|
29
|
+
"July",
|
|
30
|
+
"August",
|
|
31
|
+
"September",
|
|
32
|
+
"October",
|
|
33
|
+
"November",
|
|
34
|
+
"December"
|
|
35
|
+
];
|
|
36
|
+
var MONTH_MAP = {
|
|
37
|
+
jan: 0,
|
|
38
|
+
january: 0,
|
|
39
|
+
feb: 1,
|
|
40
|
+
february: 1,
|
|
41
|
+
mar: 2,
|
|
42
|
+
march: 2,
|
|
43
|
+
apr: 3,
|
|
44
|
+
april: 3,
|
|
45
|
+
may: 4,
|
|
46
|
+
jun: 5,
|
|
47
|
+
june: 5,
|
|
48
|
+
jul: 6,
|
|
49
|
+
july: 6,
|
|
50
|
+
aug: 7,
|
|
51
|
+
august: 7,
|
|
52
|
+
sep: 8,
|
|
53
|
+
september: 8,
|
|
54
|
+
oct: 9,
|
|
55
|
+
october: 9,
|
|
56
|
+
nov: 10,
|
|
57
|
+
november: 10,
|
|
58
|
+
dec: 11,
|
|
59
|
+
december: 11
|
|
60
|
+
};
|
|
61
|
+
function formatDate(date, format = "YYYY-MM-DD") {
|
|
62
|
+
const year = date.getFullYear();
|
|
63
|
+
const month = date.getMonth();
|
|
64
|
+
const day = date.getDate();
|
|
65
|
+
const hours = date.getHours();
|
|
66
|
+
const minutes = date.getMinutes();
|
|
67
|
+
const seconds = date.getSeconds();
|
|
68
|
+
const ms = date.getMilliseconds();
|
|
69
|
+
const pad = (n, len = 2) => String(n).padStart(len, "0");
|
|
70
|
+
return format.replace(/YYYY/g, String(year)).replace(/YY/g, String(year).slice(-2)).replace(/MMMM/g, MONTH_NAMES_FULL[month]).replace(/MMM/g, MONTH_NAMES_SHORT[month]).replace(/MM/g, pad(month + 1)).replace(/DD/g, pad(day)).replace(/HH/g, pad(hours)).replace(/mm/g, pad(minutes)).replace(/ss/g, pad(seconds)).replace(/SSS/g, pad(ms, 3));
|
|
71
|
+
}
|
|
72
|
+
function parseDate(input) {
|
|
73
|
+
if (input instanceof Date) {
|
|
74
|
+
if (isNaN(input.getTime())) throw new InvalidDateError(input);
|
|
75
|
+
return new Date(input.getTime());
|
|
76
|
+
}
|
|
77
|
+
if (typeof input === "number") {
|
|
78
|
+
const d = new Date(input);
|
|
79
|
+
if (isNaN(d.getTime())) throw new InvalidDateError(input);
|
|
80
|
+
return d;
|
|
81
|
+
}
|
|
82
|
+
const trimmed = input.trim();
|
|
83
|
+
const isoMatch = trimmed.match(/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?(?:Z|[+-]\d{2}:?\d{2})?$/);
|
|
84
|
+
if (isoMatch) {
|
|
85
|
+
const d = new Date(
|
|
86
|
+
parseInt(isoMatch[1], 10),
|
|
87
|
+
parseInt(isoMatch[2], 10) - 1,
|
|
88
|
+
parseInt(isoMatch[3], 10),
|
|
89
|
+
isoMatch[4] ? parseInt(isoMatch[4], 10) : 0,
|
|
90
|
+
isoMatch[5] ? parseInt(isoMatch[5], 10) : 0,
|
|
91
|
+
isoMatch[6] ? parseInt(isoMatch[6], 10) : 0,
|
|
92
|
+
isoMatch[7] ? parseInt(isoMatch[7].padEnd(3, "0"), 10) : 0
|
|
93
|
+
);
|
|
94
|
+
if (!isNaN(d.getTime())) return d;
|
|
95
|
+
}
|
|
96
|
+
const dmyMatch = trimmed.match(/^(\d{1,2})[\/-](\d{1,2})[\/-](\d{4})$/);
|
|
97
|
+
if (dmyMatch) {
|
|
98
|
+
const d = new Date(
|
|
99
|
+
parseInt(dmyMatch[3], 10),
|
|
100
|
+
parseInt(dmyMatch[2], 10) - 1,
|
|
101
|
+
parseInt(dmyMatch[1], 10)
|
|
102
|
+
);
|
|
103
|
+
if (!isNaN(d.getTime())) return d;
|
|
104
|
+
}
|
|
105
|
+
const textMatch = trimmed.match(/^(\d{1,2})\s+([a-zA-Z]+)\s+(\d{4})$/);
|
|
106
|
+
if (textMatch) {
|
|
107
|
+
const monthIndex = MONTH_MAP[textMatch[2].toLowerCase()];
|
|
108
|
+
if (monthIndex !== void 0) {
|
|
109
|
+
const d = new Date(
|
|
110
|
+
parseInt(textMatch[3], 10),
|
|
111
|
+
monthIndex,
|
|
112
|
+
parseInt(textMatch[1], 10)
|
|
113
|
+
);
|
|
114
|
+
if (!isNaN(d.getTime())) return d;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const numMatch = trimmed.match(/^-?\d+$/);
|
|
118
|
+
if (numMatch) {
|
|
119
|
+
const d = new Date(parseInt(numMatch[0], 10));
|
|
120
|
+
if (!isNaN(d.getTime())) return d;
|
|
121
|
+
}
|
|
122
|
+
const fallback = new Date(trimmed);
|
|
123
|
+
if (!isNaN(fallback.getTime())) return fallback;
|
|
124
|
+
throw new InvalidDateError(input);
|
|
125
|
+
}
|
|
126
|
+
function isValidDate(d) {
|
|
127
|
+
return d instanceof Date && !isNaN(d.getTime());
|
|
128
|
+
}
|
|
129
|
+
var MS_IN_SECOND = 1e3;
|
|
130
|
+
var MS_IN_MINUTE = 60 * MS_IN_SECOND;
|
|
131
|
+
var MS_IN_HOUR = 60 * MS_IN_MINUTE;
|
|
132
|
+
var MS_IN_DAY = 24 * MS_IN_HOUR;
|
|
133
|
+
function dateDiff(date1, date2) {
|
|
134
|
+
if (!isValidDate(date1) || !isValidDate(date2)) {
|
|
135
|
+
throw new InvalidDateError("Invalid date provided to dateDiff");
|
|
136
|
+
}
|
|
137
|
+
let years = date2.getFullYear() - date1.getFullYear();
|
|
138
|
+
let months = date2.getMonth() - date1.getMonth();
|
|
139
|
+
let days = date2.getDate() - date1.getDate();
|
|
140
|
+
if (days < 0) {
|
|
141
|
+
months -= 1;
|
|
142
|
+
const prevMonth = new Date(date2.getFullYear(), date2.getMonth(), 0);
|
|
143
|
+
days += prevMonth.getDate();
|
|
144
|
+
}
|
|
145
|
+
if (months < 0) {
|
|
146
|
+
years -= 1;
|
|
147
|
+
months += 12;
|
|
148
|
+
}
|
|
149
|
+
const msDiff = Math.abs(date2.getTime() - date1.getTime());
|
|
150
|
+
const totalSeconds = Math.floor(msDiff / MS_IN_SECOND);
|
|
151
|
+
const hours = Math.floor(msDiff % MS_IN_DAY / MS_IN_HOUR);
|
|
152
|
+
const minutes = Math.floor(msDiff % MS_IN_HOUR / MS_IN_MINUTE);
|
|
153
|
+
const seconds = totalSeconds % 60;
|
|
154
|
+
return { years, months, days, hours, minutes, seconds };
|
|
155
|
+
}
|
|
156
|
+
function addDays(date, days) {
|
|
157
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
158
|
+
const result = new Date(date.getTime());
|
|
159
|
+
result.setDate(result.getDate() + days);
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
function addMonths(date, months) {
|
|
163
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
164
|
+
const result = new Date(date.getTime());
|
|
165
|
+
const targetMonth = result.getMonth() + months;
|
|
166
|
+
result.setMonth(targetMonth);
|
|
167
|
+
if (result.getMonth() !== (targetMonth % 12 + 12) % 12) {
|
|
168
|
+
result.setDate(0);
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
function addYears(date, years) {
|
|
173
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
174
|
+
const result = new Date(date.getTime());
|
|
175
|
+
const targetYear = result.getFullYear() + years;
|
|
176
|
+
result.setFullYear(targetYear);
|
|
177
|
+
if (result.getFullYear() !== targetYear) {
|
|
178
|
+
result.setDate(0);
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
function startOfDay(date) {
|
|
183
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
184
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
|
|
185
|
+
}
|
|
186
|
+
function endOfDay(date) {
|
|
187
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
188
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
|
|
189
|
+
}
|
|
190
|
+
function startOfMonth(date) {
|
|
191
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
192
|
+
return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);
|
|
193
|
+
}
|
|
194
|
+
function endOfMonth(date) {
|
|
195
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
196
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0, 23, 59, 59, 999);
|
|
197
|
+
}
|
|
198
|
+
function startOfYear(date) {
|
|
199
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
200
|
+
return new Date(date.getFullYear(), 0, 1, 0, 0, 0, 0);
|
|
201
|
+
}
|
|
202
|
+
function endOfYear(date) {
|
|
203
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
204
|
+
return new Date(date.getFullYear(), 12, 0, 23, 59, 59, 999);
|
|
205
|
+
}
|
|
206
|
+
function isWeekend(date) {
|
|
207
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
208
|
+
const day = date.getDay();
|
|
209
|
+
return day === 0 || day === 6;
|
|
210
|
+
}
|
|
211
|
+
function isLeapYear(year) {
|
|
212
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
213
|
+
}
|
|
214
|
+
function isBefore(date1, date2) {
|
|
215
|
+
if (!isValidDate(date1) || !isValidDate(date2)) {
|
|
216
|
+
throw new InvalidDateError("Invalid date provided to isBefore");
|
|
217
|
+
}
|
|
218
|
+
return date1.getTime() < date2.getTime();
|
|
219
|
+
}
|
|
220
|
+
function isAfter(date1, date2) {
|
|
221
|
+
if (!isValidDate(date1) || !isValidDate(date2)) {
|
|
222
|
+
throw new InvalidDateError("Invalid date provided to isAfter");
|
|
223
|
+
}
|
|
224
|
+
return date1.getTime() > date2.getTime();
|
|
225
|
+
}
|
|
226
|
+
function isBetween(date, start, end) {
|
|
227
|
+
if (!isValidDate(date) || !isValidDate(start) || !isValidDate(end)) {
|
|
228
|
+
throw new InvalidDateError("Invalid date provided to isBetween");
|
|
229
|
+
}
|
|
230
|
+
return date.getTime() >= start.getTime() && date.getTime() <= end.getTime();
|
|
231
|
+
}
|
|
232
|
+
function isBusinessDay(date) {
|
|
233
|
+
return isValidDate(date) && !isWeekend(date);
|
|
234
|
+
}
|
|
235
|
+
function addBusinessDays(date, days) {
|
|
236
|
+
if (!isValidDate(date)) throw new InvalidDateError(date);
|
|
237
|
+
const result = new Date(date.getTime());
|
|
238
|
+
let remaining = Math.abs(days);
|
|
239
|
+
const step = days >= 0 ? 1 : -1;
|
|
240
|
+
while (remaining > 0) {
|
|
241
|
+
result.setDate(result.getDate() + step);
|
|
242
|
+
const day = result.getDay();
|
|
243
|
+
if (day !== 0 && day !== 6) {
|
|
244
|
+
remaining--;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
function calculateAge(birthDate) {
|
|
250
|
+
if (!isValidDate(birthDate)) throw new InvalidDateError(birthDate);
|
|
251
|
+
const today = /* @__PURE__ */ new Date();
|
|
252
|
+
let age = today.getFullYear() - birthDate.getFullYear();
|
|
253
|
+
const monthDiff = today.getMonth() - birthDate.getMonth();
|
|
254
|
+
if (monthDiff < 0 || monthDiff === 0 && today.getDate() < birthDate.getDate()) {
|
|
255
|
+
age--;
|
|
256
|
+
}
|
|
257
|
+
return age;
|
|
258
|
+
}
|
|
259
|
+
export {
|
|
260
|
+
InvalidDateError,
|
|
261
|
+
addBusinessDays,
|
|
262
|
+
addDays,
|
|
263
|
+
addMonths,
|
|
264
|
+
addYears,
|
|
265
|
+
calculateAge,
|
|
266
|
+
dateDiff,
|
|
267
|
+
endOfDay,
|
|
268
|
+
endOfMonth,
|
|
269
|
+
endOfYear,
|
|
270
|
+
formatDate,
|
|
271
|
+
isAfter,
|
|
272
|
+
isBefore,
|
|
273
|
+
isBetween,
|
|
274
|
+
isBusinessDay,
|
|
275
|
+
isLeapYear,
|
|
276
|
+
isWeekend,
|
|
277
|
+
parseDate,
|
|
278
|
+
startOfDay,
|
|
279
|
+
startOfMonth,
|
|
280
|
+
startOfYear
|
|
281
|
+
};
|
|
282
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/date/index.ts"],"sourcesContent":["/**\n * Error thrown when a date value is invalid.\n */\nexport class InvalidDateError extends Error {\n constructor(input: unknown) {\n super(`Invalid date: ${String(input)}`)\n this.name = 'InvalidDateError'\n }\n}\n\nexport interface DateDiff {\n years: number\n months: number\n days: number\n hours: number\n minutes: number\n seconds: number\n}\n\nconst MONTH_NAMES_SHORT = [\n 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',\n 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',\n] as const\n\nconst MONTH_NAMES_FULL = [\n 'January', 'February', 'March', 'April', 'May', 'June',\n 'July', 'August', 'September', 'October', 'November', 'December',\n] as const\n\nconst MONTH_MAP: Record<string, number> = {\n jan: 0, january: 0,\n feb: 1, february: 1,\n mar: 2, march: 2,\n apr: 3, april: 3,\n may: 4,\n jun: 5, june: 5,\n jul: 6, july: 6,\n aug: 7, august: 7,\n sep: 8, september: 8,\n oct: 9, october: 9,\n nov: 10, november: 10,\n dec: 11, december: 11,\n}\n\n/**\n * Formats a Date to a string using the given format pattern.\n *\n * Supported tokens:\n * - `YYYY` — 4-digit year\n * - `YY` — 2-digit year\n * - `MMMM` — full month name\n * - `MMM` — abbreviated month name\n * - `MM` — 2-digit month (01–12)\n * - `DD` — 2-digit day (01–31)\n * - `HH` — 2-digit hours (00–23)\n * - `mm` — 2-digit minutes\n * - `ss` — 2-digit seconds\n * - `SSS` — milliseconds\n *\n * @param date - The date to format.\n * @param format - The format string (default `'YYYY-MM-DD'`).\n * @returns The formatted date string.\n */\nexport function formatDate(date: Date, format: string = 'YYYY-MM-DD'): string {\n const year = date.getFullYear()\n const month = date.getMonth()\n const day = date.getDate()\n const hours = date.getHours()\n const minutes = date.getMinutes()\n const seconds = date.getSeconds()\n const ms = date.getMilliseconds()\n\n const pad = (n: number, len: number = 2): string => String(n).padStart(len, '0')\n\n return format\n .replace(/YYYY/g, String(year))\n .replace(/YY/g, String(year).slice(-2))\n .replace(/MMMM/g, MONTH_NAMES_FULL[month]!)\n .replace(/MMM/g, MONTH_NAMES_SHORT[month]!)\n .replace(/MM/g, pad(month + 1))\n .replace(/DD/g, pad(day))\n .replace(/HH/g, pad(hours))\n .replace(/mm/g, pad(minutes))\n .replace(/ss/g, pad(seconds))\n .replace(/SSS/g, pad(ms, 3))\n}\n\n/**\n * Parses a date from a string, number (timestamp in ms), or Date object.\n *\n * Supported string formats:\n * - ISO (`YYYY-MM-DD`, `YYYY-MM-DDTHH:mm:ss`)\n * - `DD/MM/YYYY` or `DD-MM-YYYY`\n * - `DD MMM YYYY` or `DD MMMM YYYY`\n * - Unix timestamp (milliseconds)\n *\n * @param input - The value to parse.\n * @returns A valid Date object.\n * @throws {InvalidDateError} If the input cannot be parsed.\n */\nexport function parseDate(input: string | number | Date): Date {\n if (input instanceof Date) {\n if (isNaN(input.getTime())) throw new InvalidDateError(input)\n return new Date(input.getTime())\n }\n\n if (typeof input === 'number') {\n const d = new Date(input)\n if (isNaN(d.getTime())) throw new InvalidDateError(input)\n return d\n }\n\n const trimmed = input.trim()\n\n // ISO format: YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss\n const isoMatch = trimmed.match(/^(\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d+))?)?(?:Z|[+-]\\d{2}:?\\d{2})?$/)\n if (isoMatch) {\n const d = new Date(\n parseInt(isoMatch[1]!, 10),\n parseInt(isoMatch[2]!, 10) - 1,\n parseInt(isoMatch[3]!, 10),\n isoMatch[4] ? parseInt(isoMatch[4]!, 10) : 0,\n isoMatch[5] ? parseInt(isoMatch[5]!, 10) : 0,\n isoMatch[6] ? parseInt(isoMatch[6]!, 10) : 0,\n isoMatch[7] ? parseInt(isoMatch[7]!.padEnd(3, '0'), 10) : 0\n )\n if (!isNaN(d.getTime())) return d\n }\n\n // DD/MM/YYYY or DD-MM-YYYY\n const dmyMatch = trimmed.match(/^(\\d{1,2})[\\/-](\\d{1,2})[\\/-](\\d{4})$/)\n if (dmyMatch) {\n const d = new Date(\n parseInt(dmyMatch[3]!, 10),\n parseInt(dmyMatch[2]!, 10) - 1,\n parseInt(dmyMatch[1]!, 10)\n )\n if (!isNaN(d.getTime())) return d\n }\n\n // DD MMM YYYY or DD MMMM YYYY\n const textMatch = trimmed.match(/^(\\d{1,2})\\s+([a-zA-Z]+)\\s+(\\d{4})$/)\n if (textMatch) {\n const monthIndex = MONTH_MAP[textMatch[2]!.toLowerCase()]\n if (monthIndex !== undefined) {\n const d = new Date(\n parseInt(textMatch[3]!, 10),\n monthIndex,\n parseInt(textMatch[1]!, 10)\n )\n if (!isNaN(d.getTime())) return d\n }\n }\n\n // Unix timestamp (milliseconds) as string\n const numMatch = trimmed.match(/^-?\\d+$/)\n if (numMatch) {\n const d = new Date(parseInt(numMatch[0], 10))\n if (!isNaN(d.getTime())) return d\n }\n\n // Fallback: let Date.parse try\n const fallback = new Date(trimmed)\n if (!isNaN(fallback.getTime())) return fallback\n\n throw new InvalidDateError(input)\n}\n\nfunction isValidDate(d: Date): boolean {\n return d instanceof Date && !isNaN(d.getTime())\n}\n\nconst MS_IN_SECOND = 1000\nconst MS_IN_MINUTE = 60 * MS_IN_SECOND\nconst MS_IN_HOUR = 60 * MS_IN_MINUTE\nconst MS_IN_DAY = 24 * MS_IN_HOUR\n\n/**\n * Computes the difference between two dates.\n *\n * @param date1 - Start date.\n * @param date2 - End date.\n * @returns An object with years, months, days, hours, minutes, seconds.\n * @throws {InvalidDateError} If either date is invalid.\n */\nexport function dateDiff(date1: Date, date2: Date): DateDiff {\n if (!isValidDate(date1) || !isValidDate(date2)) {\n throw new InvalidDateError('Invalid date provided to dateDiff')\n }\n\n let years = date2.getFullYear() - date1.getFullYear()\n let months = date2.getMonth() - date1.getMonth()\n let days = date2.getDate() - date1.getDate()\n\n if (days < 0) {\n months -= 1\n const prevMonth = new Date(date2.getFullYear(), date2.getMonth(), 0)\n days += prevMonth.getDate()\n }\n\n if (months < 0) {\n years -= 1\n months += 12\n }\n\n const msDiff = Math.abs(date2.getTime() - date1.getTime())\n const totalSeconds = Math.floor(msDiff / MS_IN_SECOND)\n const hours = Math.floor((msDiff % MS_IN_DAY) / MS_IN_HOUR)\n const minutes = Math.floor((msDiff % MS_IN_HOUR) / MS_IN_MINUTE)\n const seconds = totalSeconds % 60\n\n return { years, months, days, hours, minutes, seconds }\n}\n\n/**\n * Adds days to a date.\n *\n * @param date - The original date.\n * @param days - Number of days to add (negative to subtract).\n * @returns A new Date.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function addDays(date: Date, days: number): Date {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n const result = new Date(date.getTime())\n result.setDate(result.getDate() + days)\n return result\n}\n\n/**\n * Adds months to a date. Handles month-end overflow (e.g., Jan 31 + 1 month\n * becomes Feb 28).\n *\n * @param date - The original date.\n * @param months - Number of months to add (negative to subtract).\n * @returns A new Date.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function addMonths(date: Date, months: number): Date {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n const result = new Date(date.getTime())\n const targetMonth = result.getMonth() + months\n result.setMonth(targetMonth)\n\n if (result.getMonth() !== ((targetMonth % 12) + 12) % 12) {\n result.setDate(0)\n }\n\n return result\n}\n\n/**\n * Adds years to a date. Handles leap-year overflow (e.g., Feb 29 + 1 year\n * becomes Feb 28).\n *\n * @param date - The original date.\n * @param years - Number of years to add (negative to subtract).\n * @returns A new Date.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function addYears(date: Date, years: number): Date {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n const result = new Date(date.getTime())\n const targetYear = result.getFullYear() + years\n result.setFullYear(targetYear)\n\n if (result.getFullYear() !== targetYear) {\n result.setDate(0)\n }\n\n return result\n}\n\n/**\n * Returns the start of the day (00:00:00.000) for the given date.\n *\n * @param date - The date.\n * @returns A new Date set to midnight.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function startOfDay(date: Date): Date {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0)\n}\n\n/**\n * Returns the end of the day (23:59:59.999) for the given date.\n *\n * @param date - The date.\n * @returns A new Date set to the last millisecond of the day.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function endOfDay(date: Date): Date {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999)\n}\n\n/**\n * Returns the first moment of the month for the given date.\n *\n * @param date - The date.\n * @returns A new Date set to the start of the month.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function startOfMonth(date: Date): Date {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0)\n}\n\n/**\n * Returns the last moment of the month for the given date.\n *\n * @param date - The date.\n * @returns A new Date set to the end of the month.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function endOfMonth(date: Date): Date {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n return new Date(date.getFullYear(), date.getMonth() + 1, 0, 23, 59, 59, 999)\n}\n\n/**\n * Returns the first moment of the year for the given date.\n *\n * @param date - The date.\n * @returns A new Date set to Jan 1 00:00:00.000.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function startOfYear(date: Date): Date {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n return new Date(date.getFullYear(), 0, 1, 0, 0, 0, 0)\n}\n\n/**\n * Returns the last moment of the year for the given date.\n *\n * @param date - The date.\n * @returns A new Date set to Dec 31 23:59:59.999.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function endOfYear(date: Date): Date {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n return new Date(date.getFullYear(), 12, 0, 23, 59, 59, 999)\n}\n\n/**\n * Checks if the date falls on a weekend (Saturday or Sunday).\n *\n * @param date - The date to check.\n * @returns Whether the date is a weekend.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function isWeekend(date: Date): boolean {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n const day = date.getDay()\n return day === 0 || day === 6\n}\n\n/**\n * Checks if a year is a leap year.\n *\n * @param year - The year to check.\n * @returns Whether the year is a leap year.\n */\nexport function isLeapYear(year: number): boolean {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0\n}\n\n/**\n * Checks if `date1` is before `date2`.\n *\n * @param date1 - First date.\n * @param date2 - Second date.\n * @returns Whether `date1` is before `date2`.\n * @throws {InvalidDateError} If either date is invalid.\n */\nexport function isBefore(date1: Date, date2: Date): boolean {\n if (!isValidDate(date1) || !isValidDate(date2)) {\n throw new InvalidDateError('Invalid date provided to isBefore')\n }\n return date1.getTime() < date2.getTime()\n}\n\n/**\n * Checks if `date1` is after `date2`.\n *\n * @param date1 - First date.\n * @param date2 - Second date.\n * @returns Whether `date1` is after `date2`.\n * @throws {InvalidDateError} If either date is invalid.\n */\nexport function isAfter(date1: Date, date2: Date): boolean {\n if (!isValidDate(date1) || !isValidDate(date2)) {\n throw new InvalidDateError('Invalid date provided to isAfter')\n }\n return date1.getTime() > date2.getTime()\n}\n\n/**\n * Checks if a date is within the inclusive range [start, end].\n *\n * @param date - The date to check.\n * @param start - Start of the range.\n * @param end - End of the range.\n * @returns Whether the date is between start and end.\n * @throws {InvalidDateError} If any date is invalid.\n */\nexport function isBetween(date: Date, start: Date, end: Date): boolean {\n if (!isValidDate(date) || !isValidDate(start) || !isValidDate(end)) {\n throw new InvalidDateError('Invalid date provided to isBetween')\n }\n return date.getTime() >= start.getTime() && date.getTime() <= end.getTime()\n}\n\n/**\n * Checks if a date is a business day (Monday to Friday).\n *\n * @param date - The date to check.\n * @returns Whether the date is a business day.\n */\nexport function isBusinessDay(date: Date): boolean {\n return isValidDate(date) && !isWeekend(date)\n}\n\n/**\n * Adds business days (skipping weekends) to a date.\n *\n * @param date - The starting date.\n * @param days - Number of business days to add (negative to subtract).\n * @returns A new Date.\n * @throws {InvalidDateError} If the input date is invalid.\n */\nexport function addBusinessDays(date: Date, days: number): Date {\n if (!isValidDate(date)) throw new InvalidDateError(date)\n\n const result = new Date(date.getTime())\n let remaining = Math.abs(days)\n const step = days >= 0 ? 1 : -1\n\n while (remaining > 0) {\n result.setDate(result.getDate() + step)\n const day = result.getDay()\n if (day !== 0 && day !== 6) {\n remaining--\n }\n }\n\n return result\n}\n\n/**\n * Calculates age in years from a birth date.\n *\n * @param birthDate - The date of birth.\n * @returns The age in years.\n * @throws {InvalidDateError} If the birth date is invalid.\n */\nexport function calculateAge(birthDate: Date): number {\n if (!isValidDate(birthDate)) throw new InvalidDateError(birthDate)\n\n const today = new Date()\n let age = today.getFullYear() - birthDate.getFullYear()\n const monthDiff = today.getMonth() - birthDate.getMonth()\n\n if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {\n age--\n }\n\n return age\n}\n"],"mappings":";AAGO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,OAAgB;AAC1B,UAAM,iBAAiB,OAAO,KAAK,CAAC,EAAE;AACtC,SAAK,OAAO;AAAA,EACd;AACF;AAWA,IAAM,oBAAoB;AAAA,EACxB;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EACnC;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AACrC;AAEA,IAAM,mBAAmB;AAAA,EACvB;AAAA,EAAW;AAAA,EAAY;AAAA,EAAS;AAAA,EAAS;AAAA,EAAO;AAAA,EAChD;AAAA,EAAQ;AAAA,EAAU;AAAA,EAAa;AAAA,EAAW;AAAA,EAAY;AACxD;AAEA,IAAM,YAAoC;AAAA,EACxC,KAAK;AAAA,EAAG,SAAS;AAAA,EACjB,KAAK;AAAA,EAAG,UAAU;AAAA,EAClB,KAAK;AAAA,EAAG,OAAO;AAAA,EACf,KAAK;AAAA,EAAG,OAAO;AAAA,EACf,KAAK;AAAA,EACL,KAAK;AAAA,EAAG,MAAM;AAAA,EACd,KAAK;AAAA,EAAG,MAAM;AAAA,EACd,KAAK;AAAA,EAAG,QAAQ;AAAA,EAChB,KAAK;AAAA,EAAG,WAAW;AAA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;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { DebounceOptions, DebouncedFunction, MemoizedFunction, RetryOptions, debounce, deepClone, deepMerge, identity, memoize, noop, once, retry, throttle } from './core/index.js';
|
|
2
|
+
export { DivisionByZeroError, add, approxEqual, average, ceil, clamp, div, floor, inRange, mul, randomInt, round, sub, sum } from './math/index.js';
|
|
3
|
+
export { DateDiff, InvalidDateError, addBusinessDays, addDays, addMonths, addYears, calculateAge, dateDiff, endOfDay, endOfMonth, endOfYear, formatDate, isAfter, isBefore, isBetween, isBusinessDay, isLeapYear, isWeekend, parseDate, startOfDay, startOfMonth, startOfYear } from './date/index.js';
|
|
4
|
+
export { base64Decode, base64Encode, checksum, constantTimeEqual, generateOTP, generateToken, hash, randomHex, simpleHash, xorCipher } from './crypto/index.js';
|
|
5
|
+
export { ParsedPath, basename, dirname, extname, format, isAbsolute, join, normalize, parse, relative, resolve } from './path/index.js';
|
|
6
|
+
export { chunk, first, flatten, groupBy, isEmpty, keyBy, last, omit, orderBy, pick, pluck, sample, sampleSize, shuffle, sortBy, uniq, uniqueBy } from './collection/index.js';
|
|
7
|
+
export { camelCase, capitalize, countOccurrences, escapeHtml, kebabCase, nanoid, pad, padEnd, padStart, pascalCase, reverse, slugify, snakeCase, template, trim, trimEnd, trimStart, truncate, unescapeHtml, uuid, words } from './string/index.js';
|
|
8
|
+
export { Deferred, allSettledMap, deferred, parallelMap, pipeline, raceWithTimeout, retryAsync, sleep, timeout } from './async/index.js';
|
|
9
|
+
export { CsvOptions, env, envBool, envInt, parseCsv, safeJsonParse, stringifyCsv } from './io/index.js';
|
|
10
|
+
export { assertDefined, assertType, castArray, ensureArray, getType, isArray, isBoolean, isDate, isFunction, isMap, isNil, isNull, isNumber, isObject, isPromise, isRegExp, isSet, isString, isUndefined } from './type/index.js';
|