@kikiutils/shared 18.0.1 → 18.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dist/buffer.d.ts +19 -21
  2. package/dist/buffer.d.ts.map +1 -1
  3. package/dist/buffer.js +18 -19
  4. package/dist/buffer.js.map +1 -1
  5. package/dist/classes/enhanced-date.d.ts +425 -0
  6. package/dist/classes/enhanced-date.d.ts.map +1 -0
  7. package/dist/classes/enhanced-date.js +591 -0
  8. package/dist/classes/enhanced-date.js.map +1 -0
  9. package/dist/classes/path.d.ts +211 -48
  10. package/dist/classes/path.d.ts.map +1 -1
  11. package/dist/classes/path.js +181 -52
  12. package/dist/classes/path.js.map +1 -1
  13. package/dist/classes/precision-number.d.ts +44 -39
  14. package/dist/classes/precision-number.d.ts.map +1 -1
  15. package/dist/classes/precision-number.js +51 -45
  16. package/dist/classes/precision-number.js.map +1 -1
  17. package/dist/classes/ssh-client.d.ts +3 -4
  18. package/dist/classes/ssh-client.d.ts.map +1 -1
  19. package/dist/classes/ssh-client.js +2 -2
  20. package/dist/classes/ssh-client.js.map +1 -1
  21. package/dist/clipboard.d.ts +25 -26
  22. package/dist/clipboard.d.ts.map +1 -1
  23. package/dist/clipboard.js +23 -23
  24. package/dist/clipboard.js.map +1 -1
  25. package/dist/consola.d.ts +12 -15
  26. package/dist/consola.d.ts.map +1 -1
  27. package/dist/consola.js +10 -12
  28. package/dist/consola.js.map +1 -1
  29. package/dist/crypto-hash.d.ts +65 -56
  30. package/dist/crypto-hash.d.ts.map +1 -1
  31. package/dist/crypto-hash.js +55 -45
  32. package/dist/crypto-hash.js.map +1 -1
  33. package/dist/datetime.d.ts +41 -53
  34. package/dist/datetime.d.ts.map +1 -1
  35. package/dist/datetime.js +53 -66
  36. package/dist/datetime.js.map +1 -1
  37. package/dist/element-plus.d.ts +13 -14
  38. package/dist/element-plus.d.ts.map +1 -1
  39. package/dist/element-plus.js +11 -11
  40. package/dist/element-plus.js.map +1 -1
  41. package/dist/enum.d.ts +39 -36
  42. package/dist/enum.d.ts.map +1 -1
  43. package/dist/enum.js +36 -32
  44. package/dist/enum.js.map +1 -1
  45. package/dist/env.d.ts +22 -15
  46. package/dist/env.d.ts.map +1 -1
  47. package/dist/env.js +20 -12
  48. package/dist/env.js.map +1 -1
  49. package/dist/event-awaiter.d.ts +47 -52
  50. package/dist/event-awaiter.d.ts.map +1 -1
  51. package/dist/event-awaiter.js +46 -50
  52. package/dist/event-awaiter.js.map +1 -1
  53. package/dist/general.d.ts +22 -17
  54. package/dist/general.d.ts.map +1 -1
  55. package/dist/general.js.map +1 -1
  56. package/dist/hash.d.ts +24 -21
  57. package/dist/hash.d.ts.map +1 -1
  58. package/dist/hash.js +20 -16
  59. package/dist/hash.js.map +1 -1
  60. package/dist/math.d.ts +20 -19
  61. package/dist/math.d.ts.map +1 -1
  62. package/dist/math.js +14 -12
  63. package/dist/math.js.map +1 -1
  64. package/dist/number.d.ts +10 -9
  65. package/dist/number.d.ts.map +1 -1
  66. package/dist/number.js +9 -7
  67. package/dist/number.js.map +1 -1
  68. package/dist/object.d.ts +22 -10
  69. package/dist/object.d.ts.map +1 -1
  70. package/dist/object.js +21 -8
  71. package/dist/object.js.map +1 -1
  72. package/dist/pino.d.ts +12 -15
  73. package/dist/pino.d.ts.map +1 -1
  74. package/dist/pino.js +10 -15
  75. package/dist/pino.js.map +1 -1
  76. package/dist/random.d.ts +17 -15
  77. package/dist/random.d.ts.map +1 -1
  78. package/dist/random.js +16 -13
  79. package/dist/random.js.map +1 -1
  80. package/dist/redis/script-runner.d.ts +57 -0
  81. package/dist/redis/script-runner.d.ts.map +1 -0
  82. package/dist/redis/script-runner.js +46 -0
  83. package/dist/redis/script-runner.js.map +1 -0
  84. package/dist/storages/lru/keyed-store.d.ts +18 -14
  85. package/dist/storages/lru/keyed-store.d.ts.map +1 -1
  86. package/dist/storages/lru/keyed-store.js +17 -12
  87. package/dist/storages/lru/keyed-store.js.map +1 -1
  88. package/dist/storages/redis/keyed-store.d.ts +11 -21
  89. package/dist/storages/redis/keyed-store.d.ts.map +1 -1
  90. package/dist/storages/redis/keyed-store.js +10 -19
  91. package/dist/storages/redis/keyed-store.js.map +1 -1
  92. package/dist/storages/redis/msgpack.d.ts +33 -13
  93. package/dist/storages/redis/msgpack.d.ts.map +1 -1
  94. package/dist/storages/redis/msgpack.js +32 -11
  95. package/dist/storages/redis/msgpack.js.map +1 -1
  96. package/dist/storages/redis/types.d.ts +34 -17
  97. package/dist/storages/redis/types.d.ts.map +1 -1
  98. package/dist/string.d.ts +12 -11
  99. package/dist/string.d.ts.map +1 -1
  100. package/dist/string.js +20 -15
  101. package/dist/string.js.map +1 -1
  102. package/dist/time.d.ts +26 -21
  103. package/dist/time.d.ts.map +1 -1
  104. package/dist/time.js +24 -18
  105. package/dist/time.js.map +1 -1
  106. package/dist/types/filtered-key-path.d.ts +4 -15
  107. package/dist/types/filtered-key-path.d.ts.map +1 -1
  108. package/dist/types/index.d.ts +10 -10
  109. package/dist/types/index.d.ts.map +1 -1
  110. package/dist/types/vue.d.ts +7 -7
  111. package/dist/types/vue.d.ts.map +1 -1
  112. package/dist/url.d.ts +15 -14
  113. package/dist/url.d.ts.map +1 -1
  114. package/dist/url.js +12 -10
  115. package/dist/url.js.map +1 -1
  116. package/dist/vue.d.ts +19 -21
  117. package/dist/vue.d.ts.map +1 -1
  118. package/dist/vue.js +15 -16
  119. package/dist/vue.js.map +1 -1
  120. package/dist/web.d.ts +14 -11
  121. package/dist/web.d.ts.map +1 -1
  122. package/dist/web.js +12 -8
  123. package/dist/web.js.map +1 -1
  124. package/package.json +20 -20
  125. package/src/buffer.ts +18 -19
  126. package/src/classes/enhanced-date.ts +665 -0
  127. package/src/classes/path.ts +232 -91
  128. package/src/classes/precision-number.ts +61 -53
  129. package/src/classes/ssh-client.ts +8 -5
  130. package/src/clipboard.ts +23 -23
  131. package/src/consola.ts +10 -12
  132. package/src/crypto-hash.ts +55 -45
  133. package/src/datetime.ts +65 -85
  134. package/src/element-plus.ts +11 -11
  135. package/src/enum.ts +36 -32
  136. package/src/env.ts +20 -12
  137. package/src/event-awaiter.ts +49 -50
  138. package/src/general.ts +20 -14
  139. package/src/hash.ts +20 -16
  140. package/src/math.ts +18 -16
  141. package/src/number.ts +9 -7
  142. package/src/object.ts +21 -8
  143. package/src/pino.ts +11 -15
  144. package/src/random.ts +16 -13
  145. package/src/redis/script-runner.ts +107 -0
  146. package/src/storages/lru/keyed-store.ts +17 -12
  147. package/src/storages/redis/keyed-store.ts +10 -19
  148. package/src/storages/redis/msgpack.ts +32 -11
  149. package/src/storages/redis/types.ts +32 -14
  150. package/src/string.ts +10 -8
  151. package/src/time.ts +24 -18
  152. package/src/types/filtered-key-path.ts +9 -14
  153. package/src/types/vue.ts +6 -5
  154. package/src/url.ts +12 -10
  155. package/src/vue.ts +15 -16
  156. package/src/web.ts +12 -8
