@powerlines/plugin-date 0.12.299 → 0.12.301

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.
Files changed (76) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  2. package/dist/components/date-fns.cjs +528 -0
  3. package/dist/components/date-fns.d.cts +14 -0
  4. package/dist/components/date-fns.d.cts.map +1 -0
  5. package/dist/components/date-fns.d.mts +14 -0
  6. package/dist/components/date-fns.d.mts.map +1 -0
  7. package/dist/components/date-fns.mjs +528 -0
  8. package/dist/components/date-fns.mjs.map +1 -0
  9. package/dist/components/dayjs.cjs +473 -0
  10. package/dist/components/dayjs.d.cts +14 -0
  11. package/dist/components/dayjs.d.cts.map +1 -0
  12. package/dist/components/dayjs.d.mts +14 -0
  13. package/dist/components/dayjs.d.mts.map +1 -0
  14. package/dist/components/dayjs.mjs +473 -0
  15. package/dist/components/dayjs.mjs.map +1 -0
  16. package/dist/components/index.cjs +4 -0
  17. package/dist/components/index.d.cts +4 -0
  18. package/dist/components/index.d.mts +4 -0
  19. package/dist/components/index.mjs +6 -0
  20. package/dist/components/luxon.cjs +477 -0
  21. package/dist/components/luxon.d.cts +14 -0
  22. package/dist/components/luxon.d.cts.map +1 -0
  23. package/dist/components/luxon.d.mts +14 -0
  24. package/dist/components/luxon.d.mts.map +1 -0
  25. package/dist/components/luxon.mjs +477 -0
  26. package/dist/components/luxon.mjs.map +1 -0
  27. package/dist/components/moment.cjs +463 -0
  28. package/dist/components/moment.d.cts +14 -0
  29. package/dist/components/moment.d.cts.map +1 -0
  30. package/dist/components/moment.d.mts +14 -0
  31. package/dist/components/moment.d.mts.map +1 -0
  32. package/dist/components/moment.mjs +463 -0
  33. package/dist/components/moment.mjs.map +1 -0
  34. package/dist/index.cjs +17 -2007
  35. package/dist/index.d.cts +8 -40
  36. package/dist/index.d.cts.map +1 -1
  37. package/dist/index.d.mts +8 -40
  38. package/dist/index.d.mts.map +1 -1
  39. package/dist/index.mjs +6 -1970
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.cjs +43 -0
  42. package/dist/node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs +43 -0
  43. package/dist/node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs.map +1 -0
  44. package/dist/types/index.cjs +0 -3
  45. package/dist/types/index.d.cts +2 -3
  46. package/dist/types/index.d.mts +2 -3
  47. package/dist/types/index.mjs +0 -4
  48. package/dist/types/plugin.cjs +0 -1
  49. package/dist/types/plugin.d.cts +44 -2
  50. package/dist/types/plugin.d.cts.map +1 -0
  51. package/dist/types/plugin.d.mts +44 -2
  52. package/dist/types/plugin.d.mts.map +1 -0
  53. package/dist/types/plugin.mjs +0 -2
  54. package/dist/types/runtime.cjs +0 -1
  55. package/dist/types/runtime.d.cts +712 -2
  56. package/dist/types/runtime.d.cts.map +1 -0
  57. package/dist/types/runtime.d.mts +712 -2
  58. package/dist/types/runtime.d.mts.map +1 -0
  59. package/dist/types/runtime.mjs +0 -2
  60. package/package.json +5 -5
  61. package/dist/index-CA4VvAY_.d.mts +0 -1
  62. package/dist/index-CmCelmEL.d.cts +0 -1
  63. package/dist/plugin-CWe-29nA.d.mts +0 -44
  64. package/dist/plugin-CWe-29nA.d.mts.map +0 -1
  65. package/dist/plugin-D82ijYIk.d.cts +0 -44
  66. package/dist/plugin-D82ijYIk.d.cts.map +0 -1
  67. package/dist/plugin-DHXHjv16.cjs +0 -0
  68. package/dist/plugin-ufqFO5xS.mjs +0 -1
  69. package/dist/runtime-B7WoCmC4.mjs +0 -1
  70. package/dist/runtime-B8LVkjWB.d.cts +0 -712
  71. package/dist/runtime-B8LVkjWB.d.cts.map +0 -1
  72. package/dist/runtime-CiYq8JJ6.d.mts +0 -712
  73. package/dist/runtime-CiYq8JJ6.d.mts.map +0 -1
  74. package/dist/runtime-D4zTdSwv.cjs +0 -0
  75. package/dist/types-BReKsBV6.mjs +0 -1
  76. package/dist/types-CBTc19th.cjs +0 -0
