@powerlines/plugin-date 0.12.426 → 0.12.428

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 (58) hide show
  1. package/package.json +5 -5
  2. package/dist/_virtual/_rolldown/runtime.cjs +0 -29
  3. package/dist/_virtual/_rolldown/runtime.mjs +0 -3
  4. package/dist/components/date-fns.cjs +0 -528
  5. package/dist/components/date-fns.d.cts +0 -13
  6. package/dist/components/date-fns.d.cts.map +0 -1
  7. package/dist/components/date-fns.d.mts +0 -13
  8. package/dist/components/date-fns.d.mts.map +0 -1
  9. package/dist/components/date-fns.mjs +0 -528
  10. package/dist/components/date-fns.mjs.map +0 -1
  11. package/dist/components/dayjs.cjs +0 -473
  12. package/dist/components/dayjs.d.cts +0 -13
  13. package/dist/components/dayjs.d.cts.map +0 -1
  14. package/dist/components/dayjs.d.mts +0 -13
  15. package/dist/components/dayjs.d.mts.map +0 -1
  16. package/dist/components/dayjs.mjs +0 -473
  17. package/dist/components/dayjs.mjs.map +0 -1
  18. package/dist/components/index.cjs +0 -4
  19. package/dist/components/index.d.cts +0 -4
  20. package/dist/components/index.d.mts +0 -4
  21. package/dist/components/index.mjs +0 -6
  22. package/dist/components/luxon.cjs +0 -477
  23. package/dist/components/luxon.d.cts +0 -13
  24. package/dist/components/luxon.d.cts.map +0 -1
  25. package/dist/components/luxon.d.mts +0 -13
  26. package/dist/components/luxon.d.mts.map +0 -1
  27. package/dist/components/luxon.mjs +0 -477
  28. package/dist/components/luxon.mjs.map +0 -1
  29. package/dist/components/moment.cjs +0 -463
  30. package/dist/components/moment.d.cts +0 -13
  31. package/dist/components/moment.d.cts.map +0 -1
  32. package/dist/components/moment.d.mts +0 -13
  33. package/dist/components/moment.d.mts.map +0 -1
  34. package/dist/components/moment.mjs +0 -463
  35. package/dist/components/moment.mjs.map +0 -1
  36. package/dist/index.cjs +0 -67
  37. package/dist/index.d.cts +0 -21
  38. package/dist/index.d.cts.map +0 -1
  39. package/dist/index.d.mts +0 -21
  40. package/dist/index.d.mts.map +0 -1
  41. package/dist/index.mjs +0 -59
  42. package/dist/index.mjs.map +0 -1
  43. package/dist/types/index.cjs +0 -0
  44. package/dist/types/index.d.cts +0 -3
  45. package/dist/types/index.d.mts +0 -3
  46. package/dist/types/index.mjs +0 -1
  47. package/dist/types/plugin.cjs +0 -0
  48. package/dist/types/plugin.d.cts +0 -44
  49. package/dist/types/plugin.d.cts.map +0 -1
  50. package/dist/types/plugin.d.mts +0 -44
  51. package/dist/types/plugin.d.mts.map +0 -1
  52. package/dist/types/plugin.mjs +0 -1
  53. package/dist/types/runtime.cjs +0 -0
  54. package/dist/types/runtime.d.cts +0 -712
  55. package/dist/types/runtime.d.cts.map +0 -1
  56. package/dist/types/runtime.d.mts +0 -712
  57. package/dist/types/runtime.d.mts.map +0 -1
  58. package/dist/types/runtime.mjs +0 -1