@@ -1,83 +1,71 @@
1
- import { DateArg, Day, FormatOptions } from "date-fns";
1
+ import { EnhancedDate } from "./classes/enhanced-date.js";
2
+ import * as dateFns from "date-fns";
2
3
  //#region src/datetime.d.ts
3
- type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek' | 'today' | 'yesterday';
4
+ export type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek' | 'today' | 'yesterday';
4
5
  /**
5
- * Formats a given date, timestamp, or date string into a specified format.
6
+ * Formats a date using a date-fns pattern without changing the input.
6
7
  *
7
- * This function is a wrapper around `date-fns/format`.
8
+ * @remarks
9
+ * Formatting uses the system time zone unless configured through date-fns options.
10
+ * Invalid dates and unsupported patterns propagate date-fns exceptions.
8
11
  *
9
- * @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string
10
- * @param {string} [format] - The target format string
11
- * @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`
12
+ * @param date - The date, timestamp in milliseconds, or date string to format.
13
+ * @param format - The date-fns pattern. Defaults to `yyyy-MM-dd HH:mm:ss`.
14
+ * @param options - Formatting options passed to date-fns.
12
15
  *
13
- * @returns {string} The formatted date string
16
+ * @returns The formatted date string.
14
17
  *
15
18
  * @example
16
- * ```typescript
17
- * import { formatDate } from '@kikiutils/shared/datetime';
18
- *
19
- * // Format a Date object
20
- * console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10
21
19
  *
22
- * // Format a timestamp
23
- * console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15
20
+ * ```ts
21
+ * import { formatDate } from '@kikiutils/shared/datetime';
24
22
  *
25
- * // Format a date string
26
- * console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
23
+ * const date = new Date(2026, 0, 15, 12);
24
+ * console.log(formatDate(date, 'yyyy-MM-dd')); // => '2026-01-15'
27
25
  * ```
28
26
  */
29
- declare function formatDate(date: DateArg<Date> & {}, format?: string, options?: FormatOptions): string;
27
+ export declare function formatDate(date: dateFns.DateArg<Date>, format?: string, options?: dateFns.FormatOptions): string;
30
28
  /**
31
- * Get the date range (start and end) based on a given date and range type.
29
+ * Returns new start and end dates for a calendar range in the system time zone.
32
30
  *
33
- * Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.
31
+ * @remarks
32
+ * The reference date is unchanged. Boundaries are inclusive by default, ending at `23:59:59.999`.
33
+ * When `options.setEndDateToNextDayStart` is `true`, the end is the exclusive start of the next calendar day.
34
+ * `options.weekStartsOn` defaults to `1` (Monday); `0` means Sunday and `6` means Saturday.
35
+ * Calendar ranges follow local daylight saving transitions rather than fixed 24-hour durations.
34
36
  *
35
- * @param {Date} date - The reference date
36
- * @param {DateRangeType} type - The range type to compute
37
- * @param {object} [options] - Optional settings
38
- * @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
39
- * @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
37
+ * @param date - The reference date for the range.
38
+ * @param type - The current or previous day, week, or month to select.
39
+ * @param options - Settings for the end boundary and first day of the week.
40
40
  *
41
- * @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`
41
+ * @returns An object containing new `EnhancedDate` boundaries; the reference date is unchanged.
42
+ *
43
+ * @throws Error if the range type is unsupported at runtime.
42
44
  *
43
45
  * @example
44
- * ```typescript
45
- * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';
46
46
  *
47
- * // Get the date range for last month
48
- * const date = new Date('2023-07-01');
49
- * console.log(getDateRangeFromDate(date, 'lastMonth'));
50
- * // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }
47
+ * ```ts
48
+ * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';
51
49
  *
52
- * // Get this week's range with Sunday as the first day
53
- * console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));
54
- * // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }
50
+ * const range = getDateRangeFromDate(new Date(2026, 6, 15, 12), 'lastMonth');
51
+ * console.log(range.startDate.format('yyyy-MM-dd')); // => '2026-06-01'
52
+ * console.log(range.endDate.format('yyyy-MM-dd')); // => '2026-06-30'
55
53
  * ```
56
54
  */
