nuxt-ui-elements 0.1.16 → 0.1.18
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/module.json
CHANGED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date utilities built on @internationalized/date
|
|
3
|
+
* Provides tree-shakeable functional API for date manipulation
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* import { add, format, today } from '#std/date'
|
|
7
|
+
*
|
|
8
|
+
* const nextMonth = add(today(), 1, 'month')
|
|
9
|
+
* const formatted = format(nextMonth, 'MMMM D, YYYY') // "January 15, 2024"
|
|
10
|
+
*/
|
|
11
|
+
import type { CalendarDate, CalendarDateTime, DateValue, ZonedDateTime } from "@internationalized/date";
|
|
12
|
+
import { getDayOfWeek, getLocalTimeZone, getWeeksInMonth, isSameDay, isSameMonth, isSameYear, isToday, isWeekend } from "@internationalized/date";
|
|
13
|
+
/**
|
|
14
|
+
* Add time to a date
|
|
15
|
+
* @param input - The date to add to
|
|
16
|
+
* @param amount - The amount to add
|
|
17
|
+
* @param unit - The unit of time to add
|
|
18
|
+
* @returns The new date with time added
|
|
19
|
+
* @example
|
|
20
|
+
* add(someDate, 1, 'month')
|
|
21
|
+
* add(someDate, 7, 'day')
|
|
22
|
+
*/
|
|
23
|
+
export declare function add(input: Date | string | DateValue, amount: number, unit: "day" | "week" | "month" | "year" | "hour" | "minute" | "second"): DateValue;
|
|
24
|
+
/**
|
|
25
|
+
* Subtract time from a date
|
|
26
|
+
* @param input - The date to subtract from
|
|
27
|
+
* @param amount - The amount to subtract
|
|
28
|
+
* @param unit - The unit of time to subtract
|
|
29
|
+
* @returns The new date with time subtracted
|
|
30
|
+
* @example
|
|
31
|
+
* subtract(someDate, 1, 'month')
|
|
32
|
+
* subtract(someDate, 7, 'day')
|
|
33
|
+
*/
|
|
34
|
+
export declare function subtract(input: Date | string | DateValue, amount: number, unit: "day" | "week" | "month" | "year" | "hour" | "minute" | "second"): DateValue;
|
|
35
|
+
/**
|
|
36
|
+
* Set specific date/time values
|
|
37
|
+
* @param input - The date to modify
|
|
38
|
+
* @param values - Object containing the date/time values to set
|
|
39
|
+
* @returns The new date with values set
|
|
40
|
+
* @example
|
|
41
|
+
* set(someDate, { day: 15, month: 3 })
|
|
42
|
+
*/
|
|
43
|
+
export declare function set(input: Date | string | DateValue, values: {
|
|
44
|
+
year?: number;
|
|
45
|
+
month?: number;
|
|
46
|
+
day?: number;
|
|
47
|
+
hour?: number;
|
|
48
|
+
minute?: number;
|
|
49
|
+
second?: number;
|
|
50
|
+
}): DateValue;
|
|
51
|
+
/**
|
|
52
|
+
* Convert to native JavaScript Date object
|
|
53
|
+
* @param input - The date to convert
|
|
54
|
+
* @param timeZone - Optional timezone (defaults to local timezone)
|
|
55
|
+
* @returns JavaScript Date object
|
|
56
|
+
* @example
|
|
57
|
+
* toDate(someDate)
|
|
58
|
+
*/
|
|
59
|
+
export declare function toDate(input: Date | string | DateValue, timeZone?: string): Date;
|
|
60
|
+
/**
|
|
61
|
+
* Format the date using Day.js-compatible format tokens
|
|
62
|
+
*
|
|
63
|
+
* Supports all standard Day.js tokens: YYYY, MM, DD, HH, mm, ss, etc.
|
|
64
|
+
* For a complete list of format tokens, see: https://day.js.org/docs/en/display/format
|
|
65
|
+
*
|
|
66
|
+
* @param input - The date to format
|
|
67
|
+
* @param formatString - Format string using Day.js tokens (default: 'YYYY-MM-DD')
|
|
68
|
+
* @param locale - Locale for month/weekday names (default: 'en-US')
|
|
69
|
+
* @returns Formatted date string
|
|
70
|
+
* @example
|
|
71
|
+
* format(someDate, 'YYYY-MM-DD')
|
|
72
|
+
* format(someDate, 'DD/MM/YYYY HH:mm:ss')
|
|
73
|
+
* format(someDate, 'MMMM D, YYYY')
|
|
74
|
+
* format(someDate, 'MMM DD, YYYY h:mm A')
|
|
75
|
+
*/
|
|
76
|
+
export declare function format(input: Date | string | DateValue, formatString?: string, locale?: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* Get relative time string (e.g., "2 days ago", "in 3 months")
|
|
79
|
+
* @param input - The date to compare against now
|
|
80
|
+
* @param locale - Locale for the relative time format (default: 'en-US')
|
|
81
|
+
* @returns Relative time string
|
|
82
|
+
* @example
|
|
83
|
+
* relative(someDate) // "2 days ago"
|
|
84
|
+
* relative(futureDate) // "in 3 months"
|
|
85
|
+
*/
|
|
86
|
+
export declare function relative(input: Date | string | DateValue, locale?: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* Convert to CalendarDate (date without time)
|
|
89
|
+
* @param input - The date to convert
|
|
90
|
+
* @returns CalendarDate object
|
|
91
|
+
* @example
|
|
92
|
+
* asCalendarDate(someDate)
|
|
93
|
+
*/
|
|
94
|
+
export declare function asCalendarDate(input: Date | string | DateValue): CalendarDate;
|
|
95
|
+
/**
|
|
96
|
+
* Convert to CalendarDateTime (date with time, no timezone)
|
|
97
|
+
* @param input - The date to convert
|
|
98
|
+
* @returns CalendarDateTime object
|
|
99
|
+
* @example
|
|
100
|
+
* asCalendarDateTime(someDate)
|
|
101
|
+
*/
|
|
102
|
+
export declare function asCalendarDateTime(input: Date | string | DateValue): CalendarDateTime;
|
|
103
|
+
/**
|
|
104
|
+
* Convert to ZonedDateTime (date with time and timezone)
|
|
105
|
+
* @param input - The date to convert
|
|
106
|
+
* @param timeZone - Optional timezone (defaults to local timezone)
|
|
107
|
+
* @returns ZonedDateTime object
|
|
108
|
+
* @example
|
|
109
|
+
* asZonedDateTime(someDate, 'America/New_York')
|
|
110
|
+
*/
|
|
111
|
+
export declare function asZonedDateTime(input: Date | string | DateValue, timeZone?: string): ZonedDateTime;
|
|
112
|
+
/**
|
|
113
|
+
* Check if this date is before another date
|
|
114
|
+
* @param input - The first date
|
|
115
|
+
* @param other - The date to compare against
|
|
116
|
+
* @returns True if input is before other
|
|
117
|
+
* @example
|
|
118
|
+
* isBefore(date1, date2)
|
|
119
|
+
*/
|
|
120
|
+
export declare function isBefore(input: Date | string | DateValue, other: DateValue | Date | string): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Check if this date is after another date
|
|
123
|
+
* @param input - The first date
|
|
124
|
+
* @param other - The date to compare against
|
|
125
|
+
* @returns True if input is after other
|
|
126
|
+
* @example
|
|
127
|
+
* isAfter(date1, date2)
|
|
128
|
+
*/
|
|
129
|
+
export declare function isAfter(input: Date | string | DateValue, other: DateValue | Date | string): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Check if this date is the same as another date
|
|
132
|
+
* @param input - The first date
|
|
133
|
+
* @param other - The date to compare against
|
|
134
|
+
* @returns True if dates are equal
|
|
135
|
+
* @example
|
|
136
|
+
* isSame(date1, date2)
|
|
137
|
+
*/
|
|
138
|
+
export declare function isSame(input: Date | string | DateValue, other: DateValue | Date | string): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Calculate the difference between two dates
|
|
141
|
+
* @param input - The first date
|
|
142
|
+
* @param other - The second date to subtract
|
|
143
|
+
* @param unit - The unit to return the difference in (default: 'millisecond')
|
|
144
|
+
* @returns The difference between the two dates in the specified unit
|
|
145
|
+
* @example
|
|
146
|
+
* diff(date1, date2, 'days') // returns number of days between dates
|
|
147
|
+
* diff(date1, date2, 'hours') // returns number of hours between dates
|
|
148
|
+
*/
|
|
149
|
+
export declare function diff(input: Date | string | DateValue, other: Date | string | DateValue, unit?: "year" | "month" | "week" | "day" | "hour" | "minute" | "second" | "millisecond"): number;
|
|
150
|
+
/**
|
|
151
|
+
* Check if a date is between two other dates
|
|
152
|
+
* @param input - The date to check
|
|
153
|
+
* @param start - The start date of the range
|
|
154
|
+
* @param end - The end date of the range
|
|
155
|
+
* @param inclusive - Whether to include the start and end dates (default: true)
|
|
156
|
+
* @returns True if the date is within the range
|
|
157
|
+
* @example
|
|
158
|
+
* isBetween(date, startDate, endDate) // true if date is between start and end (inclusive)
|
|
159
|
+
* isBetween(date, startDate, endDate, false) // exclusive check
|
|
160
|
+
*/
|
|
161
|
+
export declare function isBetween(input: Date | string | DateValue, start: Date | string | DateValue, end: Date | string | DateValue, inclusive?: boolean): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Start of a time period
|
|
164
|
+
* @param input - The date to get the start of
|
|
165
|
+
* @param unit - The time period unit
|
|
166
|
+
* @param locale - Locale for week start calculation (default: 'en-US')
|
|
167
|
+
* @returns The start of the specified time period
|
|
168
|
+
* @example
|
|
169
|
+
* startOf(someDate, 'month')
|
|
170
|
+
* startOf(someDate, 'week', 'en-US')
|
|
171
|
+
*/
|
|
172
|
+
export declare function startOf(input: Date | string | DateValue, unit: "day" | "week" | "month" | "year", locale?: string): CalendarDate;
|
|
173
|
+
/**
|
|
174
|
+
* End of a time period
|
|
175
|
+
* @param input - The date to get the end of
|
|
176
|
+
* @param unit - The time period unit
|
|
177
|
+
* @param locale - Locale for week end calculation (default: 'en-US')
|
|
178
|
+
* @returns The end of the specified time period
|
|
179
|
+
* @example
|
|
180
|
+
* endOf(someDate, 'month')
|
|
181
|
+
* endOf(someDate, 'week', 'en-US')
|
|
182
|
+
*/
|
|
183
|
+
export declare function endOf(input: Date | string | DateValue, unit: "day" | "week" | "month" | "year", locale?: string): CalendarDate;
|
|
184
|
+
/**
|
|
185
|
+
* Get today's date
|
|
186
|
+
* @param timeZone - Optional timezone (defaults to local timezone)
|
|
187
|
+
* @returns Today's date as a CalendarDate
|
|
188
|
+
* @example
|
|
189
|
+
* today()
|
|
190
|
+
*/
|
|
191
|
+
export declare function today(timeZone?: string): CalendarDate;
|
|
192
|
+
/**
|
|
193
|
+
* Get current date and time
|
|
194
|
+
* @param timeZone - Optional timezone (defaults to local timezone)
|
|
195
|
+
* @returns Current date and time as a ZonedDateTime
|
|
196
|
+
* @example
|
|
197
|
+
* now()
|
|
198
|
+
*/
|
|
199
|
+
export declare function now(timeZone?: string): ZonedDateTime;
|
|
200
|
+
/**
|
|
201
|
+
* Parse a date string
|
|
202
|
+
* @param dateString - Date string in YYYY-MM-DD format
|
|
203
|
+
* @returns Parsed CalendarDate
|
|
204
|
+
* @example
|
|
205
|
+
* parse('2024-01-15')
|
|
206
|
+
*/
|
|
207
|
+
export declare function parse(dateString: string): CalendarDate;
|
|
208
|
+
/**
|
|
209
|
+
* Re-export useful utilities from @internationalized/date
|
|
210
|
+
* that complement (not duplicate) the main API
|
|
211
|
+
*/
|
|
212
|
+
export { isSameDay, isSameMonth, isSameYear, isToday, isWeekend, getDayOfWeek, getWeeksInMonth, getLocalTimeZone, };
|
|
213
|
+
export type { CalendarDate, CalendarDateTime, DateValue, ZonedDateTime };
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import {
|
|
2
|
+
endOfWeek,
|
|
3
|
+
getDayOfWeek,
|
|
4
|
+
getLocalTimeZone,
|
|
5
|
+
getWeeksInMonth,
|
|
6
|
+
isSameDay,
|
|
7
|
+
isSameMonth,
|
|
8
|
+
isSameYear,
|
|
9
|
+
isToday,
|
|
10
|
+
isWeekend,
|
|
11
|
+
now as nowFromLib,
|
|
12
|
+
parseDate,
|
|
13
|
+
parseDateTime,
|
|
14
|
+
parseZonedDateTime,
|
|
15
|
+
startOfWeek,
|
|
16
|
+
toCalendarDate,
|
|
17
|
+
toCalendarDateTime,
|
|
18
|
+
today as todayFromLib
|
|
19
|
+
} from "@internationalized/date";
|
|
20
|
+
function parseDateInput(input) {
|
|
21
|
+
if (!input) {
|
|
22
|
+
return todayFromLib(getLocalTimeZone());
|
|
23
|
+
}
|
|
24
|
+
if (typeof input === "object" && "calendar" in input) {
|
|
25
|
+
return input;
|
|
26
|
+
}
|
|
27
|
+
if (input instanceof Date) {
|
|
28
|
+
const isoString = input.toISOString();
|
|
29
|
+
if (isoString.endsWith("T00:00:00.000Z")) {
|
|
30
|
+
const datePart = isoString.split("T")[0];
|
|
31
|
+
if (datePart) {
|
|
32
|
+
return parseDate(datePart);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return parseZonedDateTime(isoString);
|
|
36
|
+
}
|
|
37
|
+
if (typeof input === "string") {
|
|
38
|
+
if (input.includes("T") || input.includes(" ")) {
|
|
39
|
+
try {
|
|
40
|
+
return parseZonedDateTime(input);
|
|
41
|
+
} catch {
|
|
42
|
+
try {
|
|
43
|
+
return parseDateTime(input);
|
|
44
|
+
} catch {
|
|
45
|
+
const datePart = input.split("T")[0]?.split(" ")[0];
|
|
46
|
+
if (datePart) {
|
|
47
|
+
return parseDate(datePart);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return parseDate(input);
|
|
53
|
+
}
|
|
54
|
+
return todayFromLib(getLocalTimeZone());
|
|
55
|
+
}
|
|
56
|
+
export function add(input, amount, unit) {
|
|
57
|
+
const dateValue = parseDateInput(input);
|
|
58
|
+
return dateValue.add({ [unit + "s"]: amount });
|
|
59
|
+
}
|
|
60
|
+
export function subtract(input, amount, unit) {
|
|
61
|
+
const dateValue = parseDateInput(input);
|
|
62
|
+
return dateValue.subtract({ [unit + "s"]: amount });
|
|
63
|
+
}
|
|
64
|
+
export function set(input, values) {
|
|
65
|
+
let dateValue = parseDateInput(input);
|
|
66
|
+
if (values.year !== void 0) dateValue = dateValue.set({ year: values.year });
|
|
67
|
+
if (values.month !== void 0) dateValue = dateValue.set({ month: values.month });
|
|
68
|
+
if (values.day !== void 0) dateValue = dateValue.set({ day: values.day });
|
|
69
|
+
if (values.hour !== void 0 || values.minute !== void 0 || values.second !== void 0) {
|
|
70
|
+
if (!("hour" in dateValue)) {
|
|
71
|
+
dateValue = toCalendarDateTime(dateValue);
|
|
72
|
+
}
|
|
73
|
+
if (values.hour !== void 0)
|
|
74
|
+
dateValue = dateValue.set({
|
|
75
|
+
hour: values.hour
|
|
76
|
+
});
|
|
77
|
+
if (values.minute !== void 0)
|
|
78
|
+
dateValue = dateValue.set({
|
|
79
|
+
minute: values.minute
|
|
80
|
+
});
|
|
81
|
+
if (values.second !== void 0)
|
|
82
|
+
dateValue = dateValue.set({
|
|
83
|
+
second: values.second
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return dateValue;
|
|
87
|
+
}
|
|
88
|
+
export function toDate(input, timeZone) {
|
|
89
|
+
if (input instanceof Date && !timeZone) {
|
|
90
|
+
return input;
|
|
91
|
+
}
|
|
92
|
+
const dateValue = parseDateInput(input);
|
|
93
|
+
const tz = timeZone ?? getLocalTimeZone();
|
|
94
|
+
return toCalendarDate(dateValue).toDate(tz);
|
|
95
|
+
}
|
|
96
|
+
export function format(input, formatString = "YYYY-MM-DD", locale = "en-US") {
|
|
97
|
+
const jsDate = toDate(input);
|
|
98
|
+
const pad = (num, length = 2) => String(num).padStart(length, "0");
|
|
99
|
+
const getMonthName = (monthIndex, short = false) => {
|
|
100
|
+
const date = new Date(2e3, monthIndex, 1);
|
|
101
|
+
return new Intl.DateTimeFormat(locale, {
|
|
102
|
+
month: short ? "short" : "long"
|
|
103
|
+
}).format(date);
|
|
104
|
+
};
|
|
105
|
+
const formatMap = {
|
|
106
|
+
short: "short",
|
|
107
|
+
long: "long",
|
|
108
|
+
narrow: "narrow"
|
|
109
|
+
};
|
|
110
|
+
const getWeekdayName = (dayIndex, format2) => {
|
|
111
|
+
const date = new Date(2e3, 0, 2 + dayIndex);
|
|
112
|
+
return new Intl.DateTimeFormat(locale, {
|
|
113
|
+
weekday: formatMap[format2]
|
|
114
|
+
}).format(date);
|
|
115
|
+
};
|
|
116
|
+
const year = jsDate.getFullYear();
|
|
117
|
+
const month = jsDate.getMonth() + 1;
|
|
118
|
+
const day = jsDate.getDate();
|
|
119
|
+
const weekday = jsDate.getDay();
|
|
120
|
+
const hour24 = jsDate.getHours();
|
|
121
|
+
const hour12 = hour24 % 12 || 12;
|
|
122
|
+
const minute = jsDate.getMinutes();
|
|
123
|
+
const second = jsDate.getSeconds();
|
|
124
|
+
const millisecond = jsDate.getMilliseconds();
|
|
125
|
+
const isPM = hour24 >= 12;
|
|
126
|
+
const tokens = {
|
|
127
|
+
// Year
|
|
128
|
+
YYYY: String(year),
|
|
129
|
+
YY: String(year).slice(-2),
|
|
130
|
+
// Month
|
|
131
|
+
MMMM: getMonthName(month - 1, false),
|
|
132
|
+
MMM: getMonthName(month - 1, true),
|
|
133
|
+
MM: pad(month),
|
|
134
|
+
M: String(month),
|
|
135
|
+
// Day
|
|
136
|
+
DD: pad(day),
|
|
137
|
+
D: String(day),
|
|
138
|
+
// Day of week
|
|
139
|
+
dddd: getWeekdayName(weekday, "long"),
|
|
140
|
+
ddd: getWeekdayName(weekday, "short"),
|
|
141
|
+
dd: getWeekdayName(weekday, "narrow"),
|
|
142
|
+
d: String(weekday),
|
|
143
|
+
// Hour (24-hour)
|
|
144
|
+
HH: pad(hour24),
|
|
145
|
+
H: String(hour24),
|
|
146
|
+
// Hour (12-hour)
|
|
147
|
+
hh: pad(hour12),
|
|
148
|
+
h: String(hour12),
|
|
149
|
+
// Minute
|
|
150
|
+
mm: pad(minute),
|
|
151
|
+
m: String(minute),
|
|
152
|
+
// Second
|
|
153
|
+
ss: pad(second),
|
|
154
|
+
s: String(second),
|
|
155
|
+
// Millisecond
|
|
156
|
+
SSS: pad(millisecond, 3),
|
|
157
|
+
// AM/PM
|
|
158
|
+
A: isPM ? "PM" : "AM",
|
|
159
|
+
a: isPM ? "pm" : "am"
|
|
160
|
+
};
|
|
161
|
+
const tokenPattern = Object.keys(tokens).sort((a, b) => b.length - a.length).map((token) => token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
162
|
+
const regex = new RegExp(tokenPattern, "g");
|
|
163
|
+
const result = formatString.replace(regex, (match) => tokens[match]);
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
export function relative(input, locale = "en-US") {
|
|
167
|
+
const nowMs = (/* @__PURE__ */ new Date()).getTime();
|
|
168
|
+
const targetMs = toDate(input).getTime();
|
|
169
|
+
const diffMs = targetMs - nowMs;
|
|
170
|
+
const diffSec = Math.round(diffMs / 1e3);
|
|
171
|
+
const diffMin = Math.round(diffSec / 60);
|
|
172
|
+
const diffHour = Math.round(diffMin / 60);
|
|
173
|
+
const diffDay = Math.round(diffHour / 24);
|
|
174
|
+
const diffWeek = Math.round(diffDay / 7);
|
|
175
|
+
const diffMonth = Math.round(diffDay / 30);
|
|
176
|
+
const diffYear = Math.round(diffDay / 365);
|
|
177
|
+
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
|
|
178
|
+
if (Math.abs(diffSec) < 60) return rtf.format(diffSec, "second");
|
|
179
|
+
if (Math.abs(diffMin) < 60) return rtf.format(diffMin, "minute");
|
|
180
|
+
if (Math.abs(diffHour) < 24) return rtf.format(diffHour, "hour");
|
|
181
|
+
if (Math.abs(diffDay) < 7) return rtf.format(diffDay, "day");
|
|
182
|
+
if (Math.abs(diffWeek) < 4) return rtf.format(diffWeek, "week");
|
|
183
|
+
if (Math.abs(diffMonth) < 12) return rtf.format(diffMonth, "month");
|
|
184
|
+
return rtf.format(diffYear, "year");
|
|
185
|
+
}
|
|
186
|
+
export function asCalendarDate(input) {
|
|
187
|
+
const dateValue = parseDateInput(input);
|
|
188
|
+
return toCalendarDate(dateValue);
|
|
189
|
+
}
|
|
190
|
+
export function asCalendarDateTime(input) {
|
|
191
|
+
const dateValue = parseDateInput(input);
|
|
192
|
+
if ("hour" in dateValue) return dateValue;
|
|
193
|
+
return toCalendarDateTime(dateValue);
|
|
194
|
+
}
|
|
195
|
+
export function asZonedDateTime(input, timeZone) {
|
|
196
|
+
const dateValue = parseDateInput(input);
|
|
197
|
+
const tz = timeZone ?? getLocalTimeZone();
|
|
198
|
+
if ("timeZone" in dateValue) return dateValue;
|
|
199
|
+
const dateTime = "hour" in dateValue ? dateValue : toCalendarDateTime(dateValue);
|
|
200
|
+
return parseZonedDateTime(`${dateTime.toString()}[${tz}]`);
|
|
201
|
+
}
|
|
202
|
+
export function isBefore(input, other) {
|
|
203
|
+
const dateValue = parseDateInput(input);
|
|
204
|
+
const otherValue = parseDateInput(other);
|
|
205
|
+
return dateValue.compare(otherValue) < 0;
|
|
206
|
+
}
|
|
207
|
+
export function isAfter(input, other) {
|
|
208
|
+
const dateValue = parseDateInput(input);
|
|
209
|
+
const otherValue = parseDateInput(other);
|
|
210
|
+
return dateValue.compare(otherValue) > 0;
|
|
211
|
+
}
|
|
212
|
+
export function isSame(input, other) {
|
|
213
|
+
const dateValue = parseDateInput(input);
|
|
214
|
+
const otherValue = parseDateInput(other);
|
|
215
|
+
return dateValue.compare(otherValue) === 0;
|
|
216
|
+
}
|
|
217
|
+
export function diff(input, other, unit = "millisecond") {
|
|
218
|
+
const date1Ms = toDate(input).getTime();
|
|
219
|
+
const date2Ms = toDate(other).getTime();
|
|
220
|
+
const diffMs = date1Ms - date2Ms;
|
|
221
|
+
switch (unit) {
|
|
222
|
+
case "year":
|
|
223
|
+
return diffMs / (1e3 * 60 * 60 * 24 * 365.25);
|
|
224
|
+
case "month":
|
|
225
|
+
return diffMs / (1e3 * 60 * 60 * 24 * 30.44);
|
|
226
|
+
// Average month length
|
|
227
|
+
case "week":
|
|
228
|
+
return diffMs / (1e3 * 60 * 60 * 24 * 7);
|
|
229
|
+
case "day":
|
|
230
|
+
return diffMs / (1e3 * 60 * 60 * 24);
|
|
231
|
+
case "hour":
|
|
232
|
+
return diffMs / (1e3 * 60 * 60);
|
|
233
|
+
case "minute":
|
|
234
|
+
return diffMs / (1e3 * 60);
|
|
235
|
+
case "second":
|
|
236
|
+
return diffMs / 1e3;
|
|
237
|
+
case "millisecond":
|
|
238
|
+
return diffMs;
|
|
239
|
+
default:
|
|
240
|
+
return diffMs;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
export function isBetween(input, start, end, inclusive = true) {
|
|
244
|
+
const dateValue = parseDateInput(input);
|
|
245
|
+
const startValue = parseDateInput(start);
|
|
246
|
+
const endValue = parseDateInput(end);
|
|
247
|
+
if (inclusive) {
|
|
248
|
+
return dateValue.compare(startValue) >= 0 && dateValue.compare(endValue) <= 0;
|
|
249
|
+
} else {
|
|
250
|
+
return dateValue.compare(startValue) > 0 && dateValue.compare(endValue) < 0;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
export function startOf(input, unit, locale = "en-US") {
|
|
254
|
+
const dateValue = parseDateInput(input);
|
|
255
|
+
const calDate = toCalendarDate(dateValue);
|
|
256
|
+
switch (unit) {
|
|
257
|
+
case "day":
|
|
258
|
+
return calDate;
|
|
259
|
+
case "week":
|
|
260
|
+
return startOfWeek(calDate, locale);
|
|
261
|
+
case "month":
|
|
262
|
+
return calDate.set({ day: 1 });
|
|
263
|
+
case "year":
|
|
264
|
+
return calDate.set({ month: 1, day: 1 });
|
|
265
|
+
default:
|
|
266
|
+
return calDate;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
export function endOf(input, unit, locale = "en-US") {
|
|
270
|
+
const dateValue = parseDateInput(input);
|
|
271
|
+
const calDate = toCalendarDate(dateValue);
|
|
272
|
+
switch (unit) {
|
|
273
|
+
case "day":
|
|
274
|
+
return calDate;
|
|
275
|
+
case "week":
|
|
276
|
+
return endOfWeek(calDate, locale);
|
|
277
|
+
case "month": {
|
|
278
|
+
const nextMonth = calDate.add({ months: 1 }).set({ day: 1 });
|
|
279
|
+
return nextMonth.subtract({ days: 1 });
|
|
280
|
+
}
|
|
281
|
+
case "year":
|
|
282
|
+
return calDate.set({ month: 12, day: 31 });
|
|
283
|
+
default:
|
|
284
|
+
return calDate;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
export function today(timeZone) {
|
|
288
|
+
const tz = timeZone ?? getLocalTimeZone();
|
|
289
|
+
return todayFromLib(tz);
|
|
290
|
+
}
|
|
291
|
+
export function now(timeZone) {
|
|
292
|
+
const tz = timeZone ?? getLocalTimeZone();
|
|
293
|
+
return nowFromLib(tz);
|
|
294
|
+
}
|
|
295
|
+
export function parse(dateString) {
|
|
296
|
+
return parseDate(dateString);
|
|
297
|
+
}
|
|
298
|
+
export {
|
|
299
|
+
isSameDay,
|
|
300
|
+
isSameMonth,
|
|
301
|
+
isSameYear,
|
|
302
|
+
isToday,
|
|
303
|
+
isWeekend,
|
|
304
|
+
getDayOfWeek,
|
|
305
|
+
getWeeksInMonth,
|
|
306
|
+
getLocalTimeZone
|
|
307
|
+
};
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* Import from '#std' for tree-shakeable utilities
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* import { plur,
|
|
6
|
+
* import { plur, slugify, date } from '#std'
|
|
7
7
|
*
|
|
8
8
|
* const text = plur('item', count)
|
|
9
|
-
* const
|
|
9
|
+
* const slug = slugify('Hello World')
|
|
10
|
+
* const nextMonth = date.add(date.today(), 1, 'month')
|
|
10
11
|
*/
|
|
11
12
|
export { default as plur } from "plur";
|
|
12
|
-
export { default as
|
|
13
|
+
export { default as slugify } from "@sindresorhus/slugify";
|
|
14
|
+
export * as date from "./std/date.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-ui-elements",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "A collection of beautiful, animated UI components for Nuxt applications",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/genu/nuxt-ui-elements.git",
|
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@internationalized/date": "^3.10.1",
|
|
28
29
|
"@nuxt/kit": "^4.2.2",
|
|
29
|
-
"
|
|
30
|
+
"@sindresorhus/slugify": "^3.0.0",
|
|
30
31
|
"plur": "^6.0.0",
|
|
31
32
|
"scule": "^1.3.0",
|
|
32
33
|
"tailwind-variants": "^3.2.2"
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
"prettier": "^3.7.4",
|
|
48
49
|
"typescript": "~5.9.3",
|
|
49
50
|
"vitest": "^4.0.16",
|
|
50
|
-
"vue-tsc": "^3.2.
|
|
51
|
+
"vue-tsc": "^3.2.2"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
54
|
"@nuxt/ui": "^4.0.0"
|