@@ -1,463 +0,0 @@
1
- import { getFileHeader } from "powerlines/lib/utilities/file-header";
2
-
3
- //#region src/components/moment.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 momentModule(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 defaultMoment, { LongDateFormatKey } from "moment";
21
- import {
22
- StormDateInterface,
23
- DateFormats,
24
- TimeUnit
25
- } from "@powerlines/plugin-date/types/runtime";
26
-
27
- type Moment = defaultMoment.Moment;
28
-
29
- export const formats: DateFormats = {
30
- normalDateWithWeekday: "ddd, MMM D",
31
- normalDate: "D MMMM",
32
- shortDate: "MMM D",
33
- monthAndDate: "MMMM D",
34
- dayOfMonth: "D",
35
- year: "YYYY",
36
- month: "MMMM",
37
- monthShort: "MMM",
38
- monthAndYear: "MMMM YYYY",
39
- weekday: "dddd",
40
- weekdayShort: "ddd",
41
- minutes: "mm",
42
- hours12h: "hh",
43
- hours24h: "HH",
44
- seconds: "ss",
45
- fullTime: "LT",
46
- fullTime12h: "hh:mm A",
47
- fullTime24h: "HH:mm",
48
- fullDate: "ll",
49
- fullDateWithWeekday: "dddd, LL",
50
- fullDateTime: "lll",
51
- fullDateTime12h: "ll hh:mm A",
52
- fullDateTime24h: "ll HH:mm",
53
- keyboardDate: "L",
54
- keyboardDateTime: "L LT",
55
- keyboardDateTime12h: "L hh:mm A",
56
- keyboardDateTime24h: "L HH:mm",
57
- systemDateTime: "L HH:mm:ss.SSS",
58
- filePathDateTime: "L_HH-mm-ss-SSS"
59
- };
60
-
61
- export let locale = "${context.env.parsed.DEFAULT_LOCALE || context.workspaceConfig.locale ? `${context.env.parsed.DEFAULT_LOCALE || context.workspaceConfig.locale}` : "en-US"}";
62
-
63
- export const type = "moment";
64
-
65
- const moment = defaultMoment;
66
-
67
- /**
68
- * Creates a date object using the provided value.
69
- *
70
- * @remarks
71
- * 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.
72
- *
73
- * @example
74
- * \`\`\`ts
75
- * import { createDate } from "storm:date";
76
- *
77
- * const date = createDate("2023-10-01");
78
- * console.log(date.format("YYYY-MM-DD")); // Outputs: 2023-10-01
79
- * \`\`\`
80
- *
81
- * @param value - The value to create the date object from.
82
- * @returns A date object or \`null\` if the value is \`null\`.
83
- */
84
- export function createDate<
85
- TArg extends unknown = undefined,
86
- TResultingDate extends unknown = TArg extends null
87
- ? null
88
- : TArg extends undefined
89
- ? defaultMoment.Moment
90
- : defaultMoment.Moment | null
91
- >(value?: TArg): TResultingDate {
92
- if (value === null) {
93
- return null as TResultingDate;
94
- }
95
-
96
- const _moment = moment(value);
97
- if (locale) {
98
- _moment.locale(locale);
99
- }
100
-
101
- return _moment as TResultingDate;
102
- }
103
-
104
-
105
- export function is12HourCycleInCurrentLocale(): boolean {
106
- return /A|a/.test(
107
- moment.localeData(getCurrentLocaleCode()).longDateFormat("LT")
108
- );
109
- };
110
-
111
- export function getFormatHelperText(format: string) {
112
- // @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
113
- const localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
114
-
115
- return (
116
- format
117
- .match(localFormattingTokens)
118
- ?.map((token) => {
119
- const firstCharacter = token[0];
120
- if (firstCharacter === "L" || firstCharacter === ";") {
121
- return moment
122
- .localeData(getCurrentLocaleCode())
123
- .longDateFormat(token as LongDateFormatKey);
124
- }
125
-
126
- return token;
127
- })
128
- .join("")
129
- .replace(/a/gi, "(a|p)m")
130
- .toLocaleLowerCase() ?? format
131
- );
132
- };
133
-
134
- export function getCurrentLocaleCode() {
135
- return locale || moment.locale();
136
- };
137
-
138
- export function parseISO(isoString: string) {
139
- return moment(isoString, true);
140
- };
141
-
142
- export function toISO(value: Moment) {
143
- return value.toISOString();
144
- };
145
-
146
- export function parse(value: string, format: string) {
147
- if (value === "") {
148
- return null;
149
- }
150
-
151
- if (locale) {
152
- return moment(value, format, locale, true);
153
- }
154
-
155
- return moment(value, format, true);
156
- };
157
-
158
- export function toJsDate(value: Moment) {
159
- return value.toDate();
160
- };
161
-
162
- export function isValid(value: any) {
163
- return moment(value).isValid();
164
- };
165
-
166
- export function isNull(date: Moment) {
167
- return date === null;
168
- };
169
-
170
- export function getDiff(date: Moment, comparing: Moment | string, unit?: TimeUnit) {
171
- if (!moment(comparing).isValid()) {
172
- return 0;
173
- }
174
-
175
- return date.diff(comparing, unit);
176
- };
177
-
178
- export function isAfter(date: Moment, value: Moment) {
179
- return date.isAfter(value);
180
- };
181
-
182
- export function isBefore(date: Moment, value: Moment) {
183
- return date.isBefore(value);
184
- };
185
-
186
- export function isAfterDay(date: Moment, value: Moment) {
187
- return date.isAfter(value, "day");
188
- };
189
-
190
- export function isBeforeDay(date: Moment, value: Moment) {
191
- return date.isBefore(value, "day");
192
- };
193
-
194
- export function isBeforeMonth(date: Moment, value: Moment) {
195
- return date.isBefore(value, "month");
196
- };
197
-
198
- export function isAfterMonth(date: Moment, value: Moment) {
199
- return date.isAfter(value, "month");
200
- };
201
-
202
- export function isBeforeYear(date: Moment, value: Moment) {
203
- return date.isBefore(value, "year");
204
- };
205
-
206
- export function isAfterYear(date: Moment, value: Moment) {
207
- return date.isAfter(value, "year");
208
- };
209
-
210
- export function startOfDay(date: Moment) {
211
- return date.clone().startOf("day");
212
- };
213
-
214
- export function endOfDay(date: Moment) {
215
- return date.clone().endOf("day");
216
- };
217
-
218
- export function format(date: Moment, formatKey: keyof DateFormats) {
219
- return formatByString(date, formats[formatKey]);
220
- };
221
-
222
- export function formatByString(date: Moment, formatString: string) {
223
- const clonedDate = date.clone();
224
- if (locale) {
225
- clonedDate.locale(locale);
226
- }
227
- return clonedDate.format(formatString);
228
- };
229
-
230
- export function formatNumber(numberToFormat: string) {
231
- return numberToFormat;
232
- };
233
-
234
- export function getHours(date: Moment) {
235
- return date.get("hours");
236
- };
237
-
238
- export function addSeconds(date: Moment, count: number) {
239
- return count < 0
240
- ? date.clone().subtract(Math.abs(count), "seconds")
241
- : date.clone().add(count, "seconds");
242
- };
243
-
244
- export function addMinutes(date: Moment, count: number) {
245
- return count < 0
246
- ? date.clone().subtract(Math.abs(count), "minutes")
247
- : date.clone().add(count, "minutes");
248
- };
249
-
250
- export function addHours(date: Moment, count: number) {
251
- return count < 0
252
- ? date.clone().subtract(Math.abs(count), "hours")
253
- : date.clone().add(count, "hours");
254
- };
255
-
256
- export function addDays(date: Moment, count: number) {
257
- return count < 0
258
- ? date.clone().subtract(Math.abs(count), "days")
259
- : date.clone().add(count, "days");
260
- };
261
-
262
- export function addWeeks(date: Moment, count: number) {
263
- return count < 0
264
- ? date.clone().subtract(Math.abs(count), "weeks")
265
- : date.clone().add(count, "weeks");
266
- };
267
-
268
- export function addMonths(date: Moment, count: number) {
269
- return count < 0
270
- ? date.clone().subtract(Math.abs(count), "months")
271
- : date.clone().add(count, "months");
272
- };
273
-
274
- export function addYears(date: Moment, count: number) {
275
- return count < 0
276
- ? date.clone().subtract(Math.abs(count), "years")
277
- : date.clone().add(count, "years");
278
- };
279
-
280
- export function setHours(date: Moment, count: number) {
281
- return date.clone().hours(count);
282
- };
283
-
284
- export function getMinutes(date: Moment) {
285
- return date.get("minutes");
286
- };
287
-
288
- export function setMinutes(date: Moment, count: number) {
289
- return date.clone().minutes(count);
290
- };
291
-
292
- export function getSeconds(date: Moment) {
293
- return date.get("seconds");
294
- };
295
-
296
- export function setSeconds(date: Moment, count: number) {
297
- return date.clone().seconds(count);
298
- };
299
-
300
- export function getWeek(date: Moment) {
301
- return date.get("week");
302
- };
303
-
304
- export function getMonth(date: Moment) {
305
- return date.get("month");
306
- };
307
-
308
- export function getDaysInMonth(date: Moment) {
309
- return date.daysInMonth();
310
- };
311
-
312
- export function isSameDay(date: Moment, comparing: Moment) {
313
- return date.isSame(comparing, "day");
314
- };
315
-
316
- export function isSameMonth(date: Moment, comparing: Moment) {
317
- return date.isSame(comparing, "month");
318
- };
319
-
320
- export function isSameYear(date: Moment, comparing: Moment) {
321
- return date.isSame(comparing, "year");
322
- };
323
-
324
- export function isSameHour(date: Moment, comparing: Moment) {
325
- return date.isSame(comparing, "hour");
326
- };
327
-
328
- export function setMonth(date: Moment, count: number) {
329
- return date.clone().month(count);
330
- };
331
-
332
- export function getMeridiemText(meridiem: "am" | "pm") {
333
- if (is12HourCycleInCurrentLocale()) {
334
- // AM/PM translation only possible in those who have 12 hour cycle in locale.
335
- return moment
336
- .localeData(getCurrentLocaleCode())
337
- .meridiem(meridiem === "am" ? 0 : 13, 0, false);
338
- }
339
-
340
- return meridiem === "am" ? "AM" : "PM"; // fallback for de, ru, ...etc
341
- };
342
-
343
- export function startOfYear(date: Moment) {
344
- return date.clone().startOf("year");
345
- };
346
-
347
- export function endOfYear(date: Moment) {
348
- return date.clone().endOf("year");
349
- };
350
-
351
- export function startOfMonth(date: Moment) {
352
- return date.clone().startOf("month");
353
- };
354
-
355
- export function endOfMonth(date: Moment) {
356
- return date.clone().endOf("month");
357
- };
358
-
359
- export function startOfWeek(date: Moment) {
360
- return date.clone().startOf("week");
361
- };
362
-
363
- export function endOfWeek(date: Moment) {
364
- return date.clone().endOf("week");
365
- };
366
-
367
- export function getNextMonth(date: Moment) {
368
- return date.clone().add(1, "month");
369
- };
370
-
371
- export function getPreviousMonth(date: Moment) {
372
- return date.clone().subtract(1, "month");
373
- };
374
-
375
- export function getMonthArray(date: Moment) {
376
- const firstMonth = date.clone().startOf("year");
377
- const monthArray = [firstMonth];
378
-
379
- while (monthArray.length < 12) {
380
- const prevMonth = monthArray[monthArray.length - 1];
381
- monthArray.push(getNextMonth(prevMonth));
382
- }
383
-
384
- return monthArray;
385
- };
386
-
387
- export function getYear(date: Moment) {
388
- return date.get("year");
389
- };
390
-
391
- export function setYear(date: Moment, year: number) {
392
- return date.clone().set("year", year);
393
- };
394
-
395
- export function getDate(date: Moment) {
396
- return date.get("date");
397
- };
398
-
399
- export function setDate(date: Moment, day: number) {
400
- return date.clone().set("date", day);
401
- };
402
-
403
- export function mergeDateAndTime(date: Moment, time: Moment) {
404
- return date.hour(time.hour()).minute(time.minute()).second(time.second());
405
- };
406
-
407
- export function getWeekdays() {
408
- return moment.weekdaysShort(true);
409
- };
410
-
411
- export function isEqual(value: any, comparing: any) {
412
- if (value === null && comparing === null) {
413
- return true;
414
- }
415
-
416
- return moment(value).isSame(comparing);
417
- };
418
-
419
- export function getWeekArray(date: Moment) {
420
- const start = date.clone().startOf("month").startOf("week");
421
- const end = date.clone().endOf("month").endOf("week");
422
-
423
- let count = 0;
424
- let current = start;
425
- const nestedWeeks: Moment[][] = [];
426
-
427
- while (current.isBefore(end)) {
428
- const weekNumber = Math.floor(count / 7);
429
- nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
430
- nestedWeeks[weekNumber].push(current);
431
-
432
- current = current.clone().add(1, "day");
433
- count += 1;
434
- }
435
-
436
- return nestedWeeks;
437
- };
438
-
439
- export function getYearRange(start: Moment, end: Moment) {
440
- const startDate = moment(start).startOf("year");
441
- const endDate = moment(end).endOf("year");
442
- const years: Moment[] = [];
443
-
444
- let current = startDate;
445
- while (current.isBefore(endDate)) {
446
- years.push(current);
447
- current = current.clone().add(1, "year");
448
- }
449
-
450
- return years;
451
- };
452
-
453
- export function isWithinRange(date: Moment, [start, end]: [Moment, Moment]) {
454
- return date.isBetween(start, end, null, "[]");
455
- };
456
-
457
-
458
- `;
459
- }
460
-
461
- //#endregion
462
- export { momentModule };
463
- //# sourceMappingURL=moment.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"moment.mjs","names":[],"sources":["../../src/components/moment.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 momentModule(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 defaultMoment, { LongDateFormatKey } from \"moment\";\nimport {\n StormDateInterface,\n DateFormats,\n TimeUnit\n} from \"@powerlines/plugin-date/types/runtime\";\n\ntype Moment = defaultMoment.Moment;\n\nexport const formats: DateFormats = {\n normalDateWithWeekday: \"ddd, MMM D\",\n normalDate: \"D MMMM\",\n shortDate: \"MMM D\",\n monthAndDate: \"MMMM D\",\n dayOfMonth: \"D\",\n year: \"YYYY\",\n month: \"MMMM\",\n monthShort: \"MMM\",\n monthAndYear: \"MMMM YYYY\",\n weekday: \"dddd\",\n weekdayShort: \"ddd\",\n minutes: \"mm\",\n hours12h: \"hh\",\n hours24h: \"HH\",\n seconds: \"ss\",\n fullTime: \"LT\",\n fullTime12h: \"hh:mm A\",\n fullTime24h: \"HH:mm\",\n fullDate: \"ll\",\n fullDateWithWeekday: \"dddd, LL\",\n fullDateTime: \"lll\",\n fullDateTime12h: \"ll hh:mm A\",\n fullDateTime24h: \"ll HH:mm\",\n keyboardDate: \"L\",\n keyboardDateTime: \"L LT\",\n keyboardDateTime12h: \"L hh:mm A\",\n keyboardDateTime24h: \"L HH:mm\",\n systemDateTime: \"L HH:mm:ss.SSS\",\n filePathDateTime: \"L_HH-mm-ss-SSS\"\n};\n\nexport let locale = \"${\n context.env.parsed.DEFAULT_LOCALE || context.workspaceConfig.locale\n ? `${context.env.parsed.DEFAULT_LOCALE || context.workspaceConfig.locale}`\n : \"en-US\"\n }\";\n\nexport const type = \"moment\";\n\nconst moment = defaultMoment;\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 extends unknown = undefined,\n TResultingDate extends unknown = TArg extends null\n ? null\n : TArg extends undefined\n ? defaultMoment.Moment\n : defaultMoment.Moment | null\n>(value?: TArg): TResultingDate {\n if (value === null) {\n return null as TResultingDate;\n }\n\n const _moment = moment(value);\n if (locale) {\n _moment.locale(locale);\n }\n\n return _moment as TResultingDate;\n}\n\n\nexport function is12HourCycleInCurrentLocale(): boolean {\n return /A|a/.test(\n moment.localeData(getCurrentLocaleCode()).longDateFormat(\"LT\")\n );\n};\n\nexport function getFormatHelperText(format: string) {\n // @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6\n const localFormattingTokens = /(\\[[^\\[]*\\])|(\\\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;\n\n return (\n format\n .match(localFormattingTokens)\n ?.map((token) => {\n const firstCharacter = token[0];\n if (firstCharacter === \"L\" || firstCharacter === \";\") {\n return moment\n .localeData(getCurrentLocaleCode())\n .longDateFormat(token as LongDateFormatKey);\n }\n\n return token;\n })\n .join(\"\")\n .replace(/a/gi, \"(a|p)m\")\n .toLocaleLowerCase() ?? format\n );\n};\n\nexport function getCurrentLocaleCode() {\n return locale || moment.locale();\n};\n\nexport function parseISO(isoString: string) {\n return moment(isoString, true);\n};\n\nexport function toISO(value: Moment) {\n return value.toISOString();\n};\n\nexport function parse(value: string, format: string) {\n if (value === \"\") {\n return null;\n }\n\n if (locale) {\n return moment(value, format, locale, true);\n }\n\n return moment(value, format, true);\n};\n\nexport function toJsDate(value: Moment) {\n return value.toDate();\n};\n\nexport function isValid(value: any) {\n return moment(value).isValid();\n};\n\nexport function isNull(date: Moment) {\n return date === null;\n};\n\nexport function getDiff(date: Moment, comparing: Moment | string, unit?: TimeUnit) {\n if (!moment(comparing).isValid()) {\n return 0;\n }\n\n return date.diff(comparing, unit);\n};\n\nexport function isAfter(date: Moment, value: Moment) {\n return date.isAfter(value);\n};\n\nexport function isBefore(date: Moment, value: Moment) {\n return date.isBefore(value);\n};\n\nexport function isAfterDay(date: Moment, value: Moment) {\n return date.isAfter(value, \"day\");\n};\n\nexport function isBeforeDay(date: Moment, value: Moment) {\n return date.isBefore(value, \"day\");\n};\n\nexport function isBeforeMonth(date: Moment, value: Moment) {\n return date.isBefore(value, \"month\");\n};\n\nexport function isAfterMonth(date: Moment, value: Moment) {\n return date.isAfter(value, \"month\");\n};\n\nexport function isBeforeYear(date: Moment, value: Moment) {\n return date.isBefore(value, \"year\");\n};\n\nexport function isAfterYear(date: Moment, value: Moment) {\n return date.isAfter(value, \"year\");\n};\n\nexport function startOfDay(date: Moment) {\n return date.clone().startOf(\"day\");\n};\n\nexport function endOfDay(date: Moment) {\n return date.clone().endOf(\"day\");\n};\n\nexport function format(date: Moment, formatKey: keyof DateFormats) {\n return formatByString(date, formats[formatKey]);\n};\n\nexport function formatByString(date: Moment, formatString: string) {\n const clonedDate = date.clone();\n if (locale) {\n clonedDate.locale(locale);\n }\n return clonedDate.format(formatString);\n};\n\nexport function formatNumber(numberToFormat: string) {\n return numberToFormat;\n};\n\nexport function getHours(date: Moment) {\n return date.get(\"hours\");\n};\n\nexport function addSeconds(date: Moment, count: number) {\n return count < 0\n ? date.clone().subtract(Math.abs(count), \"seconds\")\n : date.clone().add(count, \"seconds\");\n};\n\nexport function addMinutes(date: Moment, count: number) {\n return count < 0\n ? date.clone().subtract(Math.abs(count), \"minutes\")\n : date.clone().add(count, \"minutes\");\n};\n\nexport function addHours(date: Moment, count: number) {\n return count < 0\n ? date.clone().subtract(Math.abs(count), \"hours\")\n : date.clone().add(count, \"hours\");\n};\n\nexport function addDays(date: Moment, count: number) {\n return count < 0\n ? date.clone().subtract(Math.abs(count), \"days\")\n : date.clone().add(count, \"days\");\n};\n\nexport function addWeeks(date: Moment, count: number) {\n return count < 0\n ? date.clone().subtract(Math.abs(count), \"weeks\")\n : date.clone().add(count, \"weeks\");\n};\n\nexport function addMonths(date: Moment, count: number) {\n return count < 0\n ? date.clone().subtract(Math.abs(count), \"months\")\n : date.clone().add(count, \"months\");\n};\n\nexport function addYears(date: Moment, count: number) {\n return count < 0\n ? date.clone().subtract(Math.abs(count), \"years\")\n : date.clone().add(count, \"years\");\n};\n\nexport function setHours(date: Moment, count: number) {\n return date.clone().hours(count);\n};\n\nexport function getMinutes(date: Moment) {\n return date.get(\"minutes\");\n};\n\nexport function setMinutes(date: Moment, count: number) {\n return date.clone().minutes(count);\n};\n\nexport function getSeconds(date: Moment) {\n return date.get(\"seconds\");\n};\n\nexport function setSeconds(date: Moment, count: number) {\n return date.clone().seconds(count);\n};\n\nexport function getWeek(date: Moment) {\n return date.get(\"week\");\n};\n\nexport function getMonth(date: Moment) {\n return date.get(\"month\");\n};\n\nexport function getDaysInMonth(date: Moment) {\n return date.daysInMonth();\n};\n\nexport function isSameDay(date: Moment, comparing: Moment) {\n return date.isSame(comparing, \"day\");\n};\n\nexport function isSameMonth(date: Moment, comparing: Moment) {\n return date.isSame(comparing, \"month\");\n};\n\nexport function isSameYear(date: Moment, comparing: Moment) {\n return date.isSame(comparing, \"year\");\n};\n\nexport function isSameHour(date: Moment, comparing: Moment) {\n return date.isSame(comparing, \"hour\");\n};\n\nexport function setMonth(date: Moment, count: number) {\n return date.clone().month(count);\n};\n\nexport function getMeridiemText(meridiem: \"am\" | \"pm\") {\n if (is12HourCycleInCurrentLocale()) {\n // AM/PM translation only possible in those who have 12 hour cycle in locale.\n return moment\n .localeData(getCurrentLocaleCode())\n .meridiem(meridiem === \"am\" ? 0 : 13, 0, false);\n }\n\n return meridiem === \"am\" ? \"AM\" : \"PM\"; // fallback for de, ru, ...etc\n};\n\nexport function startOfYear(date: Moment) {\n return date.clone().startOf(\"year\");\n};\n\nexport function endOfYear(date: Moment) {\n return date.clone().endOf(\"year\");\n};\n\nexport function startOfMonth(date: Moment) {\n return date.clone().startOf(\"month\");\n};\n\nexport function endOfMonth(date: Moment) {\n return date.clone().endOf(\"month\");\n};\n\nexport function startOfWeek(date: Moment) {\n return date.clone().startOf(\"week\");\n};\n\nexport function endOfWeek(date: Moment) {\n return date.clone().endOf(\"week\");\n};\n\nexport function getNextMonth(date: Moment) {\n return date.clone().add(1, \"month\");\n};\n\nexport function getPreviousMonth(date: Moment) {\n return date.clone().subtract(1, \"month\");\n};\n\nexport function getMonthArray(date: Moment) {\n const firstMonth = date.clone().startOf(\"year\");\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 getYear(date: Moment) {\n return date.get(\"year\");\n};\n\nexport function setYear(date: Moment, year: number) {\n return date.clone().set(\"year\", year);\n};\n\nexport function getDate(date: Moment) {\n return date.get(\"date\");\n};\n\nexport function setDate(date: Moment, day: number) {\n return date.clone().set(\"date\", day);\n};\n\nexport function mergeDateAndTime(date: Moment, time: Moment) {\n return date.hour(time.hour()).minute(time.minute()).second(time.second());\n};\n\nexport function getWeekdays() {\n return moment.weekdaysShort(true);\n};\n\nexport function isEqual(value: any, comparing: any) {\n if (value === null && comparing === null) {\n return true;\n }\n\n return moment(value).isSame(comparing);\n};\n\nexport function getWeekArray(date: Moment) {\n const start = date.clone().startOf(\"month\").startOf(\"week\");\n const end = date.clone().endOf(\"month\").endOf(\"week\");\n\n let count = 0;\n let current = start;\n const nestedWeeks: Moment[][] = [];\n\n while (current.isBefore(end)) {\n const weekNumber = Math.floor(count / 7);\n nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];\n nestedWeeks[weekNumber].push(current);\n\n current = current.clone().add(1, \"day\");\n count += 1;\n }\n\n return nestedWeeks;\n};\n\nexport function getYearRange(start: Moment, end: Moment) {\n const startDate = moment(start).startOf(\"year\");\n const endDate = moment(end).endOf(\"year\");\n const years: Moment[] = [];\n\n let current = startDate;\n while (current.isBefore(endDate)) {\n years.push(current);\n current = current.clone().add(1, \"year\");\n }\n\n return years;\n};\n\nexport function isWithinRange(date: Moment, [start, end]: [Moment, Moment]) {\n return date.isBetween(start, end, null, \"[]\");\n};\n\n\n`;\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAgB,aAAa,SAA4B;AACvD,QAAO;;;;aAII,QAAQ,OAAO,UAAU;;;EAGpC,cAAc,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA4CrB,QAAQ,IAAI,OAAO,kBAAkB,QAAQ,gBAAgB,SACzD,GAAG,QAAQ,IAAI,OAAO,kBAAkB,QAAQ,gBAAgB,WAChE,QACL"}
package/dist/index.cjs DELETED
@@ -1,67 +0,0 @@
1
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- const require_date_fns = require('./components/date-fns.cjs');
4
- const require_dayjs = require('./components/dayjs.cjs');
5
- const require_luxon = require('./components/luxon.cjs');
6
- const require_moment = require('./components/moment.cjs');
7
- require('./components/index.cjs');
8
- let _powerlines_plugin_env = require("@powerlines/plugin-env");
9
- _powerlines_plugin_env = require_runtime.__toESM(_powerlines_plugin_env);
10
- let defu = require("defu");
11
- defu = require_runtime.__toESM(defu);
12
-
13
- //#region src/index.ts
14
- /**
15
- * A Powerlines plugin to assist in developing other Powerlines plugins.
16
- */
17
- function plugin(options = {}) {
18
- return [(0, _powerlines_plugin_env.default)(options.env), {
19
- name: "date",
20
- async config() {
21
- this.debug("Providing default configuration for the Powerlines `date` build plugin.");
22
- const config = { date: (0, defu.default)(options, { type: "date-fns" }) };
23
- if (!config.date.type || ![
24
- "date-fns",
25
- "dayjs",
26
- "luxon",
27
- "moment"
28
- ].includes(config.date.type)) {
29
- if (config.date.type) this.warn(`Invalid date library type "${config.date.type}" specified. Defaulting to "date-fns".`);
30
- config.date.type = "date-fns";
31
- }
32
- this.debug(`Using date library: ${config.date.type}`);
33
- return config;
34
- },
35
- async configResolved() {
36
- this.debug(`Environment plugin configuration has been resolved for the Powerlines project.`);
37
- this.dependencies[this.config.date.type] = "latest";
38
- },
39
- async prepare() {
40
- this.debug(`Preparing the Date runtime artifacts for the Powerlines project.`);
41
- let dateModule;
42
- switch (this.config.date.type) {
43
- case "dayjs":
44
- dateModule = require_dayjs.dayjsModule;
45
- break;
46
- case "luxon":
47
- dateModule = require_luxon.luxonModule;
48
- break;
49
- case "moment":
50
- dateModule = require_moment.momentModule;
51
- break;
52
- default:
53
- dateModule = require_date_fns.dateFnsModule;
54
- break;
55
- }
56
- await this.emitBuiltin(await Promise.resolve(dateModule(this)), "date");
57
- }
58
- }];
59
- }
60
-
61
- //#endregion
62
- exports.dateFnsModule = require_date_fns.dateFnsModule;
63
- exports.dayjsModule = require_dayjs.dayjsModule;
64
- exports.default = plugin;
65
- exports.plugin = plugin;
66
- exports.luxonModule = require_luxon.luxonModule;
67
- exports.momentModule = require_moment.momentModule;
package/dist/index.d.cts DELETED
@@ -1,21 +0,0 @@
1
- import { DateLibraryType, DatePluginContext, DatePluginOptions, DatePluginResolvedConfig, DatePluginUserConfig, __ΩDateLibraryType, __ΩDatePluginContext, __ΩDatePluginOptions, __ΩDatePluginResolvedConfig, __ΩDatePluginUserConfig } from "./types/plugin.cjs";
2
- import { dateFnsModule } from "./components/date-fns.cjs";
3
- import { dayjsModule } from "./components/dayjs.cjs";
4
- import { luxonModule } from "./components/luxon.cjs";
5
- import { momentModule } from "./components/moment.cjs";
6
- import { DateFormats, StormDateInterface, TimeUnit, __ΩDateFormats, __ΩStormDateInterface, __ΩTimeUnit } from "./types/runtime.cjs";
7
- import { Plugin } from "powerlines";
8
-
9
- //#region src/index.d.ts
10
- declare module "powerlines" {
11
- interface Config {
12
- date?: DatePluginOptions;
13
- }
14
- }
15
- /**
16
- * A Powerlines plugin to assist in developing other Powerlines plugins.
17
- */
18
- declare function plugin<TContext extends DatePluginContext = DatePluginContext>(options?: DatePluginOptions): Plugin<TContext>[];
19
- //#endregion
20
- export { DateFormats, DateLibraryType, DatePluginContext, DatePluginOptions, DatePluginResolvedConfig, DatePluginUserConfig, StormDateInterface, TimeUnit, __ΩDateFormats, __ΩDateLibraryType, __ΩDatePluginContext, __ΩDatePluginOptions, __ΩDatePluginResolvedConfig, __ΩDatePluginUserConfig, __ΩStormDateInterface, __ΩTimeUnit, dateFnsModule, dayjsModule, plugin as default, plugin, luxonModule, momentModule };
21
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;YAmCY,MAAA;IACR,IAAA,GAAO,iBAAA;EAAA;AAAA;;;AAJa;iBAWR,MAAA,kBAAwB,iBAAA,GAAoB,iBAAA,CAAA,CAC1D,OAAA,GAAS,iBAAA,GAmEJ,MAAA,CAAO,QAAA"}
package/dist/index.d.mts DELETED
@@ -1,21 +0,0 @@
1
- import { DateLibraryType, DatePluginContext, DatePluginOptions, DatePluginResolvedConfig, DatePluginUserConfig, __ΩDateLibraryType, __ΩDatePluginContext, __ΩDatePluginOptions, __ΩDatePluginResolvedConfig, __ΩDatePluginUserConfig } from "./types/plugin.mjs";
2
- import { dateFnsModule } from "./components/date-fns.mjs";
3
- import { dayjsModule } from "./components/dayjs.mjs";
4
- import { luxonModule } from "./components/luxon.mjs";
5
- import { momentModule } from "./components/moment.mjs";
6
- import { DateFormats, StormDateInterface, TimeUnit, __ΩDateFormats, __ΩStormDateInterface, __ΩTimeUnit } from "./types/runtime.mjs";
7
- import { Plugin } from "powerlines";
8
-
9
- //#region src/index.d.ts
10
- declare module "powerlines" {
11
- interface Config {
12
- date?: DatePluginOptions;
13
- }
14
- }
15
- /**
16
- * A Powerlines plugin to assist in developing other Powerlines plugins.
17
- */
18
- declare function plugin<TContext extends DatePluginContext = DatePluginContext>(options?: DatePluginOptions): Plugin<TContext>[];
19
- //#endregion
20
- export { DateFormats, DateLibraryType, DatePluginContext, DatePluginOptions, DatePluginResolvedConfig, DatePluginUserConfig, StormDateInterface, TimeUnit, __ΩDateFormats, __ΩDateLibraryType, __ΩDatePluginContext, __ΩDatePluginOptions, __ΩDatePluginResolvedConfig, __ΩDatePluginUserConfig, __ΩStormDateInterface, __ΩTimeUnit, dateFnsModule, dayjsModule, plugin as default, plugin, luxonModule, momentModule };
21
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;YAmCY,MAAA;IACR,IAAA,GAAO,iBAAA;EAAA;AAAA;;;AAJa;iBAWR,MAAA,kBAAwB,iBAAA,GAAoB,iBAAA,CAAA,CAC1D,OAAA,GAAS,iBAAA,GAmEJ,MAAA,CAAO,QAAA"}
package/dist/index.mjs DELETED
@@ -1,59 +0,0 @@
1
- import { dateFnsModule } from "./components/date-fns.mjs";
2
- import { dayjsModule } from "./components/dayjs.mjs";
3
- import { luxonModule } from "./components/luxon.mjs";
4
- import { momentModule } from "./components/moment.mjs";
5
- import "./components/index.mjs";
6
- import env from "@powerlines/plugin-env";
7
- import defu from "defu";
8
-
9
- //#region src/index.ts
10
- /**
11
- * A Powerlines plugin to assist in developing other Powerlines plugins.
12
- */
13
- function plugin(options = {}) {
14
- return [env(options.env), {
15
- name: "date",
16
- async config() {
17
- this.debug("Providing default configuration for the Powerlines `date` build plugin.");
18
- const config = { date: defu(options, { type: "date-fns" }) };
19
- if (!config.date.type || ![
20
- "date-fns",
21
- "dayjs",
22
- "luxon",
23
- "moment"
24
- ].includes(config.date.type)) {
25
- if (config.date.type) this.warn(`Invalid date library type "${config.date.type}" specified. Defaulting to "date-fns".`);
26
- config.date.type = "date-fns";
27
- }
28
- this.debug(`Using date library: ${config.date.type}`);
29
- return config;
30
- },
31
- async configResolved() {
32
- this.debug(`Environment plugin configuration has been resolved for the Powerlines project.`);
33
- this.dependencies[this.config.date.type] = "latest";
34
- },
35
- async prepare() {
36
- this.debug(`Preparing the Date runtime artifacts for the Powerlines project.`);
37
- let dateModule;
38
- switch (this.config.date.type) {
39
- case "dayjs":
40
- dateModule = dayjsModule;
41
- break;
42
- case "luxon":
43
- dateModule = luxonModule;
44
- break;
45
- case "moment":
46
- dateModule = momentModule;
47
- break;
48
- default:
49
- dateModule = dateFnsModule;
50
- break;
51
- }
52
- await this.emitBuiltin(await Promise.resolve(dateModule(this)), "date");
53
- }
54
- }];
55
- }
56
-
57
- //#endregion
58
- export { dateFnsModule, dayjsModule, plugin as default, plugin, luxonModule, momentModule };
59
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.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 env from \"@powerlines/plugin-env\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\nimport { dateFnsModule } from \"./components/date-fns\";\nimport { dayjsModule } from \"./components/dayjs\";\nimport { luxonModule } from \"./components/luxon\";\nimport { momentModule } from \"./components/moment\";\nimport {\n DatePluginContext,\n DatePluginOptions,\n DatePluginUserConfig\n} from \"./types/plugin\";\n\nexport * from \"./components\";\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n date?: DatePluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport function plugin<TContext extends DatePluginContext = DatePluginContext>(\n options: DatePluginOptions = {}\n) {\n return [\n env(options.env),\n {\n name: \"date\",\n async config() {\n this.debug(\n \"Providing default configuration for the Powerlines `date` build plugin.\"\n );\n\n const config = {\n date: defu(options, {\n type: \"date-fns\"\n })\n } as DatePluginUserConfig;\n\n if (\n !config.date!.type ||\n ![\"date-fns\", \"dayjs\", \"luxon\", \"moment\"].includes(config.date!.type)\n ) {\n if (config.date!.type) {\n this.warn(\n `Invalid date library type \"${config.date!.type}\" specified. Defaulting to \"date-fns\".`\n );\n }\n\n config.date!.type = \"date-fns\";\n }\n\n this.debug(`Using date library: ${config.date!.type}`);\n\n return config;\n },\n async configResolved() {\n this.debug(\n `Environment plugin configuration has been resolved for the Powerlines project.`\n );\n\n this.dependencies[this.config.date.type] = \"latest\";\n },\n async prepare() {\n this.debug(\n `Preparing the Date runtime artifacts for the Powerlines project.`\n );\n\n let dateModule!: (context: DatePluginContext) => string;\n switch (this.config.date.type) {\n case \"dayjs\":\n dateModule = dayjsModule;\n break;\n case \"luxon\":\n dateModule = luxonModule;\n break;\n case \"moment\":\n dateModule = momentModule;\n break;\n case \"date-fns\":\n default:\n // Default to date-fns if no type is specified or if the type is not recognized\n dateModule = dateFnsModule;\n break;\n }\n\n await this.emitBuiltin(await Promise.resolve(dateModule(this)), \"date\");\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;AA2CA,SAAgB,OACd,UAA6B,EAAE,EAC/B;AACA,QAAO,CACL,IAAI,QAAQ,IAAI,EAChB;EACE,MAAM;EACN,MAAM,SAAS;AACb,QAAK,MACH,0EACD;GAED,MAAM,SAAS,EACb,MAAM,KAAK,SAAS,EAClB,MAAM,YACP,CAAC,EACH;AAED,OACE,CAAC,OAAO,KAAM,QACd,CAAC;IAAC;IAAY;IAAS;IAAS;IAAS,CAAC,SAAS,OAAO,KAAM,KAAK,EACrE;AACA,QAAI,OAAO,KAAM,KACf,MAAK,KACH,8BAA8B,OAAO,KAAM,KAAK,wCACjD;AAGH,WAAO,KAAM,OAAO;;AAGtB,QAAK,MAAM,uBAAuB,OAAO,KAAM,OAAO;AAEtD,UAAO;;EAET,MAAM,iBAAiB;AACrB,QAAK,MACH,iFACD;AAED,QAAK,aAAa,KAAK,OAAO,KAAK,QAAQ;;EAE7C,MAAM,UAAU;AACd,QAAK,MACH,mEACD;GAED,IAAI;AACJ,WAAQ,KAAK,OAAO,KAAK,MAAzB;IACE,KAAK;AACH,kBAAa;AACb;IACF,KAAK;AACH,kBAAa;AACb;IACF,KAAK;AACH,kBAAa;AACb;IAEF;AAEE,kBAAa;AACb;;AAGJ,SAAM,KAAK,YAAY,MAAM,QAAQ,QAAQ,WAAW,KAAK,CAAC,EAAE,OAAO;;EAE1E,CACF"}
File without changes