57
- declare function getDateRangeFromDate(date: Date, type: DateRangeType, options?: {
55
+ export declare function getDateRangeFromDate(date: Date, type: DateRangeType, options?: {
58
56
  setEndDateToNextDayStart?: boolean;
59
- weekStartsOn?: Day;
57
+ weekStartsOn?: dateFns.Day;
60
58
  }): {
61
- endDate: Date;
62
- startDate: Date;
59
+ endDate: EnhancedDate;
60
+ startDate: EnhancedDate;
63
61
  };
64
62
  /**
65
- * Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
66
- *
67
- * @param {number} [offsetDays] - Number of days to offset from today. Can be negative
63
+ * Returns a new date at local midnight with an optional calendar-day offset from today.
68
64
  *
69
- * @returns {Date} A `Date` object at 00:00:00 of the offset day
65
+ * @param offsetDays - The calendar days to add; negative values select earlier days.
70
66
  *
71
- * @example
72
- * ```typescript
73
- * import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';
74
- *
75
- * console.log(getMidnightDateFromToday()); // today at 00:00:00
76
- * console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00
77
- * console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00
78
- * ```
67
+ * @returns A new `EnhancedDate` at local midnight on the selected day.
79
68
  */
80
- declare function getMidnightDateFromToday(offsetDays?: number): Date;
69
+ export declare function getMidnightDateFromToday(offsetDays?: number): EnhancedDate;
81
70
  //#endregion
82
- export { DateRangeType, formatDate, getDateRangeFromDate, getMidnightDateFromToday };
83
71
  //# sourceMappingURL=datetime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"datetime.d.ts","names":[],"sources":["../src/datetime.ts"],"mappings":";;KAkBY;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2BI,WAAW,MAAM,QAAQ,YAAY,iBAAwC,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+BvF,qBACZ,MAAM,MACN,MAAM,eACN;EACI;EACA,eAAe;;;;;;;;;;;;;;;;;;;;;iBAoEP,yBAAyB,sBAAsB"}
1
+ {"version":3,"file":"datetime.d.ts","names":[],"sources":["../src/datetime.ts"],"mappings":";;;YAIY;;;;;;;;;;;;;;;;;;;;;;;wBAwBI,WACZ,MAAM,QAAQ,QAAQ,OACtB,iBACA,UAAU,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkCN,qBACZ,MAAM,MACN,MAAM,eACN;EACI;EACA,eAAe,QAAQ;;;;;;;;;;;;wBA8Df,yBAAyB,sBAAsB"}
package/dist/datetime.js CHANGED
@@ -1,95 +1,94 @@
1
- import { endOfDay, endOfMonth, endOfWeek, format, startOfDay, startOfMonth, startOfWeek, subDays, subMonths, subWeeks } from "date-fns";
1
+ import { EnhancedDate } from "./classes/enhanced-date.js";
2
+ import * as dateFns from "date-fns";
2
3
  //#region src/datetime.ts
3
4
  /**
4
- * Formats a given date, timestamp, or date string into a specified format.
5
+ * Formats a date using a date-fns pattern without changing the input.
5
6
  *
6
- * This function is a wrapper around `date-fns/format`.
7
+ * @remarks
8
+ * Formatting uses the system time zone unless configured through date-fns options.
9
+ * Invalid dates and unsupported patterns propagate date-fns exceptions.
7
10
  *
8
- * @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string
9
- * @param {string} [format] - The target format string
10
- * @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`
11
+ * @param date - The date, timestamp in milliseconds, or date string to format.
12
+ * @param format - The date-fns pattern. Defaults to `yyyy-MM-dd HH:mm:ss`.
13
+ * @param options - Formatting options passed to date-fns.
11
14
  *
12
- * @returns {string} The formatted date string
15
+ * @returns The formatted date string.
13
16
  *
14
17
  * @example
15
- * ```typescript
16
- * import { formatDate } from '@kikiutils/shared/datetime';
17
- *
18
- * // Format a Date object
19
- * console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10
20
18
  *
21
- * // Format a timestamp
22
- * console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15
19
+ * ```ts
20
+ * import { formatDate } from '@kikiutils/shared/datetime';
23
21
  *
24
- * // Format a date string
25
- * console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
22
+ * const date = new Date(2026, 0, 15, 12);
23
+ * console.log(formatDate(date, 'yyyy-MM-dd')); // => '2026-01-15'
26
24
  * ```
27
25
  */
28
- function formatDate(date, format$1 = "yyyy-MM-dd HH:mm:ss", options) {
29
- return format(date, format$1, options);
26
+ function formatDate(date, format = "yyyy-MM-dd HH:mm:ss", options) {
27
+ return dateFns.format(date, format, options);
30
28
  }
31
29
  /**
32
- * Get the date range (start and end) based on a given date and range type.
30
+ * Returns new start and end dates for a calendar range in the system time zone.
33
31
  *
34
- * Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.
32
+ * @remarks
33
+ * The reference date is unchanged. Boundaries are inclusive by default, ending at `23:59:59.999`.
34
+ * When `options.setEndDateToNextDayStart` is `true`, the end is the exclusive start of the next calendar day.
35
+ * `options.weekStartsOn` defaults to `1` (Monday); `0` means Sunday and `6` means Saturday.
36
+ * Calendar ranges follow local daylight saving transitions rather than fixed 24-hour durations.
35
37
  *
36
- * @param {Date} date - The reference date
37
- * @param {DateRangeType} type - The range type to compute
38
- * @param {object} [options] - Optional settings
39
- * @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
40
- * @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
38
+ * @param date - The reference date for the range.
39
+ * @param type - The current or previous day, week, or month to select.
40
+ * @param options - Settings for the end boundary and first day of the week.
41
41
  *
42
- * @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`
42
+ * @returns An object containing new `EnhancedDate` boundaries; the reference date is unchanged.
43
+ *
44
+ * @throws Error if the range type is unsupported at runtime.
43
45
  *
44
46
  * @example
45
- * ```typescript
46
- * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';
47
47
  *
48
- * // Get the date range for last month
49
- * const date = new Date('2023-07-01');
50
- * console.log(getDateRangeFromDate(date, 'lastMonth'));
51
- * // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }
48
+ * ```ts
49
+ * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';
52
50
  *
53
- * // Get this week's range with Sunday as the first day
54
- * console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));
55
- * // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }
51
+ * const range = getDateRangeFromDate(new Date(2026, 6, 15, 12), 'lastMonth');
52
+ * console.log(range.startDate.format('yyyy-MM-dd')); // => '2026-06-01'
53
+ * console.log(range.endDate.format('yyyy-MM-dd')); // => '2026-06-30'
56
54
  * ```
57
55
  */
58
56
  function getDateRangeFromDate(date, type, options) {
57
+ const referenceDate = new EnhancedDate(date);
59
58
  let endDate;
60
59
  let startDate;
61
60
  switch (type) {
62
61
  case "lastMonth":
63
62
  {
64
- const lastMonth = subMonths(date, 1);
65
- endDate = endOfMonth(lastMonth);
66
- startDate = startOfMonth(lastMonth);
63
+ const lastMonth = referenceDate.toSubMonths(1);
64
+ endDate = lastMonth.toEndOfMonth();
65
+ startDate = lastMonth.toStartOfMonth();
67
66
  }
68
67
  break;
69
68
  case "lastWeek":
70
69
  {
71
- const lastWeek = subWeeks(date, 1);
72
- endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
73
- startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
70
+ const lastWeek = referenceDate.toSubWeeks(1);
71
+ endDate = lastWeek.toEndOfWeek({ weekStartsOn: options?.weekStartsOn ?? 1 });
72
+ startDate = lastWeek.toStartOfWeek({ weekStartsOn: options?.weekStartsOn ?? 1 });
74
73
  }
75
74
  break;
76
75
  case "thisMonth":
77
- endDate = endOfMonth(date);
78
- startDate = startOfMonth(date);
76
+ endDate = referenceDate.toEndOfMonth();
77
+ startDate = referenceDate.toStartOfMonth();
79
78
  break;
80
79
  case "thisWeek":
81
- endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
82
- startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
80
+ endDate = referenceDate.toEndOfWeek({ weekStartsOn: options?.weekStartsOn ?? 1 });
81
+ startDate = referenceDate.toStartOfWeek({ weekStartsOn: options?.weekStartsOn ?? 1 });
83
82
  break;
84
83
  case "today":
85
- endDate = endOfDay(date);
86
- startDate = startOfDay(date);
84
+ endDate = referenceDate.toEndOfDay();
85
+ startDate = referenceDate.toStartOfDay();
87
86
  break;
88
87
  case "yesterday":
89
88
  {
90
- const yesterday = subDays(date, 1);
91
- endDate = endOfDay(yesterday);
92
- startDate = startOfDay(yesterday);
89
+ const yesterday = referenceDate.toSubDays(1);
90
+ endDate = yesterday.toEndOfDay();
91
+ startDate = yesterday.toStartOfDay();
93
92
  }
94
93
  break;
95
94
  default: throw new Error(`Unsupported date range type: ${type}`);
@@ -101,26 +100,14 @@ function getDateRangeFromDate(date, type, options) {
101
100
  };
102
101
  }
103
102
  /**
104
- * Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
105
- *
106
- * @param {number} [offsetDays] - Number of days to offset from today. Can be negative
103
+ * Returns a new date at local midnight with an optional calendar-day offset from today.
107
104
  *
108
- * @returns {Date} A `Date` object at 00:00:00 of the offset day
105
+ * @param offsetDays - The calendar days to add; negative values select earlier days.
109
106
  *
110
- * @example
111
- * ```typescript
112
- * import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';
113
- *
114
- * console.log(getMidnightDateFromToday()); // today at 00:00:00
115
- * console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00
116
- * console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00
117
- * ```
107
+ * @returns A new `EnhancedDate` at local midnight on the selected day.
118
108
  */
119
109
  function getMidnightDateFromToday(offsetDays = 0) {
120
- const date = /* @__PURE__ */ new Date();
121
- date.setDate(date.getDate() + offsetDays);
122
- date.setHours(0, 0, 0, 0);
123
- return date;
110
+ return new EnhancedDate().addDays(offsetDays).startOfDay();
124
111
  }
125
112
  //#endregion
126
113
  export { formatDate, getDateRangeFromDate, getMidnightDateFromToday };
@@ -1 +1 @@
1
- {"version":3,"file":"datetime.js","names":["dateFnsFormat","format"],"sources":["../src/datetime.ts"],"sourcesContent":["import {\n format as dateFnsFormat,\n endOfDay,\n endOfMonth,\n endOfWeek,\n startOfDay,\n startOfMonth,\n startOfWeek,\n subDays,\n subMonths,\n subWeeks,\n} from 'date-fns';\nimport type {\n DateArg,\n Day,\n FormatOptions,\n} from 'date-fns';\n\nexport type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek' | 'today' | 'yesterday';\n\n/**\n * Formats a given date, timestamp, or date string into a specified format.\n *\n * This function is a wrapper around `date-fns/format`.\n *\n * @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string\n * @param {string} [format] - The target format string\n * @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`\n *\n * @returns {string} The formatted date string\n *\n * @example\n * ```typescript\n * import { formatDate } from '@kikiutils/shared/datetime';\n *\n * // Format a Date object\n * console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10\n *\n * // Format a timestamp\n * console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15\n *\n * // Format a date string\n * console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10\n * ```\n */\nexport function formatDate(date: DateArg<Date> & {}, format: string = 'yyyy-MM-dd HH:mm:ss', options?: FormatOptions) {\n return dateFnsFormat(date, format, options);\n}\n\n/**\n * Get the date range (start and end) based on a given date and range type.\n *\n * Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.\n *\n * @param {Date} date - The reference date\n * @param {DateRangeType} type - The range type to compute\n * @param {object} [options] - Optional settings\n * @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day\n * @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)\n *\n * @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`\n *\n * @example\n * ```typescript\n * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';\n *\n * // Get the date range for last month\n * const date = new Date('2023-07-01');\n * console.log(getDateRangeFromDate(date, 'lastMonth'));\n * // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }\n *\n * // Get this week's range with Sunday as the first day\n * console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));\n * // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }\n * ```\n */\nexport function getDateRangeFromDate(\n date: Date,\n type: DateRangeType,\n options?: {\n setEndDateToNextDayStart?: boolean;\n weekStartsOn?: Day;\n },\n) {\n let endDate: Date;\n let startDate: Date;\n switch (type) {\n case 'lastMonth':\n {\n const lastMonth = subMonths(date, 1);\n endDate = endOfMonth(lastMonth);\n startDate = startOfMonth(lastMonth);\n }\n\n break;\n case 'lastWeek':\n {\n const lastWeek = subWeeks(date, 1);\n endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });\n }\n\n break;\n case 'thisMonth':\n endDate = endOfMonth(date);\n startDate = startOfMonth(date);\n break;\n case 'thisWeek':\n endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });\n break;\n case 'today':\n endDate = endOfDay(date);\n startDate = startOfDay(date);\n break;\n case 'yesterday':\n {\n const yesterday = subDays(date, 1);\n endDate = endOfDay(yesterday);\n startDate = startOfDay(yesterday);\n }\n\n break;\n default: throw new Error(`Unsupported date range type: ${type}`);\n }\n\n if (options?.setEndDateToNextDayStart) endDate.setHours(24, 0, 0, 0);\n return {\n endDate,\n startDate,\n };\n}\n\n/**\n * Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.\n *\n * @param {number} [offsetDays] - Number of days to offset from today. Can be negative\n *\n * @returns {Date} A `Date` object at 00:00:00 of the offset day\n *\n * @example\n * ```typescript\n * import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';\n *\n * console.log(getMidnightDateFromToday()); // today at 00:00:00\n * console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00\n * console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00\n * ```\n */\nexport function getMidnightDateFromToday(offsetDays: number = 0) {\n const date = new Date();\n date.setDate(date.getDate() + offsetDays);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,WAAW,MAA0B,WAAiB,uBAAuB,SAAyB;CAClH,OAAOA,OAAc,MAAMC,UAAQ,OAAO;AAC9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,qBACZ,MACA,MACA,SAIF;CACE,IAAI;CACJ,IAAI;CACJ,QAAQ,MAAR;EACI,KAAK;GACD;IACI,MAAM,YAAY,UAAU,MAAM,CAAC;IACnC,UAAU,WAAW,SAAS;IAC9B,YAAY,aAAa,SAAS;GACtC;GAEA;EACJ,KAAK;GACD;IACI,MAAM,WAAW,SAAS,MAAM,CAAC;IACjC,UAAU,UAAU,UAAU,EAAE,cAAc,SAAS,gBAAgB,EAAE,CAAC;IAC1E,YAAY,YAAY,UAAU,EAAE,cAAc,SAAS,gBAAgB,EAAE,CAAC;GAClF;GAEA;EACJ,KAAK;GACD,UAAU,WAAW,IAAI;GACzB,YAAY,aAAa,IAAI;GAC7B;EACJ,KAAK;GACD,UAAU,UAAU,MAAM,EAAE,cAAc,SAAS,gBAAgB,EAAE,CAAC;GACtE,YAAY,YAAY,MAAM,EAAE,cAAc,SAAS,gBAAgB,EAAE,CAAC;GAC1E;EACJ,KAAK;GACD,UAAU,SAAS,IAAI;GACvB,YAAY,WAAW,IAAI;GAC3B;EACJ,KAAK;GACD;IACI,MAAM,YAAY,QAAQ,MAAM,CAAC;IACjC,UAAU,SAAS,SAAS;IAC5B,YAAY,WAAW,SAAS;GACpC;GAEA;EACJ,SAAS,MAAM,IAAI,MAAM,gCAAgC,MAAM;CACnE;CAEA,IAAI,SAAS,0BAA0B,QAAQ,SAAS,IAAI,GAAG,GAAG,CAAC;CACnE,OAAO;EACH;EACA;CACJ;AACJ;;;;;;;;;;;;;;;;;AAkBA,SAAgB,yBAAyB,aAAqB,GAAG;CAC7D,MAAM,uBAAO,IAAI,KAAK;CACtB,KAAK,QAAQ,KAAK,QAAQ,IAAI,UAAU;CACxC,KAAK,SAAS,GAAG,GAAG,GAAG,CAAC;CACxB,OAAO;AACX"}
1
+ {"version":3,"file":"datetime.js","names":[],"sources":["../src/datetime.ts"],"sourcesContent":["import * as dateFns from 'date-fns';\n\nimport { EnhancedDate } from './classes/enhanced-date';\n\nexport type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek' | 'today' | 'yesterday';\n\n/**\n * Formats a date using a date-fns pattern without changing the input.\n *\n * @remarks\n * Formatting uses the system time zone unless configured through date-fns options.\n * Invalid dates and unsupported patterns propagate date-fns exceptions.\n *\n * @param date - The date, timestamp in milliseconds, or date string to format.\n * @param format - The date-fns pattern. Defaults to `yyyy-MM-dd HH:mm:ss`.\n * @param options - Formatting options passed to date-fns.\n *\n * @returns The formatted date string.\n *\n * @example\n *\n * ```ts\n * import { formatDate } from '@kikiutils/shared/datetime';\n *\n * const date = new Date(2026, 0, 15, 12);\n * console.log(formatDate(date, 'yyyy-MM-dd')); // => '2026-01-15'\n * ```\n */\nexport function formatDate(\n date: dateFns.DateArg<Date>,\n format: string = 'yyyy-MM-dd HH:mm:ss',\n options?: dateFns.FormatOptions,\n) {\n return dateFns.format(date, format, options);\n}\n\n/* eslint-disable jsdoc/check-param-names -- Inline TypeScript options are documented in remarks. */\n\n/**\n * Returns new start and end dates for a calendar range in the system time zone.\n *\n * @remarks\n * The reference date is unchanged. Boundaries are inclusive by default, ending at `23:59:59.999`.\n * When `options.setEndDateToNextDayStart` is `true`, the end is the exclusive start of the next calendar day.\n * `options.weekStartsOn` defaults to `1` (Monday); `0` means Sunday and `6` means Saturday.\n * Calendar ranges follow local daylight saving transitions rather than fixed 24-hour durations.\n *\n * @param date - The reference date for the range.\n * @param type - The current or previous day, week, or month to select.\n * @param options - Settings for the end boundary and first day of the week.\n *\n * @returns An object containing new `EnhancedDate` boundaries; the reference date is unchanged.\n *\n * @throws Error if the range type is unsupported at runtime.\n *\n * @example\n *\n * ```ts\n * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';\n *\n * const range = getDateRangeFromDate(new Date(2026, 6, 15, 12), 'lastMonth');\n * console.log(range.startDate.format('yyyy-MM-dd')); // => '2026-06-01'\n * console.log(range.endDate.format('yyyy-MM-dd')); // => '2026-06-30'\n * ```\n */\nexport function getDateRangeFromDate(\n date: Date,\n type: DateRangeType,\n options?: {\n setEndDateToNextDayStart?: boolean;\n weekStartsOn?: dateFns.Day;\n },\n) {\n const referenceDate = new EnhancedDate(date);\n let endDate: EnhancedDate;\n let startDate: EnhancedDate;\n switch (type) {\n case 'lastMonth':\n {\n const lastMonth = referenceDate.toSubMonths(1);\n endDate = lastMonth.toEndOfMonth();\n startDate = lastMonth.toStartOfMonth();\n }\n\n break;\n case 'lastWeek':\n {\n const lastWeek = referenceDate.toSubWeeks(1);\n endDate = lastWeek.toEndOfWeek({ weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = lastWeek.toStartOfWeek({ weekStartsOn: options?.weekStartsOn ?? 1 });\n }\n\n break;\n case 'thisMonth':\n endDate = referenceDate.toEndOfMonth();\n startDate = referenceDate.toStartOfMonth();\n break;\n case 'thisWeek':\n endDate = referenceDate.toEndOfWeek({ weekStartsOn: options?.weekStartsOn ?? 1 });\n startDate = referenceDate.toStartOfWeek({ weekStartsOn: options?.weekStartsOn ?? 1 });\n break;\n case 'today':\n endDate = referenceDate.toEndOfDay();\n startDate = referenceDate.toStartOfDay();\n break;\n case 'yesterday':\n {\n const yesterday = referenceDate.toSubDays(1);\n endDate = yesterday.toEndOfDay();\n startDate = yesterday.toStartOfDay();\n }\n\n break;\n default: throw new Error(`Unsupported date range type: ${type}`);\n }\n\n if (options?.setEndDateToNextDayStart) endDate.setHours(24, 0, 0, 0);\n return {\n endDate,\n startDate,\n };\n}\n\n/* eslint-enable jsdoc/check-param-names */\n\n/**\n * Returns a new date at local midnight with an optional calendar-day offset from today.\n *\n * @param offsetDays - The calendar days to add; negative values select earlier days.\n *\n * @returns A new `EnhancedDate` at local midnight on the selected day.\n */\nexport function getMidnightDateFromToday(offsetDays: number = 0) {\n return new EnhancedDate().addDays(offsetDays).startOfDay();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,WACZ,MACA,SAAiB,uBACjB,SACF;CACE,OAAO,QAAQ,OAAO,MAAM,QAAQ,OAAO;AAC/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,qBACZ,MACA,MACA,SAIF;CACE,MAAM,gBAAgB,IAAI,aAAa,IAAI;CAC3C,IAAI;CACJ,IAAI;CACJ,QAAQ,MAAR;EACI,KAAK;GACD;IACI,MAAM,YAAY,cAAc,YAAY,CAAC;IAC7C,UAAU,UAAU,aAAa;IACjC,YAAY,UAAU,eAAe;GACzC;GAEA;EACJ,KAAK;GACD;IACI,MAAM,WAAW,cAAc,WAAW,CAAC;IAC3C,UAAU,SAAS,YAAY,EAAE,cAAc,SAAS,gBAAgB,EAAE,CAAC;IAC3E,YAAY,SAAS,cAAc,EAAE,cAAc,SAAS,gBAAgB,EAAE,CAAC;GACnF;GAEA;EACJ,KAAK;GACD,UAAU,cAAc,aAAa;GACrC,YAAY,cAAc,eAAe;GACzC;EACJ,KAAK;GACD,UAAU,cAAc,YAAY,EAAE,cAAc,SAAS,gBAAgB,EAAE,CAAC;GAChF,YAAY,cAAc,cAAc,EAAE,cAAc,SAAS,gBAAgB,EAAE,CAAC;GACpF;EACJ,KAAK;GACD,UAAU,cAAc,WAAW;GACnC,YAAY,cAAc,aAAa;GACvC;EACJ,KAAK;GACD;IACI,MAAM,YAAY,cAAc,UAAU,CAAC;IAC3C,UAAU,UAAU,WAAW;IAC/B,YAAY,UAAU,aAAa;GACvC;GAEA;EACJ,SAAS,MAAM,IAAI,MAAM,gCAAgC,MAAM;CACnE;CAEA,IAAI,SAAS,0BAA0B,QAAQ,SAAS,IAAI,GAAG,GAAG,CAAC;CACnE,OAAO;EACH;EACA;CACJ;AACJ;;;;;;;;AAWA,SAAgB,yBAAyB,aAAqB,GAAG;CAC7D,OAAO,IAAI,aAAa,CAAC,CAAC,QAAQ,UAAU,CAAC,CAAC,WAAW;AAC7D"}
@@ -1,31 +1,30 @@
1
1
  import { RuleType } from "async-validator";
2
2
  import { FormItemRule } from "element-plus";
3
3
  //#region src/element-plus.d.ts
4
- type DoNotRemoveOrUseThisType = RuleType;
4
+ export type DoNotRemoveOrUseThisType = RuleType;
5
5
  /**
6
- * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.
6
+ * Creates a new Element Plus form validation rule with overridable defaults.
7
7
  *
8
- * This utility provides default values for `required`, `trigger`, and `type`,
9
- * while allowing overrides via the `options` parameter. It simplifies common
10
- * form validation rule creation and ensures consistency across forms.
8
+ * @remarks
9
+ * Defaults to `required: true`, `trigger: 'blur'`, and `type: 'string'`.
10
+ * Non-nullish options override those defaults; `null` and `undefined` use the defaults.
11
+ * The `message` argument takes precedence over `options.message`.
12
+ * The options object is unchanged.
11
13
  *
12
- * @param {FormItemRule['message']} message - The validation message to display when the rule fails
13
- * @param {FormItemRule} [options] - Optional overrides for the rule fields
14
- * @param {boolean} [options.required] - Whether the field is required (default: `true`)
15
- * @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
16
- * @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
14
+ * @param message - The validation message displayed on failure.
15
+ * @param options - Additional rule fields and non-nullish overrides for the defaults; `message` takes precedence.
17
16
  *
18
- * @returns A `FormItemRule` object that can be used in Element Plus form validation
17
+ * @returns A new `FormItemRule` object.
19
18
  *
20
19
  * @example
21
- * ```typescript
20
+ *
21
+ * ```ts
22
22
  * import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';
23
23
  *
24
24
  * const rule = createElFormItemRuleWithDefaults('This field is required');
25
25
  * const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });
26
26
  * ```
27
27
  */
28
- declare function createElFormItemRuleWithDefaults(message: FormItemRule['message'], options?: FormItemRule): FormItemRule;
28
+ export declare function createElFormItemRuleWithDefaults(message: FormItemRule['message'], options?: FormItemRule): FormItemRule;
29
29
  //#endregion
30
- export { DoNotRemoveOrUseThisType, createElFormItemRuleWithDefaults };
31
30
  //# sourceMappingURL=element-plus.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"element-plus.d.ts","names":[],"sources":["../src/element-plus.ts"],"mappings":";;;KAGY,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;iBAyBvB,iCACZ,SAAS,yBACT,UAAS,eACV"}
1
+ {"version":3,"file":"element-plus.d.ts","names":[],"sources":["../src/element-plus.ts"],"mappings":";;;YAGY,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;wBAyBvB,iCACZ,SAAS,yBACT,UAAS,eACV"}
@@ -1,21 +1,21 @@
1
1
  //#region src/element-plus.ts
2
2
  /**
3
- * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.
3
+ * Creates a new Element Plus form validation rule with overridable defaults.
4
4
  *
5
- * This utility provides default values for `required`, `trigger`, and `type`,
6
- * while allowing overrides via the `options` parameter. It simplifies common
7
- * form validation rule creation and ensures consistency across forms.
5
+ * @remarks
6
+ * Defaults to `required: true`, `trigger: 'blur'`, and `type: 'string'`.
7
+ * Non-nullish options override those defaults; `null` and `undefined` use the defaults.
8
+ * The `message` argument takes precedence over `options.message`.
9
+ * The options object is unchanged.
8
10
  *
9
- * @param {FormItemRule['message']} message - The validation message to display when the rule fails
10
- * @param {FormItemRule} [options] - Optional overrides for the rule fields
11
- * @param {boolean} [options.required] - Whether the field is required (default: `true`)
12
- * @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
13
- * @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
11
+ * @param message - The validation message displayed on failure.
12
+ * @param options - Additional rule fields and non-nullish overrides for the defaults; `message` takes precedence.
14
13
  *
15
- * @returns A `FormItemRule` object that can be used in Element Plus form validation
14
+ * @returns A new `FormItemRule` object.
16
15
  *
17
16
  * @example
18
- * ```typescript
17
+ *
18
+ * ```ts
19
19
  * import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';
20
20
  *
21
21
  * const rule = createElFormItemRuleWithDefaults('This field is required');
@@ -1 +1 @@
1
- {"version":3,"file":"element-plus.js","names":[],"sources":["../src/element-plus.ts"],"sourcesContent":["import type { RuleType } from 'async-validator';\nimport type { FormItemRule } from 'element-plus';\n\nexport type DoNotRemoveOrUseThisType = RuleType;\n\n/**\n * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.\n *\n * This utility provides default values for `required`, `trigger`, and `type`,\n * while allowing overrides via the `options` parameter. It simplifies common\n * form validation rule creation and ensures consistency across forms.\n *\n * @param {FormItemRule['message']} message - The validation message to display when the rule fails\n * @param {FormItemRule} [options] - Optional overrides for the rule fields\n * @param {boolean} [options.required] - Whether the field is required (default: `true`)\n * @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)\n * @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)\n *\n * @returns A `FormItemRule` object that can be used in Element Plus form validation\n *\n * @example\n * ```typescript\n * import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';\n *\n * const rule = createElFormItemRuleWithDefaults('This field is required');\n * const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });\n * ```\n */\nexport function createElFormItemRuleWithDefaults(\n message: FormItemRule['message'],\n options: FormItemRule = {},\n): FormItemRule {\n return {\n ...options,\n message,\n required: options.required ?? true,\n trigger: options.trigger ?? 'blur',\n type: options.type ?? 'string',\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,iCACZ,SACA,UAAwB,CAAC,GACb;CACZ,OAAO;EACH,GAAG;EACH;EACA,UAAU,QAAQ,YAAY;EAC9B,SAAS,QAAQ,WAAW;EAC5B,MAAM,QAAQ,QAAQ;CAC1B;AACJ"}
1
+ {"version":3,"file":"element-plus.js","names":[],"sources":["../src/element-plus.ts"],"sourcesContent":["import type { RuleType } from 'async-validator';\nimport type { FormItemRule } from 'element-plus';\n\nexport type DoNotRemoveOrUseThisType = RuleType;\n\n/**\n * Creates a new Element Plus form validation rule with overridable defaults.\n *\n * @remarks\n * Defaults to `required: true`, `trigger: 'blur'`, and `type: 'string'`.\n * Non-nullish options override those defaults; `null` and `undefined` use the defaults.\n * The `message` argument takes precedence over `options.message`.\n * The options object is unchanged.\n *\n * @param message - The validation message displayed on failure.\n * @param options - Additional rule fields and non-nullish overrides for the defaults; `message` takes precedence.\n *\n * @returns A new `FormItemRule` object.\n *\n * @example\n *\n * ```ts\n * import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';\n *\n * const rule = createElFormItemRuleWithDefaults('This field is required');\n * const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });\n * ```\n */\nexport function createElFormItemRuleWithDefaults(\n message: FormItemRule['message'],\n options: FormItemRule = {},\n): FormItemRule {\n return {\n ...options,\n message,\n required: options.required ?? true,\n trigger: options.trigger ?? 'blur',\n type: options.type ?? 'string',\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,iCACZ,SACA,UAAwB,CAAC,GACb;CACZ,OAAO;EACH,GAAG;EACH;EACA,UAAU,QAAQ,YAAY;EAC9B,SAAS,QAAQ,WAAW;EAC5B,MAAM,QAAQ,QAAQ;CAC1B;AACJ"}
package/dist/enum.d.ts CHANGED
@@ -2,98 +2,101 @@
2
2
  /**
3
3
  * Extracts only the numeric values from an enumeration-like object.
4
4
  *
5
- * @template T - The type of the enum object
5
+ * @typeParam T - The type of the enum object.
6
6
  *
7
- * @param {T} enumObject - The enumeration-like object to extract numeric values from,
7
+ * @param enumObject - The enumeration-like object to extract numeric values from,
8
8
  * the object can contain numeric values, string values, or both.
9
9
  *
10
- * @returns {Extract<T[keyof T], number>[]} An array of numeric values extracted from the enum object
10
+ * @returns An array of numeric values extracted from the enum object.
11
11
  *
12
12
  * @example
13
- * ```typescript
13
+ *
14
+ * ```ts
14
15
  * import { getEnumNumberValues } from '@kikiutils/shared/enum';
15
16
  *
16
17
  * enum RecordType {
17
- * Receive = 0,
18
- * Send = 1,
19
- * Unknown = 'unknown'
18
+ * Receive = 0,
19
+ * Send = 1,
20
+ * Unknown = 'unknown',
20
21
  * }
21
22
  *
22
- * console.log(getEnumNumberValues(RecordType)); // [0, 1]
23
+ * console.log(getEnumNumberValues(RecordType)); // => [0, 1]
23
24
  * ```
24
25
  */
25
- declare function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], number>[];
26
+ export declare function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], number>[];
26
27
  /**
27
28
  * Extracts only the string values from an enumeration-like object.
28
29
  *
29
- * @template T - The type of the enum object
30
+ * @typeParam T - The type of the enum object.
30
31
  *
31
- * @param {T} enumObject - The enumeration-like object to extract string values from,
32
+ * @param enumObject - The enumeration-like object to extract string values from,
32
33
  * the object can contain numeric values, string values, or both.
33
34
  *
34
- * @returns {Extract<T[keyof T], string>[]} An array of string values extracted from the enum object
35
+ * @returns An array of string values extracted from the enum object.
35
36
  *
36
37
  * @example
37
- * ```typescript
38
+ *
39
+ * ```ts
38
40
  * import { getEnumStringValues } from '@kikiutils/shared/enum';
39
41
  *
40
42
  * enum RecordType {
41
- * Receive = 0,
42
- * Send = 1,
43
- * Unknown = 'unknown'
43
+ * Receive = 0,
44
+ * Send = 1,
45
+ * Unknown = 'unknown',
44
46
  * }
45
47
  *
46
- * console.log(getEnumStringValues(RecordType)); // ['unknown']
48
+ * console.log(getEnumStringValues(RecordType)); // => ['unknown']
47
49
  * ```
48
50
  */
49
- declare function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], string>[];
51
+ export declare function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], string>[];
50
52
  /**
51
53
  * Extracts all values from an enumeration-like object.
52
54
  *
55
+ * @remarks
53
56
  * This function handles TypeScript enums correctly by accounting for the reverse mapping
54
57
  * that occurs with numeric enums. It works with pure numeric enums, pure string enums,
55
58
  * and mixed enums.
56
59
  *
57
- * @template T - The type of the enum object
60
+ * @typeParam T - The type of the enum object.
58
61
  *
59
- * @param {T} enumObject - The enumeration-like object to extract values from,
62
+ * @param enumObject - The enumeration-like object to extract values from,
60
63
  * the object can contain numeric values, string values, or both.
61
64
  *
62
- * @returns {(T[keyof T])[]} An array containing all the values from the enum object
65
+ * @returns An array containing all the values from the enum object.
63
66
  *
64
67
  * @example
65
- * ```typescript
68
+ *
69
+ * ```ts
66
70
  * import { getEnumValues } from '@kikiutils/shared/enum';
67
71
  *
68
72
  * // Numeric enum
69
73
  * enum Status {
70
- * Active = 0,
71
- * Inactive = 1,
72
- * Pending = 2
74
+ * Active = 0,
75
+ * Inactive = 1,
76
+ * Pending = 2,
73
77
  * }
74
78
  *
75
- * console.log(getEnumValues(Status)); // [0, 1, 2]
79
+ * console.log(getEnumValues(Status)); // => [0, 1, 2]
76
80
  *
77
81
  * // String enum
78
82
  * enum Color {
79
- * Red = 'RED',
80
- * Green = 'GREEN',
81
- * Blue = 'BLUE'
83
+ * Red = 'RED',
84
+ * Green = 'GREEN',
85
+ * Blue = 'BLUE',
82
86
  * }
83
87
  *
84
- * console.log(getEnumValues(Color)); // ['RED', 'GREEN', 'BLUE']
88
+ * console.log(getEnumValues(Color)); // => ['RED', 'GREEN', 'BLUE']
85
89
  *
86
90
  * // Mixed enum
87
91
  * enum RecordType {
88
- * Receive = 0,
89
- * Send = 1,
90
- * Unknown = 'unknown'
92
+ * Receive = 0,
93
+ * Send = 1,
94
+ * Unknown = 'unknown',
91
95
  * }
92
96
  *
93
- * console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']
97
+ * console.log(getEnumValues(RecordType)); // => [0, 1, 'unknown']
94
98
  * ```
95
99
  */
96
- declare function getEnumValues<T extends Record<string, any>>(enumObject: T): (T[keyof T])[];
100
+ export declare function getEnumValues<T extends Record<string, any>>(enumObject: T): (T[keyof T])[];
97
101
  //#endregion
98
- export { getEnumNumberValues, getEnumStringValues, getEnumValues };
99
102
  //# sourceMappingURL=enum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"enum.d.ts","names":[],"sources":["../src/enum.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;iBAuBgB,oBAAoB,UAAU,qBAAqB,YAAY,IAAI,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;iBA2BnF,oBAAoB,UAAU,qBAAqB,YAAY,IAAI,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkDnF,cAAc,UAAU,qBAAqB,YAAY,KAAK,QAAQ"}
1
+ {"version":3,"file":"enum.d.ts","names":[],"sources":["../src/enum.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;wBAwBgB,oBAAoB,UAAU,qBAAqB,YAAY,IAAI,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;wBA4BnF,oBAAoB,UAAU,qBAAqB,YAAY,IAAI,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAoDnF,cAAc,UAAU,qBAAqB,YAAY,KAAK,QAAQ"}