@@ -0,0 +1,528 @@
1
+ import { getFileHeader } from "powerlines/lib/utilities/file-header";
2
+
3
+ //#region src/components/date-fns.ts
4
+ /**
5
+ * Generates the Powerlines configuration file.
6
+ *
7
+ * @param context - The build context containing runtime information.
8
+ * @returns A string representing the configuration file content.
9
+ */
10
+ function dateFnsModule(context) {
11
+ return `
12
+ /**
13
+ * The Date module provides utility functions for date manipulation and formatting
14
+ *
15
+ * @module ${context.config.framework}:date
16
+ */
17
+
18
+ ${getFileHeader(context)}
19
+
20
+ import { DateFormats, TimeUnit } from "@powerlines/plugin-date/types/runtime";
21
+ import { addDays as dateFnsAddDays } from "date-fns/addDays";
22
+ import { addHours as dateFnsAddHours } from "date-fns/addHours";
23
+ import { addMinutes as dateFnsAddMinutes } from "date-fns/addMinutes";
24
+ import { addMonths as dateFnsAddMonths } from "date-fns/addMonths";
25
+ import { addSeconds as dateFnsAddSeconds } from "date-fns/addSeconds";
26
+ import { addWeeks as dateFnsAddWeeks } from "date-fns/addWeeks";
27
+ import { addYears as dateFnsAddYears } from "date-fns/addYears";
28
+ import { differenceInDays } from "date-fns/differenceInDays";
29
+ import { differenceInHours } from "date-fns/differenceInHours";
30
+ import { differenceInMilliseconds } from "date-fns/differenceInMilliseconds";
31
+ import { differenceInMinutes } from "date-fns/differenceInMinutes";
32
+ import { differenceInMonths } from "date-fns/differenceInMonths";
33
+ import { differenceInQuarters } from "date-fns/differenceInQuarters";
34
+ import { differenceInSeconds } from "date-fns/differenceInSeconds";
35
+ import { differenceInWeeks } from "date-fns/differenceInWeeks";
36
+ import { differenceInYears } from "date-fns/differenceInYears";
37
+ import { eachDayOfInterval } from "date-fns/eachDayOfInterval";
38
+ import { endOfDay as dateFnsEndOfDay } from "date-fns/endOfDay";
39
+ import { endOfMonth as dateFnsEndOfMonth } from "date-fns/endOfMonth";
40
+ import { endOfWeek as dateFnsEndOfWeek } from "date-fns/endOfWeek";
41
+ import { endOfYear as dateFnsEndOfYear } from "date-fns/endOfYear";
42
+ import { format as dateFnsFormat, longFormatters } from "date-fns/format";
43
+ import { formatISO } from "date-fns/formatISO";
44
+ import { getDate as dateFnsGetDate } from "date-fns/getDate";
45
+ import { getDay as dateFnsGetDay } from "date-fns/getDay";
46
+ import { getDaysInMonth as dateFnsGetDaysInMonth } from "date-fns/getDaysInMonth";
47
+ import { getHours as dateFnsGetHours } from "date-fns/getHours";
48
+ import { getMinutes as dateFnsGetMinutes } from "date-fns/getMinutes";
49
+ import { getMonth as dateFnsGetMonth } from "date-fns/getMonth";
50
+ import { getSeconds as dateFnsGetSeconds } from "date-fns/getSeconds";
51
+ import { getWeek as dateFnsGetWeek } from "date-fns/getWeek";
52
+ import { getYear as dateFnsGetYear } from "date-fns/getYear";
53
+ import { isAfter as dateFnsIsAfter } from "date-fns/isAfter";
54
+ import { isBefore as dateFnsIsBefore } from "date-fns/isBefore";
55
+ import { isEqual as dateFnsIsEqual } from "date-fns/isEqual";
56
+ import { isSameDay as dateFnsIsSameDay } from "date-fns/isSameDay";
57
+ import { isSameHour as dateFnsIsSameHour } from "date-fns/isSameHour";
58
+ import { isSameMonth as dateFnsIsSameMonth } from "date-fns/isSameMonth";
59
+ import { isSameYear as dateFnsIsSameYear } from "date-fns/isSameYear";
60
+ import { isValid as dateFnsIsValid } from "date-fns/isValid";
61
+ import { isWithinInterval } from "date-fns/isWithinInterval";
62
+ import { Locale } from "date-fns/locale";
63
+ import { ${context.env.parsed.DEFAULT_LOCALE?.replaceAll("-", "") || "enUS"} as defaultLocale } from "date-fns/locale/${context.env.parsed.DEFAULT_LOCALE || "en-US"}";
64
+ import { parse as dateFnsParse } from "date-fns/parse";
65
+ import { parseISO as dateFnsParseISO } from "date-fns/parseISO";
66
+ import { setDate as dateFnsSetDate } from "date-fns/setDate";
67
+ import { setHours as dateFnsSetHours } from "date-fns/setHours";
68
+ import { setMinutes as dateFnsSetMinutes } from "date-fns/setMinutes";
69
+ import { setMonth as dateFnsSetMonth } from "date-fns/setMonth";
70
+ import { setSeconds as dateFnsSetSeconds } from "date-fns/setSeconds";
71
+ import { setYear as dateFnsSetYear } from "date-fns/setYear";
72
+ import { startOfDay as dateFnsStartOfDay } from "date-fns/startOfDay";
73
+ import { startOfMonth as dateFnsStartOfMonth } from "date-fns/startOfMonth";
74
+ import { startOfWeek as dateFnsStartOfWeek } from "date-fns/startOfWeek";
75
+ import { startOfYear as dateFnsStartOfYear } from "date-fns/startOfYear";
76
+
77
+ export const formats: DateFormats = {
78
+ dayOfMonth: "d",
79
+ fullDate: "PP",
80
+ fullDateWithWeekday: "PPPP",
81
+ fullDateTime: "PP p",
82
+ fullDateTime12h: "PP hh:mm aa",
83
+ fullDateTime24h: "PP HH:mm",
84
+ fullTime: "p",
85
+ fullTime12h: "hh:mm aa",
86
+ fullTime24h: "HH:mm",
87
+ hours12h: "hh",
88
+ hours24h: "HH",
89
+ keyboardDate: "P",
90
+ keyboardDateTime: "P p",
91
+ keyboardDateTime12h: "P hh:mm aa",
92
+ keyboardDateTime24h: "P HH:mm",
93
+ systemDateTime: "P HH:mm:ss.SSS",
94
+ filePathDateTime: "P_HH-mm-ss-SSS",
95
+ minutes: "mm",
96
+ month: "LLLL",
97
+ monthAndDate: "MMMM d",
98
+ monthAndYear: "LLLL yyyy",
99
+ monthShort: "MMM",
100
+ weekday: "EEEE",
101
+ weekdayShort: "EEE",
102
+ normalDate: "d MMMM",
103
+ normalDateWithWeekday: "EEE, MMM d",
104
+ seconds: "ss",
105
+ shortDate: "MMM d",
106
+ year: "yyyy"
107
+ };
108
+
109
+ export const locale: Locale = defaultLocale;
110
+
111
+ /**
112
+ * Creates a date object using the provided value.
113
+ *
114
+ * @remarks
115
+ * This function creates a date object using the provided value. If the value is \`null\`, it returns \`null\`. If the value is \`undefined\`, it returns the current date. If the value is a string, it parses the string as a date. If the value is a number, it treats it as a timestamp. If the value is a date object, it returns the date object.
116
+ *
117
+ * @example
118
+ * \`\`\`ts
119
+ * import { createDate } from "storm:date";
120
+ *
121
+ * const date = createDate("2023-10-01");
122
+ * console.log(date.format("YYYY-MM-DD")); // Outputs: 2023-10-01
123
+ * \`\`\`
124
+ *
125
+ * @param value - The value to create the date object from.
126
+ * @returns A date object or \`null\` if the value is \`null\`.
127
+ */
128
+ export function createDate<
129
+ TArg = undefined,
130
+ TResultingDate = TArg extends null
131
+ ? null
132
+ : TArg extends undefined
133
+ ? Date
134
+ : Date | null
135
+ >(value?: TArg): TResultingDate {
136
+ if (typeof value === "undefined") {
137
+ return new Date() as TResultingDate;
138
+ }
139
+ if (value === null) {
140
+ return null as TResultingDate;
141
+ }
142
+ return new Date(value as string | number) as TResultingDate;
143
+ }
144
+
145
+ export const type = "date-fns";
146
+
147
+ // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
148
+ // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
149
+ export function is12HourCycleInCurrentLocale(): boolean {
150
+ if (locale) {
151
+ return /a/.test(locale.formatLong?.time({}));
152
+ }
153
+
154
+ // By default date-fns is using en-US locale with am/pm enabled
155
+ return true;
156
+ }
157
+
158
+ export function getFormatHelperText(format: string) {
159
+ // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
160
+ const longFormatRegexp = /P+p+|P+|p+|''|'(?:''|[^'])+(?:'|$)|./g;
161
+ const _locale = locale || defaultLocale;
162
+
163
+ return (
164
+ format
165
+ .match(longFormatRegexp)
166
+ ?.map(token => {
167
+ const firstCharacter = token[0];
168
+ if (firstCharacter === "p" || firstCharacter === "P") {
169
+ const longFormatter = longFormatters[firstCharacter]!;
170
+
171
+ return longFormatter(token, _locale.formatLong);
172
+ }
173
+
174
+ return token;
175
+ })
176
+ .join("")
177
+ .replace(/aaa|aa|a/g, "(a|p)m")
178
+ .toLocaleLowerCase() ?? format
179
+ );
180
+ }
181
+
182
+ export function parseISO(isoString: string) {
183
+ return dateFnsParseISO(isoString);
184
+ }
185
+
186
+ export function toISO(value: Date) {
187
+ return formatISO(value, {
188
+ format: "extended"
189
+ });
190
+ }
191
+
192
+ export function getCurrentLocaleCode() {
193
+ return locale?.code || $storm.env.DEFAULT_LOCALE;
194
+ }
195
+
196
+ export function addSeconds(value: Date, count: number) {
197
+ return dateFnsAddSeconds(value, count);
198
+ }
199
+
200
+ export function addMinutes(value: Date, count: number) {
201
+ return dateFnsAddMinutes(value, count);
202
+ }
203
+
204
+ export function addHours(value: Date, count: number) {
205
+ return dateFnsAddHours(value, count);
206
+ }
207
+
208
+ export function addDays(value: Date, count: number) {
209
+ return dateFnsAddDays(value, count);
210
+ }
211
+
212
+ export function addWeeks(value: Date, count: number) {
213
+ return dateFnsAddWeeks(value, count);
214
+ }
215
+
216
+ export function addMonths(value: Date, count: number) {
217
+ return dateFnsAddMonths(value, count);
218
+ }
219
+
220
+ export function addYears(value: Date, count: number) {
221
+ return dateFnsAddYears(value, count);
222
+ }
223
+
224
+ export function isValid(value: any) {
225
+ return dateFnsIsValid(createDate(value));
226
+ }
227
+
228
+ export function getDiff(
229
+ value: Date,
230
+ comparing: Date | string,
231
+ unit?: TimeUnit
232
+ ) {
233
+ // we output 0 if the compare date is string and parsing is not valid
234
+ const dateToCompare = createDate(comparing) ?? value;
235
+ if (!isValid(dateToCompare)) {
236
+ return 0;
237
+ }
238
+
239
+ switch (unit) {
240
+ case "years":
241
+ return differenceInYears(value, dateToCompare);
242
+ case "quarters":
243
+ return differenceInQuarters(value, dateToCompare);
244
+ case "months":
245
+ return differenceInMonths(value, dateToCompare);
246
+ case "weeks":
247
+ return differenceInWeeks(value, dateToCompare);
248
+ case "days":
249
+ return differenceInDays(value, dateToCompare);
250
+ case "hours":
251
+ return differenceInHours(value, dateToCompare);
252
+ case "minutes":
253
+ return differenceInMinutes(value, dateToCompare);
254
+ case "seconds":
255
+ return differenceInSeconds(value, dateToCompare);
256
+ case "milliseconds":
257
+ case undefined:
258
+ default:
259
+ return differenceInMilliseconds(value, dateToCompare);
260
+ }
261
+ }
262
+
263
+ export function isAfter(value: Date, comparing: Date) {
264
+ return dateFnsIsAfter(value, comparing);
265
+ }
266
+
267
+ export function isBefore(value: Date, comparing: Date) {
268
+ return dateFnsIsBefore(value, comparing);
269
+ }
270
+
271
+ export function startOfDay(value: Date) {
272
+ return dateFnsStartOfDay(value);
273
+ }
274
+
275
+ export function endOfDay(value: Date) {
276
+ return dateFnsEndOfDay(value);
277
+ }
278
+
279
+ export function getHours(value: Date) {
280
+ return dateFnsGetHours(value);
281
+ }
282
+
283
+ export function setHours(value: Date, count: number) {
284
+ return dateFnsSetHours(value, count);
285
+ }
286
+
287
+ export function setMinutes(value: Date, count: number) {
288
+ return dateFnsSetMinutes(value, count);
289
+ }
290
+
291
+ export function getSeconds(value: Date) {
292
+ return dateFnsGetSeconds(value);
293
+ }
294
+
295
+ export function setSeconds(value: Date, count: number) {
296
+ return dateFnsSetSeconds(value, count);
297
+ }
298
+
299
+ export function isSameDay(value: Date, comparing: Date) {
300
+ return dateFnsIsSameDay(value, comparing);
301
+ }
302
+
303
+ export function isSameMonth(value: Date, comparing: Date) {
304
+ return dateFnsIsSameMonth(value, comparing);
305
+ }
306
+
307
+ export function isSameYear(value: Date, comparing: Date) {
308
+ return dateFnsIsSameYear(value, comparing);
309
+ }
310
+
311
+ export function isSameHour(value: Date, comparing: Date) {
312
+ return dateFnsIsSameHour(value, comparing);
313
+ }
314
+
315
+ export function startOfYear(value: Date) {
316
+ return dateFnsStartOfYear(value);
317
+ }
318
+
319
+ export function endOfYear(value: Date) {
320
+ return dateFnsEndOfYear(value);
321
+ }
322
+
323
+ export function startOfMonth(value: Date) {
324
+ return dateFnsStartOfMonth(value);
325
+ }
326
+
327
+ export function endOfMonth(value: Date) {
328
+ return dateFnsEndOfMonth(value);
329
+ }
330
+
331
+ export function startOfWeek(value: Date) {
332
+ return dateFnsStartOfWeek(value, {
333
+ locale
334
+ });
335
+ }
336
+
337
+ export function endOfWeek(value: Date) {
338
+ return dateFnsEndOfWeek(value, {
339
+ locale
340
+ });
341
+ }
342
+
343
+ export function getYear(value: Date) {
344
+ return dateFnsGetYear(value);
345
+ }
346
+
347
+ export function setYear(value: Date, count: number) {
348
+ return dateFnsSetYear(value, count);
349
+ }
350
+
351
+ export function toJsDate(value: Date) {
352
+ return value;
353
+ }
354
+
355
+ export function parse(value: string, formatString: string) {
356
+ if (value === "") {
357
+ return null;
358
+ }
359
+ return dateFnsParse(value, formatString, new Date(), {
360
+ locale
361
+ });
362
+ }
363
+
364
+ export function format(date: Date, formatKey: keyof DateFormats) {
365
+ return formatByString(date, formats[formatKey]);
366
+ }
367
+
368
+ export function formatByString(date: Date, formatString: string) {
369
+ return dateFnsFormat(date, formatString, {
370
+ locale
371
+ });
372
+ }
373
+
374
+ export function isEqual(date: any, comparing: any) {
375
+ if (date === null && comparing === null) {
376
+ return true;
377
+ }
378
+ return dateFnsIsEqual(date, comparing);
379
+ }
380
+
381
+ export function isNull(date: Date) {
382
+ return date === null;
383
+ }
384
+
385
+ export function isAfterDay(date: Date, value: Date) {
386
+ return isAfter(date, endOfDay(value));
387
+ }
388
+
389
+ export function isBeforeDay(date: Date, value: Date) {
390
+ return isBefore(date, startOfDay(value));
391
+ }
392
+
393
+ export function isBeforeYear(date: Date, value: Date) {
394
+ return isBefore(date, startOfYear(value));
395
+ }
396
+
397
+ export function isBeforeMonth(value: Date, comparing: Date): boolean {
398
+ return isBefore(value, startOfMonth(comparing));
399
+ }
400
+
401
+ export function isAfterMonth(value: Date, comparing: Date): boolean {
402
+ return isAfter(value, startOfMonth(comparing));
403
+ }
404
+
405
+ export function isAfterYear(date: Date, value: Date) {
406
+ return isAfter(date, endOfYear(value));
407
+ }
408
+
409
+ export function isWithinRange(date: Date, [start, end]: [Date, Date]) {
410
+ return isWithinInterval(date, {
411
+ start,
412
+ end
413
+ });
414
+ }
415
+
416
+ export function formatNumber(numberToFormat: string) {
417
+ return numberToFormat;
418
+ }
419
+
420
+ export function getMinutes(date: Date) {
421
+ return dateFnsGetMinutes(date);
422
+ }
423
+
424
+ export function getDate(date: Date) {
425
+ return dateFnsGetDate(date);
426
+ }
427
+
428
+ export function setDate(date: Date, count: number) {
429
+ return dateFnsSetDate(date, count);
430
+ }
431
+
432
+ export function getWeek(date: Date) {
433
+ return dateFnsGetWeek(date);
434
+ }
435
+
436
+ export function getMonth(date: Date) {
437
+ return dateFnsGetMonth(date);
438
+ }
439
+
440
+ export function getDaysInMonth(date: Date) {
441
+ return dateFnsGetDaysInMonth(date);
442
+ }
443
+
444
+ export function setMonth(date: Date, count: number) {
445
+ return dateFnsSetMonth(date, count);
446
+ }
447
+
448
+ export function getMeridiemText(meridiem: "am" | "pm") {
449
+ return meridiem === "am" ? "AM" : "PM";
450
+ }
451
+
452
+ export function getNextMonth(date: Date) {
453
+ return addMonths(date, 1);
454
+ }
455
+
456
+ export function getPreviousMonth(date: Date) {
457
+ return addMonths(date, -1);
458
+ }
459
+
460
+ export function getMonthArray(date: Date) {
461
+ const firstMonth = startOfYear(date);
462
+ const monthArray = [firstMonth];
463
+
464
+ while (monthArray.length < 12) {
465
+ const prevMonth = monthArray[monthArray.length - 1]!;
466
+ monthArray.push(getNextMonth(prevMonth));
467
+ }
468
+
469
+ return monthArray;
470
+ }
471
+
472
+ export function mergeDateAndTime(date: Date, time: Date) {
473
+ return setSeconds(
474
+ setMinutes(setHours(date, getHours(time)), getMinutes(time)),
475
+ getSeconds(time)
476
+ );
477
+ }
478
+
479
+ export function getWeekdays() {
480
+ const now = new Date();
481
+
482
+ return eachDayOfInterval({
483
+ start: startOfWeek(now),
484
+ end: endOfWeek(now)
485
+ }).map(day => formatByString(day, "EEEEEE"));
486
+ }
487
+
488
+ export function getWeekArray(date: Date) {
489
+ const start = startOfWeek(startOfMonth(date));
490
+ const end = endOfWeek(endOfMonth(date));
491
+ let count = 0;
492
+ let current = start;
493
+ const nestedWeeks: Date[][] = [];
494
+ let lastDay = null as null | number;
495
+ while (isBefore(current, end)) {
496
+ const weekNumber = Math.floor(count / 7);
497
+ nestedWeeks[weekNumber] ??= [];
498
+ const day = dateFnsGetDay(current);
499
+ if (lastDay !== day) {
500
+ lastDay = day;
501
+ nestedWeeks[weekNumber].push(current);
502
+ count += 1;
503
+ }
504
+ current = addDays(current, 1);
505
+ }
506
+ return nestedWeeks;
507
+ }
508
+
509
+ export function getYearRange(start: Date, end: Date) {
510
+ const startDate = startOfYear(start);
511
+ const endDate = endOfYear(end);
512
+ const years: Date[] = [];
513
+
514
+ let current = startDate;
515
+ while (isBefore(current, endDate)) {
516
+ years.push(current);
517
+ current = addYears(current, 1);
518
+ }
519
+ return years;
520
+ }
521
+
522
+
523
+ `;
524
+ }
525
+
526
+ //#endregion
527
+ export { dateFnsModule };
528
+ //# sourceMappingURL=date-fns.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-fns.mjs","names":[],"sources":["../../src/components/date-fns.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\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/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getFileHeader } from \"powerlines/lib/utilities/file-header\";\nimport { DatePluginContext } from \"../types/plugin\";\n\n/**\n * Generates the Powerlines configuration file.\n *\n * @param context - The build context containing runtime information.\n * @returns A string representing the configuration file content.\n */\nexport function dateFnsModule(context: DatePluginContext) {\n return `\n/**\n * The Date module provides utility functions for date manipulation and formatting\n *\n * @module ${context.config.framework}:date\n */\n\n${getFileHeader(context)}\n\nimport { DateFormats, TimeUnit } from \"@powerlines/plugin-date/types/runtime\";\nimport { addDays as dateFnsAddDays } from \"date-fns/addDays\";\nimport { addHours as dateFnsAddHours } from \"date-fns/addHours\";\nimport { addMinutes as dateFnsAddMinutes } from \"date-fns/addMinutes\";\nimport { addMonths as dateFnsAddMonths } from \"date-fns/addMonths\";\nimport { addSeconds as dateFnsAddSeconds } from \"date-fns/addSeconds\";\nimport { addWeeks as dateFnsAddWeeks } from \"date-fns/addWeeks\";\nimport { addYears as dateFnsAddYears } from \"date-fns/addYears\";\nimport { differenceInDays } from \"date-fns/differenceInDays\";\nimport { differenceInHours } from \"date-fns/differenceInHours\";\nimport { differenceInMilliseconds } from \"date-fns/differenceInMilliseconds\";\nimport { differenceInMinutes } from \"date-fns/differenceInMinutes\";\nimport { differenceInMonths } from \"date-fns/differenceInMonths\";\nimport { differenceInQuarters } from \"date-fns/differenceInQuarters\";\nimport { differenceInSeconds } from \"date-fns/differenceInSeconds\";\nimport { differenceInWeeks } from \"date-fns/differenceInWeeks\";\nimport { differenceInYears } from \"date-fns/differenceInYears\";\nimport { eachDayOfInterval } from \"date-fns/eachDayOfInterval\";\nimport { endOfDay as dateFnsEndOfDay } from \"date-fns/endOfDay\";\nimport { endOfMonth as dateFnsEndOfMonth } from \"date-fns/endOfMonth\";\nimport { endOfWeek as dateFnsEndOfWeek } from \"date-fns/endOfWeek\";\nimport { endOfYear as dateFnsEndOfYear } from \"date-fns/endOfYear\";\nimport { format as dateFnsFormat, longFormatters } from \"date-fns/format\";\nimport { formatISO } from \"date-fns/formatISO\";\nimport { getDate as dateFnsGetDate } from \"date-fns/getDate\";\nimport { getDay as dateFnsGetDay } from \"date-fns/getDay\";\nimport { getDaysInMonth as dateFnsGetDaysInMonth } from \"date-fns/getDaysInMonth\";\nimport { getHours as dateFnsGetHours } from \"date-fns/getHours\";\nimport { getMinutes as dateFnsGetMinutes } from \"date-fns/getMinutes\";\nimport { getMonth as dateFnsGetMonth } from \"date-fns/getMonth\";\nimport { getSeconds as dateFnsGetSeconds } from \"date-fns/getSeconds\";\nimport { getWeek as dateFnsGetWeek } from \"date-fns/getWeek\";\nimport { getYear as dateFnsGetYear } from \"date-fns/getYear\";\nimport { isAfter as dateFnsIsAfter } from \"date-fns/isAfter\";\nimport { isBefore as dateFnsIsBefore } from \"date-fns/isBefore\";\nimport { isEqual as dateFnsIsEqual } from \"date-fns/isEqual\";\nimport { isSameDay as dateFnsIsSameDay } from \"date-fns/isSameDay\";\nimport { isSameHour as dateFnsIsSameHour } from \"date-fns/isSameHour\";\nimport { isSameMonth as dateFnsIsSameMonth } from \"date-fns/isSameMonth\";\nimport { isSameYear as dateFnsIsSameYear } from \"date-fns/isSameYear\";\nimport { isValid as dateFnsIsValid } from \"date-fns/isValid\";\nimport { isWithinInterval } from \"date-fns/isWithinInterval\";\nimport { Locale } from \"date-fns/locale\";\nimport { ${\n context.env.parsed.DEFAULT_LOCALE?.replaceAll(\"-\", \"\") || \"enUS\"\n } as defaultLocale } from \"date-fns/locale/${\n context.env.parsed.DEFAULT_LOCALE || \"en-US\"\n }\";\nimport { parse as dateFnsParse } from \"date-fns/parse\";\nimport { parseISO as dateFnsParseISO } from \"date-fns/parseISO\";\nimport { setDate as dateFnsSetDate } from \"date-fns/setDate\";\nimport { setHours as dateFnsSetHours } from \"date-fns/setHours\";\nimport { setMinutes as dateFnsSetMinutes } from \"date-fns/setMinutes\";\nimport { setMonth as dateFnsSetMonth } from \"date-fns/setMonth\";\nimport { setSeconds as dateFnsSetSeconds } from \"date-fns/setSeconds\";\nimport { setYear as dateFnsSetYear } from \"date-fns/setYear\";\nimport { startOfDay as dateFnsStartOfDay } from \"date-fns/startOfDay\";\nimport { startOfMonth as dateFnsStartOfMonth } from \"date-fns/startOfMonth\";\nimport { startOfWeek as dateFnsStartOfWeek } from \"date-fns/startOfWeek\";\nimport { startOfYear as dateFnsStartOfYear } from \"date-fns/startOfYear\";\n\nexport const formats: DateFormats = {\n dayOfMonth: \"d\",\n fullDate: \"PP\",\n fullDateWithWeekday: \"PPPP\",\n fullDateTime: \"PP p\",\n fullDateTime12h: \"PP hh:mm aa\",\n fullDateTime24h: \"PP HH:mm\",\n fullTime: \"p\",\n fullTime12h: \"hh:mm aa\",\n fullTime24h: \"HH:mm\",\n hours12h: \"hh\",\n hours24h: \"HH\",\n keyboardDate: \"P\",\n keyboardDateTime: \"P p\",\n keyboardDateTime12h: \"P hh:mm aa\",\n keyboardDateTime24h: \"P HH:mm\",\n systemDateTime: \"P HH:mm:ss.SSS\",\n filePathDateTime: \"P_HH-mm-ss-SSS\",\n minutes: \"mm\",\n month: \"LLLL\",\n monthAndDate: \"MMMM d\",\n monthAndYear: \"LLLL yyyy\",\n monthShort: \"MMM\",\n weekday: \"EEEE\",\n weekdayShort: \"EEE\",\n normalDate: \"d MMMM\",\n normalDateWithWeekday: \"EEE, MMM d\",\n seconds: \"ss\",\n shortDate: \"MMM d\",\n year: \"yyyy\"\n};\n\nexport const locale: Locale = defaultLocale;\n\n/**\n * Creates a date object using the provided value.\n *\n * @remarks\n * This function creates a date object using the provided value. If the value is \\`null\\`, it returns \\`null\\`. If the value is \\`undefined\\`, it returns the current date. If the value is a string, it parses the string as a date. If the value is a number, it treats it as a timestamp. If the value is a date object, it returns the date object.\n *\n * @example\n * \\`\\`\\`ts\n * import { createDate } from \"storm:date\";\n *\n * const date = createDate(\"2023-10-01\");\n * console.log(date.format(\"YYYY-MM-DD\")); // Outputs: 2023-10-01\n * \\`\\`\\`\n *\n * @param value - The value to create the date object from.\n * @returns A date object or \\`null\\` if the value is \\`null\\`.\n */\nexport function createDate<\n TArg = undefined,\n TResultingDate = TArg extends null\n ? null\n : TArg extends undefined\n ? Date\n : Date | null\n>(value?: TArg): TResultingDate {\n if (typeof value === \"undefined\") {\n return new Date() as TResultingDate;\n }\n if (value === null) {\n return null as TResultingDate;\n }\n return new Date(value as string | number) as TResultingDate;\n}\n\nexport const type = \"date-fns\";\n\n// Note: date-fns input types are more lenient than this adapter, so we need to expose our more\n// strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.\nexport function is12HourCycleInCurrentLocale(): boolean {\n if (locale) {\n return /a/.test(locale.formatLong?.time({}));\n }\n\n // By default date-fns is using en-US locale with am/pm enabled\n return true;\n}\n\nexport function getFormatHelperText(format: string) {\n // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31\n const longFormatRegexp = /P+p+|P+|p+|''|'(?:''|[^'])+(?:'|$)|./g;\n const _locale = locale || defaultLocale;\n\n return (\n format\n .match(longFormatRegexp)\n ?.map(token => {\n const firstCharacter = token[0];\n if (firstCharacter === \"p\" || firstCharacter === \"P\") {\n const longFormatter = longFormatters[firstCharacter]!;\n\n return longFormatter(token, _locale.formatLong);\n }\n\n return token;\n })\n .join(\"\")\n .replace(/aaa|aa|a/g, \"(a|p)m\")\n .toLocaleLowerCase() ?? format\n );\n}\n\nexport function parseISO(isoString: string) {\n return dateFnsParseISO(isoString);\n}\n\nexport function toISO(value: Date) {\n return formatISO(value, {\n format: \"extended\"\n });\n}\n\nexport function getCurrentLocaleCode() {\n return locale?.code || $storm.env.DEFAULT_LOCALE;\n}\n\nexport function addSeconds(value: Date, count: number) {\n return dateFnsAddSeconds(value, count);\n}\n\nexport function addMinutes(value: Date, count: number) {\n return dateFnsAddMinutes(value, count);\n}\n\nexport function addHours(value: Date, count: number) {\n return dateFnsAddHours(value, count);\n}\n\nexport function addDays(value: Date, count: number) {\n return dateFnsAddDays(value, count);\n}\n\nexport function addWeeks(value: Date, count: number) {\n return dateFnsAddWeeks(value, count);\n}\n\nexport function addMonths(value: Date, count: number) {\n return dateFnsAddMonths(value, count);\n}\n\nexport function addYears(value: Date, count: number) {\n return dateFnsAddYears(value, count);\n}\n\nexport function isValid(value: any) {\n return dateFnsIsValid(createDate(value));\n}\n\nexport function getDiff(\n value: Date,\n comparing: Date | string,\n unit?: TimeUnit\n) {\n // we output 0 if the compare date is string and parsing is not valid\n const dateToCompare = createDate(comparing) ?? value;\n if (!isValid(dateToCompare)) {\n return 0;\n }\n\n switch (unit) {\n case \"years\":\n return differenceInYears(value, dateToCompare);\n case \"quarters\":\n return differenceInQuarters(value, dateToCompare);\n case \"months\":\n return differenceInMonths(value, dateToCompare);\n case \"weeks\":\n return differenceInWeeks(value, dateToCompare);\n case \"days\":\n return differenceInDays(value, dateToCompare);\n case \"hours\":\n return differenceInHours(value, dateToCompare);\n case \"minutes\":\n return differenceInMinutes(value, dateToCompare);\n case \"seconds\":\n return differenceInSeconds(value, dateToCompare);\n case \"milliseconds\":\n case undefined:\n default:\n return differenceInMilliseconds(value, dateToCompare);\n }\n}\n\nexport function isAfter(value: Date, comparing: Date) {\n return dateFnsIsAfter(value, comparing);\n}\n\nexport function isBefore(value: Date, comparing: Date) {\n return dateFnsIsBefore(value, comparing);\n}\n\nexport function startOfDay(value: Date) {\n return dateFnsStartOfDay(value);\n}\n\nexport function endOfDay(value: Date) {\n return dateFnsEndOfDay(value);\n}\n\nexport function getHours(value: Date) {\n return dateFnsGetHours(value);\n}\n\nexport function setHours(value: Date, count: number) {\n return dateFnsSetHours(value, count);\n}\n\nexport function setMinutes(value: Date, count: number) {\n return dateFnsSetMinutes(value, count);\n}\n\nexport function getSeconds(value: Date) {\n return dateFnsGetSeconds(value);\n}\n\nexport function setSeconds(value: Date, count: number) {\n return dateFnsSetSeconds(value, count);\n}\n\nexport function isSameDay(value: Date, comparing: Date) {\n return dateFnsIsSameDay(value, comparing);\n}\n\nexport function isSameMonth(value: Date, comparing: Date) {\n return dateFnsIsSameMonth(value, comparing);\n}\n\nexport function isSameYear(value: Date, comparing: Date) {\n return dateFnsIsSameYear(value, comparing);\n}\n\nexport function isSameHour(value: Date, comparing: Date) {\n return dateFnsIsSameHour(value, comparing);\n}\n\nexport function startOfYear(value: Date) {\n return dateFnsStartOfYear(value);\n}\n\nexport function endOfYear(value: Date) {\n return dateFnsEndOfYear(value);\n}\n\nexport function startOfMonth(value: Date) {\n return dateFnsStartOfMonth(value);\n}\n\nexport function endOfMonth(value: Date) {\n return dateFnsEndOfMonth(value);\n}\n\nexport function startOfWeek(value: Date) {\n return dateFnsStartOfWeek(value, {\n locale\n });\n}\n\nexport function endOfWeek(value: Date) {\n return dateFnsEndOfWeek(value, {\n locale\n });\n}\n\nexport function getYear(value: Date) {\n return dateFnsGetYear(value);\n}\n\nexport function setYear(value: Date, count: number) {\n return dateFnsSetYear(value, count);\n}\n\nexport function toJsDate(value: Date) {\n return value;\n}\n\nexport function parse(value: string, formatString: string) {\n if (value === \"\") {\n return null;\n }\n return dateFnsParse(value, formatString, new Date(), {\n locale\n });\n}\n\nexport function format(date: Date, formatKey: keyof DateFormats) {\n return formatByString(date, formats[formatKey]);\n}\n\nexport function formatByString(date: Date, formatString: string) {\n return dateFnsFormat(date, formatString, {\n locale\n });\n}\n\nexport function isEqual(date: any, comparing: any) {\n if (date === null && comparing === null) {\n return true;\n }\n return dateFnsIsEqual(date, comparing);\n}\n\nexport function isNull(date: Date) {\n return date === null;\n}\n\nexport function isAfterDay(date: Date, value: Date) {\n return isAfter(date, endOfDay(value));\n}\n\nexport function isBeforeDay(date: Date, value: Date) {\n return isBefore(date, startOfDay(value));\n}\n\nexport function isBeforeYear(date: Date, value: Date) {\n return isBefore(date, startOfYear(value));\n}\n\nexport function isBeforeMonth(value: Date, comparing: Date): boolean {\n return isBefore(value, startOfMonth(comparing));\n}\n\nexport function isAfterMonth(value: Date, comparing: Date): boolean {\n return isAfter(value, startOfMonth(comparing));\n}\n\nexport function isAfterYear(date: Date, value: Date) {\n return isAfter(date, endOfYear(value));\n}\n\nexport function isWithinRange(date: Date, [start, end]: [Date, Date]) {\n return isWithinInterval(date, {\n start,\n end\n });\n}\n\nexport function formatNumber(numberToFormat: string) {\n return numberToFormat;\n}\n\nexport function getMinutes(date: Date) {\n return dateFnsGetMinutes(date);\n}\n\nexport function getDate(date: Date) {\n return dateFnsGetDate(date);\n}\n\nexport function setDate(date: Date, count: number) {\n return dateFnsSetDate(date, count);\n}\n\nexport function getWeek(date: Date) {\n return dateFnsGetWeek(date);\n}\n\nexport function getMonth(date: Date) {\n return dateFnsGetMonth(date);\n}\n\nexport function getDaysInMonth(date: Date) {\n return dateFnsGetDaysInMonth(date);\n}\n\nexport function setMonth(date: Date, count: number) {\n return dateFnsSetMonth(date, count);\n}\n\nexport function getMeridiemText(meridiem: \"am\" | \"pm\") {\n return meridiem === \"am\" ? \"AM\" : \"PM\";\n}\n\nexport function getNextMonth(date: Date) {\n return addMonths(date, 1);\n}\n\nexport function getPreviousMonth(date: Date) {\n return addMonths(date, -1);\n}\n\nexport function getMonthArray(date: Date) {\n const firstMonth = startOfYear(date);\n const monthArray = [firstMonth];\n\n while (monthArray.length < 12) {\n const prevMonth = monthArray[monthArray.length - 1]!;\n monthArray.push(getNextMonth(prevMonth));\n }\n\n return monthArray;\n}\n\nexport function mergeDateAndTime(date: Date, time: Date) {\n return setSeconds(\n setMinutes(setHours(date, getHours(time)), getMinutes(time)),\n getSeconds(time)\n );\n}\n\nexport function getWeekdays() {\n const now = new Date();\n\n return eachDayOfInterval({\n start: startOfWeek(now),\n end: endOfWeek(now)\n }).map(day => formatByString(day, \"EEEEEE\"));\n}\n\nexport function getWeekArray(date: Date) {\n const start = startOfWeek(startOfMonth(date));\n const end = endOfWeek(endOfMonth(date));\n let count = 0;\n let current = start;\n const nestedWeeks: Date[][] = [];\n let lastDay = null as null | number;\n while (isBefore(current, end)) {\n const weekNumber = Math.floor(count / 7);\n nestedWeeks[weekNumber] ??= [];\n const day = dateFnsGetDay(current);\n if (lastDay !== day) {\n lastDay = day;\n nestedWeeks[weekNumber].push(current);\n count += 1;\n }\n current = addDays(current, 1);\n }\n return nestedWeeks;\n}\n\nexport function getYearRange(start: Date, end: Date) {\n const startDate = startOfYear(start);\n const endDate = endOfYear(end);\n const years: Date[] = [];\n\n let current = startDate;\n while (isBefore(current, endDate)) {\n years.push(current);\n current = addYears(current, 1);\n }\n return years;\n}\n\n\n`;\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAgB,cAAc,SAA4B;AACxD,QAAO;;;;aAII,QAAQ,OAAO,UAAU;;;EAGpC,cAAc,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA8CrB,QAAQ,IAAI,OAAO,gBAAgB,WAAW,KAAK,GAAG,IAAI,OAC3D,4CACC,QAAQ,IAAI,OAAO,kBAAkB,QACtC"}