@kikiutils/shared 12.0.0 → 13.0.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 (210) hide show
  1. package/README.md +1 -1
  2. package/dist/buffer.d.ts +7 -3
  3. package/dist/buffer.d.ts.map +1 -1
  4. package/dist/buffer.js +42 -0
  5. package/dist/buffer.js.map +1 -0
  6. package/dist/clipboard.d.ts +8 -6
  7. package/dist/clipboard.d.ts.map +1 -1
  8. package/dist/clipboard.js +86 -0
  9. package/dist/clipboard.js.map +1 -0
  10. package/dist/consola.d.ts +8 -2
  11. package/dist/consola.d.ts.map +1 -1
  12. package/dist/consola.js +32 -0
  13. package/dist/consola.js.map +1 -0
  14. package/dist/crypto-hash.d.ts +16 -26
  15. package/dist/crypto-hash.d.ts.map +1 -1
  16. package/dist/crypto-hash.js +37 -0
  17. package/dist/crypto-hash.js.map +1 -0
  18. package/dist/datetime.d.ts +13 -9
  19. package/dist/datetime.d.ts.map +1 -1
  20. package/dist/datetime.js +131 -0
  21. package/dist/datetime.js.map +1 -0
  22. package/dist/element-plus.d.ts +8 -4
  23. package/dist/element-plus.d.ts.map +1 -1
  24. package/dist/element-plus.js +37 -0
  25. package/dist/element-plus.js.map +1 -0
  26. package/dist/enum.d.ts +6 -3
  27. package/dist/enum.d.ts.map +1 -1
  28. package/dist/enum.js +108 -0
  29. package/dist/enum.js.map +1 -0
  30. package/dist/env.d.ts +12 -9
  31. package/dist/env.d.ts.map +1 -1
  32. package/dist/env.js +51 -0
  33. package/dist/env.js.map +1 -0
  34. package/dist/general.d.ts +5 -2
  35. package/dist/general.d.ts.map +1 -1
  36. package/dist/general.js +8 -0
  37. package/dist/general.js.map +1 -0
  38. package/dist/hash.d.ts +7 -4
  39. package/dist/hash.d.ts.map +1 -1
  40. package/dist/hash.js +20 -0
  41. package/dist/hash.js.map +1 -0
  42. package/dist/math.d.ts +20 -17
  43. package/dist/math.d.ts.map +1 -1
  44. package/dist/math.js +36 -0
  45. package/dist/math.js.map +1 -0
  46. package/dist/number.d.ts +7 -2
  47. package/dist/number.d.ts.map +1 -1
  48. package/dist/number.js +32 -0
  49. package/dist/number.js.map +1 -0
  50. package/dist/object.d.ts +4 -1
  51. package/dist/object.d.ts.map +1 -1
  52. package/dist/object.js +42 -0
  53. package/dist/object.js.map +1 -0
  54. package/dist/pino.d.ts +8 -2
  55. package/dist/pino.d.ts.map +1 -1
  56. package/dist/pino.js +40 -0
  57. package/dist/pino.js.map +1 -0
  58. package/dist/random.d.ts +4 -1
  59. package/dist/random.d.ts.map +1 -1
  60. package/dist/random.js +31 -0
  61. package/dist/random.js.map +1 -0
  62. package/dist/storage/enhanced/local/core.d.ts +45 -42
  63. package/dist/storage/enhanced/local/core.d.ts.map +1 -1
  64. package/dist/storage/enhanced/local/core.js +63 -0
  65. package/dist/storage/enhanced/local/core.js.map +1 -0
  66. package/dist/storage/enhanced/local/index.d.ts +3 -3
  67. package/dist/storage/enhanced/local/index.js +4 -0
  68. package/dist/storage/enhanced/local/keyed-store.d.ts +14 -11
  69. package/dist/storage/enhanced/local/keyed-store.d.ts.map +1 -1
  70. package/dist/storage/enhanced/local/keyed-store.js +36 -0
  71. package/dist/storage/enhanced/local/keyed-store.js.map +1 -0
  72. package/dist/storage/enhanced/redis/core.d.ts +64 -59
  73. package/dist/storage/enhanced/redis/core.d.ts.map +1 -1
  74. package/dist/storage/enhanced/redis/core.js +85 -0
  75. package/dist/storage/enhanced/redis/core.js.map +1 -0
  76. package/dist/storage/enhanced/redis/index.d.ts +3 -3
  77. package/dist/storage/enhanced/redis/index.js +4 -0
  78. package/dist/storage/enhanced/redis/keyed-store.d.ts +19 -14
  79. package/dist/storage/enhanced/redis/keyed-store.d.ts.map +1 -1
  80. package/dist/storage/enhanced/redis/keyed-store.js +41 -0
  81. package/dist/storage/enhanced/redis/keyed-store.js.map +1 -0
  82. package/dist/storage/lru/keyed-store.d.ts +21 -16
  83. package/dist/storage/lru/keyed-store.d.ts.map +1 -1
  84. package/dist/storage/lru/keyed-store.js +40 -0
  85. package/dist/storage/lru/keyed-store.js.map +1 -0
  86. package/dist/string.d.ts +5 -2
  87. package/dist/string.d.ts.map +1 -1
  88. package/dist/string.js +42 -0
  89. package/dist/string.js.map +1 -0
  90. package/dist/url.d.ts +4 -1
  91. package/dist/url.d.ts.map +1 -1
  92. package/dist/url.js +21 -0
  93. package/dist/url.js.map +1 -0
  94. package/dist/vue.d.ts +10 -5
  95. package/dist/vue.d.ts.map +1 -1
  96. package/dist/vue.js +58 -0
  97. package/dist/vue.js.map +1 -0
  98. package/dist/web.d.ts +5 -2
  99. package/dist/web.d.ts.map +1 -1
  100. package/dist/web.js +32 -0
  101. package/dist/web.js.map +1 -0
  102. package/package.json +42 -26
  103. package/src/vue.ts +1 -1
  104. package/src/web.ts +1 -1
  105. package/dist/buffer.cjs +0 -43
  106. package/dist/buffer.cjs.map +0 -1
  107. package/dist/buffer.mjs +0 -41
  108. package/dist/buffer.mjs.map +0 -1
  109. package/dist/clipboard.cjs +0 -91
  110. package/dist/clipboard.cjs.map +0 -1
  111. package/dist/clipboard.mjs +0 -88
  112. package/dist/clipboard.mjs.map +0 -1
  113. package/dist/consola.cjs +0 -35
  114. package/dist/consola.cjs.map +0 -1
  115. package/dist/consola.mjs +0 -32
  116. package/dist/consola.mjs.map +0 -1
  117. package/dist/crypto-hash.cjs +0 -61
  118. package/dist/crypto-hash.cjs.map +0 -1
  119. package/dist/crypto-hash.mjs +0 -50
  120. package/dist/crypto-hash.mjs.map +0 -1
  121. package/dist/datetime.cjs +0 -134
  122. package/dist/datetime.cjs.map +0 -1
  123. package/dist/datetime.mjs +0 -130
  124. package/dist/datetime.mjs.map +0 -1
  125. package/dist/element-plus.cjs +0 -37
  126. package/dist/element-plus.cjs.map +0 -1
  127. package/dist/element-plus.mjs +0 -35
  128. package/dist/element-plus.mjs.map +0 -1
  129. package/dist/enum.cjs +0 -112
  130. package/dist/enum.cjs.map +0 -1
  131. package/dist/enum.mjs +0 -108
  132. package/dist/enum.mjs.map +0 -1
  133. package/dist/env.cjs +0 -53
  134. package/dist/env.cjs.map +0 -1
  135. package/dist/env.mjs +0 -50
  136. package/dist/env.mjs.map +0 -1
  137. package/dist/general.cjs +0 -10
  138. package/dist/general.cjs.map +0 -1
  139. package/dist/general.mjs +0 -8
  140. package/dist/general.mjs.map +0 -1
  141. package/dist/hash.cjs +0 -36
  142. package/dist/hash.cjs.map +0 -1
  143. package/dist/hash.mjs +0 -31
  144. package/dist/hash.mjs.map +0 -1
  145. package/dist/math.cjs +0 -38
  146. package/dist/math.cjs.map +0 -1
  147. package/dist/math.mjs +0 -36
  148. package/dist/math.mjs.map +0 -1
  149. package/dist/number.cjs +0 -32
  150. package/dist/number.cjs.map +0 -1
  151. package/dist/number.mjs +0 -30
  152. package/dist/number.mjs.map +0 -1
  153. package/dist/object.cjs +0 -55
  154. package/dist/object.cjs.map +0 -1
  155. package/dist/object.mjs +0 -53
  156. package/dist/object.mjs.map +0 -1
  157. package/dist/pino.cjs +0 -42
  158. package/dist/pino.cjs.map +0 -1
  159. package/dist/pino.mjs +0 -39
  160. package/dist/pino.mjs.map +0 -1
  161. package/dist/random.cjs +0 -31
  162. package/dist/random.cjs.map +0 -1
  163. package/dist/random.mjs +0 -29
  164. package/dist/random.mjs.map +0 -1
  165. package/dist/storage/enhanced/local/core.cjs +0 -105
  166. package/dist/storage/enhanced/local/core.cjs.map +0 -1
  167. package/dist/storage/enhanced/local/core.mjs +0 -103
  168. package/dist/storage/enhanced/local/core.mjs.map +0 -1
  169. package/dist/storage/enhanced/local/index.cjs +0 -10
  170. package/dist/storage/enhanced/local/index.cjs.map +0 -1
  171. package/dist/storage/enhanced/local/index.d.ts.map +0 -1
  172. package/dist/storage/enhanced/local/index.mjs +0 -3
  173. package/dist/storage/enhanced/local/index.mjs.map +0 -1
  174. package/dist/storage/enhanced/local/keyed-store.cjs +0 -41
  175. package/dist/storage/enhanced/local/keyed-store.cjs.map +0 -1
  176. package/dist/storage/enhanced/local/keyed-store.mjs +0 -39
  177. package/dist/storage/enhanced/local/keyed-store.mjs.map +0 -1
  178. package/dist/storage/enhanced/redis/core.cjs +0 -144
  179. package/dist/storage/enhanced/redis/core.cjs.map +0 -1
  180. package/dist/storage/enhanced/redis/core.mjs +0 -142
  181. package/dist/storage/enhanced/redis/core.mjs.map +0 -1
  182. package/dist/storage/enhanced/redis/index.cjs +0 -10
  183. package/dist/storage/enhanced/redis/index.cjs.map +0 -1
  184. package/dist/storage/enhanced/redis/index.d.ts.map +0 -1
  185. package/dist/storage/enhanced/redis/index.mjs +0 -3
  186. package/dist/storage/enhanced/redis/index.mjs.map +0 -1
  187. package/dist/storage/enhanced/redis/keyed-store.cjs +0 -46
  188. package/dist/storage/enhanced/redis/keyed-store.cjs.map +0 -1
  189. package/dist/storage/enhanced/redis/keyed-store.mjs +0 -44
  190. package/dist/storage/enhanced/redis/keyed-store.mjs.map +0 -1
  191. package/dist/storage/lru/keyed-store.cjs +0 -49
  192. package/dist/storage/lru/keyed-store.cjs.map +0 -1
  193. package/dist/storage/lru/keyed-store.mjs +0 -47
  194. package/dist/storage/lru/keyed-store.mjs.map +0 -1
  195. package/dist/string.cjs +0 -45
  196. package/dist/string.cjs.map +0 -1
  197. package/dist/string.mjs +0 -43
  198. package/dist/string.mjs.map +0 -1
  199. package/dist/url.cjs +0 -21
  200. package/dist/url.cjs.map +0 -1
  201. package/dist/url.mjs +0 -19
  202. package/dist/url.mjs.map +0 -1
  203. package/dist/vue.cjs +0 -64
  204. package/dist/vue.cjs.map +0 -1
  205. package/dist/vue.mjs +0 -59
  206. package/dist/vue.mjs.map +0 -1
  207. package/dist/web.cjs +0 -35
  208. package/dist/web.cjs.map +0 -1
  209. package/dist/web.mjs +0 -32
  210. package/dist/web.mjs.map +0 -1
package/dist/datetime.cjs DELETED
@@ -1,134 +0,0 @@
1
- 'use strict';
2
-
3
- const dateFns = require('date-fns');
4
-
5
- /**
6
- * Formats a given date, timestamp, or date string into a specified format.
7
- *
8
- * This function is a wrapper around `date-fns/format`.
9
- *
10
- * @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string
11
- * @param {string} [format] - The target format string
12
- * @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`
13
- *
14
- * @returns {string} The formatted date string
15
- *
16
- * @example
17
- * ```typescript
18
- * import { formatDate } from '@kikiutils/shared/datetime';
19
- *
20
- * // Format a Date object
21
- * console.log(formatDate(new Date(), 'yyyy-MM-dd')); // 2024-07-10
22
- *
23
- * // Format a timestamp
24
- * console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15
25
- *
26
- * // Format a date string
27
- * console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
28
- * ```
29
- *
30
- * @see https://date-fns.org/docs/format
31
- */
32
- function formatDate(date, format = 'yyyy-MM-dd HH:mm:ss', options) {
33
- return dateFns.format(date, format, options);
34
- }
35
- /**
36
- * Get the date range (start and end) based on a given date and range type.
37
- *
38
- * Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.
39
- *
40
- * @param {Date} date - The reference date
41
- * @param {DateRangeType} type - The range type to compute
42
- * @param {object} [options] - Optional settings
43
- * @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
44
- * @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
45
- *
46
- * @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`
47
- *
48
- * @example
49
- * ```typescript
50
- * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';
51
- *
52
- * // Get the date range for last month
53
- * const date = new Date('2023-07-01');
54
- * console.log(getDateRangeFromDate(date, 'lastMonth'));
55
- * // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }
56
- *
57
- * // Get this week's range with Sunday as the first day
58
- * console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));
59
- * // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }
60
- * ```
61
- */
62
- function getDateRangeFromDate(date, type, options) {
63
- let endDate;
64
- let startDate;
65
- switch (type) {
66
- case 'lastMonth':
67
- {
68
- const lastMonth = dateFns.subMonths(date, 1);
69
- endDate = dateFns.endOfMonth(lastMonth);
70
- startDate = dateFns.startOfMonth(lastMonth);
71
- }
72
- break;
73
- case 'lastWeek':
74
- {
75
- const lastWeek = dateFns.subWeeks(date, 1);
76
- endDate = dateFns.endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
77
- startDate = dateFns.startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
78
- }
79
- break;
80
- case 'thisMonth':
81
- endDate = dateFns.endOfMonth(date);
82
- startDate = dateFns.startOfMonth(date);
83
- break;
84
- case 'thisWeek':
85
- endDate = dateFns.endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
86
- startDate = dateFns.startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
87
- break;
88
- case 'today':
89
- endDate = dateFns.endOfDay(date);
90
- startDate = dateFns.startOfDay(date);
91
- break;
92
- case 'yesterday':
93
- {
94
- const yesterday = dateFns.subDays(date, 1);
95
- endDate = dateFns.endOfDay(yesterday);
96
- startDate = dateFns.startOfDay(yesterday);
97
- }
98
- break;
99
- default: throw new Error(`Unsupported date range type: ${type}`);
100
- }
101
- if (options?.setEndDateToNextDayStart)
102
- endDate.setHours(24, 0, 0, 0);
103
- return {
104
- endDate,
105
- startDate,
106
- };
107
- }
108
- /**
109
- * Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
110
- *
111
- * @param {number} [offsetDays] - Number of days to offset from today. Can be negative
112
- *
113
- * @returns {Date} A `Date` object at 00:00:00 of the offset day
114
- *
115
- * @example
116
- * ```typescript
117
- * import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';
118
- *
119
- * console.log(getMidnightDateFromToday()); // today at 00:00:00
120
- * console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00
121
- * console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00
122
- * ```
123
- */
124
- function getMidnightDateFromToday(offsetDays = 0) {
125
- const date = new Date();
126
- date.setDate(date.getDate() + offsetDays);
127
- date.setHours(0, 0, 0, 0);
128
- return date;
129
- }
130
-
131
- exports.formatDate = formatDate;
132
- exports.getDateRangeFromDate = getDateRangeFromDate;
133
- exports.getMidnightDateFromToday = getMidnightDateFromToday;
134
- //# sourceMappingURL=datetime.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"datetime.cjs","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 *\n * @see https://date-fns.org/docs/format\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"],"names":["dateFnsFormat","subMonths","endOfMonth","startOfMonth","subWeeks","endOfWeek","startOfWeek","endOfDay","startOfDay","subDays"],"mappings":";;;;AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,UAAU,CAAC,IAAwB,EAAE,MAAA,GAAiB,qBAAqB,EAAE,OAAuB,EAAA;IAChH,OAAOA,cAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC;AAC/C;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;SACa,oBAAoB,CAChC,IAAU,EACV,IAAmB,EACnB,OAGC,EAAA;AAED,IAAA,IAAI,OAAa;AACjB,IAAA,IAAI,SAAe;IACnB,QAAQ,IAAI;AACR,QAAA,KAAK,WAAW;YACZ;gBACI,MAAM,SAAS,GAAGC,iBAAS,CAAC,IAAI,EAAE,CAAC,CAAC;AACpC,gBAAA,OAAO,GAAGC,kBAAU,CAAC,SAAS,CAAC;AAC/B,gBAAA,SAAS,GAAGC,oBAAY,CAAC,SAAS,CAAC;YACvC;YAEA;AACJ,QAAA,KAAK,UAAU;YACX;gBACI,MAAM,QAAQ,GAAGC,gBAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AAClC,gBAAA,OAAO,GAAGC,iBAAS,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;AAC3E,gBAAA,SAAS,GAAGC,mBAAW,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;YACnF;YAEA;AACJ,QAAA,KAAK,WAAW;AACZ,YAAA,OAAO,GAAGJ,kBAAU,CAAC,IAAI,CAAC;AAC1B,YAAA,SAAS,GAAGC,oBAAY,CAAC,IAAI,CAAC;YAC9B;AACJ,QAAA,KAAK,UAAU;AACX,YAAA,OAAO,GAAGE,iBAAS,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;AACvE,YAAA,SAAS,GAAGC,mBAAW,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;YAC3E;AACJ,QAAA,KAAK,OAAO;AACR,YAAA,OAAO,GAAGC,gBAAQ,CAAC,IAAI,CAAC;AACxB,YAAA,SAAS,GAAGC,kBAAU,CAAC,IAAI,CAAC;YAC5B;AACJ,QAAA,KAAK,WAAW;YACZ;gBACI,MAAM,SAAS,GAAGC,eAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAClC,gBAAA,OAAO,GAAGF,gBAAQ,CAAC,SAAS,CAAC;AAC7B,gBAAA,SAAS,GAAGC,kBAAU,CAAC,SAAS,CAAC;YACrC;YAEA;QACJ,SAAS,MAAM,IAAI,KAAK,CAAC,CAAA,6BAAA,EAAgC,IAAI,CAAA,CAAE,CAAC;;IAGpE,IAAI,OAAO,EAAE,wBAAwB;QAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACpE,OAAO;QACH,OAAO;QACP,SAAS;KACZ;AACL;AAEA;;;;;;;;;;;;;;;AAeG;AACG,SAAU,wBAAwB,CAAC,UAAA,GAAqB,CAAC,EAAA;AAC3D,IAAA,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE;IACvB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC;IACzC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACzB,IAAA,OAAO,IAAI;AACf;;;;;;"}
package/dist/datetime.mjs DELETED
@@ -1,130 +0,0 @@
1
- import { format, subDays, endOfDay, startOfDay, endOfWeek, startOfWeek, endOfMonth, startOfMonth, subWeeks, subMonths } from 'date-fns';
2
-
3
- /**
4
- * Formats a given date, timestamp, or date string into a specified format.
5
- *
6
- * This function is a wrapper around `date-fns/format`.
7
- *
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
- *
12
- * @returns {string} The formatted date string
13
- *
14
- * @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
- *
21
- * // Format a timestamp
22
- * console.log(formatDate(1657814400000, 'yyyy-MM-dd')); // 2022-07-15
23
- *
24
- * // Format a date string
25
- * console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
26
- * ```
27
- *
28
- * @see https://date-fns.org/docs/format
29
- */
30
- function formatDate(date, format$1 = 'yyyy-MM-dd HH:mm:ss', options) {
31
- return format(date, format$1, options);
32
- }
33
- /**
34
- * Get the date range (start and end) based on a given date and range type.
35
- *
36
- * Supports common range types like 'lastMonth', 'lastWeek', 'thisMonth', 'thisWeek', 'today', and 'yesterday'.
37
- *
38
- * @param {Date} date - The reference date
39
- * @param {DateRangeType} type - The range type to compute
40
- * @param {object} [options] - Optional settings
41
- * @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day
42
- * @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
43
- *
44
- * @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`
45
- *
46
- * @example
47
- * ```typescript
48
- * import { getDateRangeFromDate } from '@kikiutils/shared/datetime';
49
- *
50
- * // Get the date range for last month
51
- * const date = new Date('2023-07-01');
52
- * console.log(getDateRangeFromDate(date, 'lastMonth'));
53
- * // { startDate: 2023-06-01T00:00:00.000Z, endDate: 2023-06-30T23:59:59.999Z }
54
- *
55
- * // Get this week's range with Sunday as the first day
56
- * console.log(getDateRangeFromDate(date, 'thisWeek', { weekStartsOn: 0 }));
57
- * // { startDate: 2023-06-25T00:00:00.000Z, endDate: 2023-07-01T23:59:59.999Z }
58
- * ```
59
- */
60
- function getDateRangeFromDate(date, type, options) {
61
- let endDate;
62
- let startDate;
63
- switch (type) {
64
- case 'lastMonth':
65
- {
66
- const lastMonth = subMonths(date, 1);
67
- endDate = endOfMonth(lastMonth);
68
- startDate = startOfMonth(lastMonth);
69
- }
70
- break;
71
- case 'lastWeek':
72
- {
73
- const lastWeek = subWeeks(date, 1);
74
- endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
75
- startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
76
- }
77
- break;
78
- case 'thisMonth':
79
- endDate = endOfMonth(date);
80
- startDate = startOfMonth(date);
81
- break;
82
- case 'thisWeek':
83
- endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
84
- startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
85
- break;
86
- case 'today':
87
- endDate = endOfDay(date);
88
- startDate = startOfDay(date);
89
- break;
90
- case 'yesterday':
91
- {
92
- const yesterday = subDays(date, 1);
93
- endDate = endOfDay(yesterday);
94
- startDate = startOfDay(yesterday);
95
- }
96
- break;
97
- default: throw new Error(`Unsupported date range type: ${type}`);
98
- }
99
- if (options?.setEndDateToNextDayStart)
100
- endDate.setHours(24, 0, 0, 0);
101
- return {
102
- endDate,
103
- startDate,
104
- };
105
- }
106
- /**
107
- * Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
108
- *
109
- * @param {number} [offsetDays] - Number of days to offset from today. Can be negative
110
- *
111
- * @returns {Date} A `Date` object at 00:00:00 of the offset day
112
- *
113
- * @example
114
- * ```typescript
115
- * import { getMidnightDateFromToday } from '@kikiutils/shared/datetime';
116
- *
117
- * console.log(getMidnightDateFromToday()); // today at 00:00:00
118
- * console.log(getMidnightDateFromToday(3)); // 3 days from today at 00:00:00
119
- * console.log(getMidnightDateFromToday(-1)); // yesterday at 00:00:00
120
- * ```
121
- */
122
- function getMidnightDateFromToday(offsetDays = 0) {
123
- const date = new Date();
124
- date.setDate(date.getDate() + offsetDays);
125
- date.setHours(0, 0, 0, 0);
126
- return date;
127
- }
128
-
129
- export { formatDate, getDateRangeFromDate, getMidnightDateFromToday };
130
- //# sourceMappingURL=datetime.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"datetime.mjs","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 *\n * @see https://date-fns.org/docs/format\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"],"names":["format","dateFnsFormat"],"mappings":";;AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,UAAU,CAAC,IAAwB,EAAEA,QAAA,GAAiB,qBAAqB,EAAE,OAAuB,EAAA;IAChH,OAAOC,MAAa,CAAC,IAAI,EAAED,QAAM,EAAE,OAAO,CAAC;AAC/C;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;SACa,oBAAoB,CAChC,IAAU,EACV,IAAmB,EACnB,OAGC,EAAA;AAED,IAAA,IAAI,OAAa;AACjB,IAAA,IAAI,SAAe;IACnB,QAAQ,IAAI;AACR,QAAA,KAAK,WAAW;YACZ;gBACI,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;AACpC,gBAAA,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC;AAC/B,gBAAA,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;YACvC;YAEA;AACJ,QAAA,KAAK,UAAU;YACX;gBACI,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AAClC,gBAAA,OAAO,GAAG,SAAS,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;AAC3E,gBAAA,SAAS,GAAG,WAAW,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;YACnF;YAEA;AACJ,QAAA,KAAK,WAAW;AACZ,YAAA,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC;AAC1B,YAAA,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC;YAC9B;AACJ,QAAA,KAAK,UAAU;AACX,YAAA,OAAO,GAAG,SAAS,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;AACvE,YAAA,SAAS,GAAG,WAAW,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;YAC3E;AACJ,QAAA,KAAK,OAAO;AACR,YAAA,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC;AACxB,YAAA,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC;YAC5B;AACJ,QAAA,KAAK,WAAW;YACZ;gBACI,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAClC,gBAAA,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC;AAC7B,gBAAA,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;YACrC;YAEA;QACJ,SAAS,MAAM,IAAI,KAAK,CAAC,CAAA,6BAAA,EAAgC,IAAI,CAAA,CAAE,CAAC;;IAGpE,IAAI,OAAO,EAAE,wBAAwB;QAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACpE,OAAO;QACH,OAAO;QACP,SAAS;KACZ;AACL;AAEA;;;;;;;;;;;;;;;AAeG;AACG,SAAU,wBAAwB,CAAC,UAAA,GAAqB,CAAC,EAAA;AAC3D,IAAA,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE;IACvB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC;IACzC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACzB,IAAA,OAAO,IAAI;AACf;;;;"}
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.
5
- *
6
- * This utility provides default values for `required`, `trigger`, and `type`,
7
- * while allowing overrides via the `options` parameter. It simplifies common
8
- * form validation rule creation and ensures consistency across forms.
9
- *
10
- * @param {string} message - The validation message to display when the rule fails
11
- * @param {FormItemRule} [options] - Optional overrides for the rule fields
12
- * @param {boolean} [options.required] - Whether the field is required (default: `true`)
13
- * @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
14
- * @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
15
- *
16
- * @returns A `FormItemRule` object that can be used in Element Plus form validation
17
- *
18
- * @example
19
- * ```typescript
20
- * import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';
21
- *
22
- * const rule = createElFormItemRuleWithDefaults('This field is required');
23
- * const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });
24
- * ```
25
- */
26
- function createElFormItemRuleWithDefaults(message, options = {}) {
27
- return {
28
- ...options,
29
- message,
30
- required: options.required ?? true,
31
- trigger: options.trigger ?? 'blur',
32
- type: options.type ?? 'string',
33
- };
34
- }
35
-
36
- exports.createElFormItemRuleWithDefaults = createElFormItemRuleWithDefaults;
37
- //# sourceMappingURL=element-plus.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"element-plus.cjs","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 {string} 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(message: string, options: FormItemRule = {}): 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"],"names":[],"mappings":";;AAKA;;;;;;;;;;;;;;;;;;;;;;AAsBG;SACa,gCAAgC,CAAC,OAAe,EAAE,UAAwB,EAAE,EAAA;IACxF,OAAO;AACH,QAAA,GAAG,OAAO;QACV,OAAO;AACP,QAAA,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;AAClC,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,MAAM;AAClC,QAAA,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,QAAQ;KACjC;AACL;;;;"}
@@ -1,35 +0,0 @@
1
- /**
2
- * Creates a reusable Element Plus `<el-form-item>` validation rule with sensible defaults.
3
- *
4
- * This utility provides default values for `required`, `trigger`, and `type`,
5
- * while allowing overrides via the `options` parameter. It simplifies common
6
- * form validation rule creation and ensures consistency across forms.
7
- *
8
- * @param {string} message - The validation message to display when the rule fails
9
- * @param {FormItemRule} [options] - Optional overrides for the rule fields
10
- * @param {boolean} [options.required] - Whether the field is required (default: `true`)
11
- * @param {string | string[]} [options.trigger] - The event(s) that trigger validation (default: `'blur'`)
12
- * @param {RuleType} [options.type] - The expected type of the field (default: `'string'`)
13
- *
14
- * @returns A `FormItemRule` object that can be used in Element Plus form validation
15
- *
16
- * @example
17
- * ```typescript
18
- * import { createElFormItemRuleWithDefaults } from '@kikiutils/shared/element-plus';
19
- *
20
- * const rule = createElFormItemRuleWithDefaults('This field is required');
21
- * const optionalRule = createElFormItemRuleWithDefaults('Optional field', { required: false });
22
- * ```
23
- */
24
- function createElFormItemRuleWithDefaults(message, options = {}) {
25
- return {
26
- ...options,
27
- message,
28
- required: options.required ?? true,
29
- trigger: options.trigger ?? 'blur',
30
- type: options.type ?? 'string',
31
- };
32
- }
33
-
34
- export { createElFormItemRuleWithDefaults };
35
- //# sourceMappingURL=element-plus.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"element-plus.mjs","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 {string} 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(message: string, options: FormItemRule = {}): 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"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;AAsBG;SACa,gCAAgC,CAAC,OAAe,EAAE,UAAwB,EAAE,EAAA;IACxF,OAAO;AACH,QAAA,GAAG,OAAO;QACV,OAAO;AACP,QAAA,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;AAClC,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,MAAM;AAClC,QAAA,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,QAAQ;KACjC;AACL;;;;"}
package/dist/enum.cjs DELETED
@@ -1,112 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Extracts only the numeric values from an enumeration-like object.
5
- *
6
- * @template T - The type of the enum object
7
- *
8
- * @param {T} enumObject - The enumeration-like object to extract numeric values from,
9
- * the object can contain numeric values, string values, or both.
10
- *
11
- * @returns {Extract<T[keyof T], number>[]} An array of numeric values extracted from the enum object
12
- *
13
- * @example
14
- * ```typescript
15
- * import { getEnumNumberValues } from '@kikiutils/shared/enum';
16
- *
17
- * enum RecordType {
18
- * Receive = 0,
19
- * Send = 1,
20
- * Unknown = 'unknown'
21
- * }
22
- *
23
- * console.log(getEnumNumberValues(RecordType)); // [0, 1]
24
- * ```
25
- */
26
- function getEnumNumberValues(enumObject) {
27
- return getEnumValues(enumObject).filter((value) => typeof value === 'number');
28
- }
29
- /**
30
- * Extracts only the string values from an enumeration-like object.
31
- *
32
- * @template T - The type of the enum object
33
- *
34
- * @param {T} enumObject - The enumeration-like object to extract string values from,
35
- * the object can contain numeric values, string values, or both.
36
- *
37
- * @returns {Extract<T[keyof T], string>[]} An array of string values extracted from the enum object
38
- *
39
- * @example
40
- * ```typescript
41
- * import { getEnumStringValues } from '@kikiutils/shared/enum';
42
- *
43
- * enum RecordType {
44
- * Receive = 0,
45
- * Send = 1,
46
- * Unknown = 'unknown'
47
- * }
48
- *
49
- * console.log(getEnumStringValues(RecordType)); // ['unknown']
50
- * ```
51
- */
52
- function getEnumStringValues(enumObject) {
53
- return getEnumValues(enumObject).filter((value) => typeof value === 'string');
54
- }
55
- /**
56
- * Extracts all values from an enumeration-like object.
57
- *
58
- * This function handles TypeScript enums correctly by accounting for the reverse mapping
59
- * that occurs with numeric enums. It works with pure numeric enums, pure string enums,
60
- * and mixed enums.
61
- *
62
- * @template T - The type of the enum object
63
- *
64
- * @param {T} enumObject - The enumeration-like object to extract values from,
65
- * the object can contain numeric values, string values, or both.
66
- *
67
- * @returns {(T[keyof T])[]} An array containing all the values from the enum object
68
- *
69
- * @example
70
- * ```typescript
71
- * import { getEnumValues } from '@kikiutils/shared/enum';
72
- *
73
- * // Numeric enum
74
- * enum Status {
75
- * Active = 0,
76
- * Inactive = 1,
77
- * Pending = 2
78
- * }
79
- *
80
- * console.log(getEnumValues(Status)); // [0, 1, 2]
81
- *
82
- * // String enum
83
- * enum Color {
84
- * Red = 'RED',
85
- * Green = 'GREEN',
86
- * Blue = 'BLUE'
87
- * }
88
- *
89
- * console.log(getEnumValues(Color)); // ['RED', 'GREEN', 'BLUE']
90
- *
91
- * // Mixed enum
92
- * enum RecordType {
93
- * Receive = 0,
94
- * Send = 1,
95
- * Unknown = 'unknown'
96
- * }
97
- *
98
- * console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']
99
- * ```
100
- */
101
- function getEnumValues(enumObject) {
102
- const values = Object.values(enumObject);
103
- const hasNumberValues = values.some((value) => typeof value === 'number');
104
- if (!hasNumberValues)
105
- return values;
106
- return Object.keys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);
107
- }
108
-
109
- exports.getEnumNumberValues = getEnumNumberValues;
110
- exports.getEnumStringValues = getEnumStringValues;
111
- exports.getEnumValues = getEnumValues;
112
- //# sourceMappingURL=enum.cjs.map
package/dist/enum.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"enum.cjs","sources":["../src/enum.ts"],"sourcesContent":["/**\n * Extracts only the numeric values from an enumeration-like object.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract numeric values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {Extract<T[keyof T], number>[]} An array of numeric values extracted from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumNumberValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumNumberValues(RecordType)); // [0, 1]\n * ```\n */\nexport function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], number>[] {\n return getEnumValues(enumObject).filter((value) => typeof value === 'number');\n}\n\n/**\n * Extracts only the string values from an enumeration-like object.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract string values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {Extract<T[keyof T], string>[]} An array of string values extracted from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumStringValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumStringValues(RecordType)); // ['unknown']\n * ```\n */\nexport function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], string>[] {\n return getEnumValues(enumObject).filter((value) => typeof value === 'string');\n}\n\n/**\n * Extracts all values from an enumeration-like object.\n *\n * This function handles TypeScript enums correctly by accounting for the reverse mapping\n * that occurs with numeric enums. It works with pure numeric enums, pure string enums,\n * and mixed enums.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {(T[keyof T])[]} An array containing all the values from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumValues } from '@kikiutils/shared/enum';\n *\n * // Numeric enum\n * enum Status {\n * Active = 0,\n * Inactive = 1,\n * Pending = 2\n * }\n *\n * console.log(getEnumValues(Status)); // [0, 1, 2]\n *\n * // String enum\n * enum Color {\n * Red = 'RED',\n * Green = 'GREEN',\n * Blue = 'BLUE'\n * }\n *\n * console.log(getEnumValues(Color)); // ['RED', 'GREEN', 'BLUE']\n *\n * // Mixed enum\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']\n * ```\n */\nexport function getEnumValues<T extends Record<string, any>>(enumObject: T): (T[keyof T])[] {\n const values = Object.values(enumObject);\n const hasNumberValues = values.some((value) => typeof value === 'number');\n if (!hasNumberValues) return values;\n return Object.keys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACG,SAAU,mBAAmB,CAAgC,UAAa,EAAA;AAC5E,IAAA,OAAO,aAAa,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC;AACjF;AAEA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACG,SAAU,mBAAmB,CAAgC,UAAa,EAAA;AAC5E,IAAA,OAAO,aAAa,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC;AACjF;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CG;AACG,SAAU,aAAa,CAAgC,UAAa,EAAA;IACtE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;AACxC,IAAA,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC;AACzE,IAAA,IAAI,CAAC,eAAe;AAAE,QAAA,OAAO,MAAM;AACnC,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,UAAU,CAAC,GAAG,CAAC,CAAC;AAC3G;;;;;;"}
package/dist/enum.mjs DELETED
@@ -1,108 +0,0 @@
1
- /**
2
- * Extracts only the numeric values from an enumeration-like object.
3
- *
4
- * @template T - The type of the enum object
5
- *
6
- * @param {T} enumObject - The enumeration-like object to extract numeric values from,
7
- * the object can contain numeric values, string values, or both.
8
- *
9
- * @returns {Extract<T[keyof T], number>[]} An array of numeric values extracted from the enum object
10
- *
11
- * @example
12
- * ```typescript
13
- * import { getEnumNumberValues } from '@kikiutils/shared/enum';
14
- *
15
- * enum RecordType {
16
- * Receive = 0,
17
- * Send = 1,
18
- * Unknown = 'unknown'
19
- * }
20
- *
21
- * console.log(getEnumNumberValues(RecordType)); // [0, 1]
22
- * ```
23
- */
24
- function getEnumNumberValues(enumObject) {
25
- return getEnumValues(enumObject).filter((value) => typeof value === 'number');
26
- }
27
- /**
28
- * Extracts only the string values from an enumeration-like object.
29
- *
30
- * @template T - The type of the enum object
31
- *
32
- * @param {T} enumObject - The enumeration-like object to extract string values from,
33
- * the object can contain numeric values, string values, or both.
34
- *
35
- * @returns {Extract<T[keyof T], string>[]} An array of string values extracted from the enum object
36
- *
37
- * @example
38
- * ```typescript
39
- * import { getEnumStringValues } from '@kikiutils/shared/enum';
40
- *
41
- * enum RecordType {
42
- * Receive = 0,
43
- * Send = 1,
44
- * Unknown = 'unknown'
45
- * }
46
- *
47
- * console.log(getEnumStringValues(RecordType)); // ['unknown']
48
- * ```
49
- */
50
- function getEnumStringValues(enumObject) {
51
- return getEnumValues(enumObject).filter((value) => typeof value === 'string');
52
- }
53
- /**
54
- * Extracts all values from an enumeration-like object.
55
- *
56
- * This function handles TypeScript enums correctly by accounting for the reverse mapping
57
- * that occurs with numeric enums. It works with pure numeric enums, pure string enums,
58
- * and mixed enums.
59
- *
60
- * @template T - The type of the enum object
61
- *
62
- * @param {T} enumObject - The enumeration-like object to extract values from,
63
- * the object can contain numeric values, string values, or both.
64
- *
65
- * @returns {(T[keyof T])[]} An array containing all the values from the enum object
66
- *
67
- * @example
68
- * ```typescript
69
- * import { getEnumValues } from '@kikiutils/shared/enum';
70
- *
71
- * // Numeric enum
72
- * enum Status {
73
- * Active = 0,
74
- * Inactive = 1,
75
- * Pending = 2
76
- * }
77
- *
78
- * console.log(getEnumValues(Status)); // [0, 1, 2]
79
- *
80
- * // String enum
81
- * enum Color {
82
- * Red = 'RED',
83
- * Green = 'GREEN',
84
- * Blue = 'BLUE'
85
- * }
86
- *
87
- * console.log(getEnumValues(Color)); // ['RED', 'GREEN', 'BLUE']
88
- *
89
- * // Mixed enum
90
- * enum RecordType {
91
- * Receive = 0,
92
- * Send = 1,
93
- * Unknown = 'unknown'
94
- * }
95
- *
96
- * console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']
97
- * ```
98
- */
99
- function getEnumValues(enumObject) {
100
- const values = Object.values(enumObject);
101
- const hasNumberValues = values.some((value) => typeof value === 'number');
102
- if (!hasNumberValues)
103
- return values;
104
- return Object.keys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);
105
- }
106
-
107
- export { getEnumNumberValues, getEnumStringValues, getEnumValues };
108
- //# sourceMappingURL=enum.mjs.map
package/dist/enum.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"enum.mjs","sources":["../src/enum.ts"],"sourcesContent":["/**\n * Extracts only the numeric values from an enumeration-like object.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract numeric values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {Extract<T[keyof T], number>[]} An array of numeric values extracted from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumNumberValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumNumberValues(RecordType)); // [0, 1]\n * ```\n */\nexport function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], number>[] {\n return getEnumValues(enumObject).filter((value) => typeof value === 'number');\n}\n\n/**\n * Extracts only the string values from an enumeration-like object.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract string values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {Extract<T[keyof T], string>[]} An array of string values extracted from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumStringValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumStringValues(RecordType)); // ['unknown']\n * ```\n */\nexport function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], string>[] {\n return getEnumValues(enumObject).filter((value) => typeof value === 'string');\n}\n\n/**\n * Extracts all values from an enumeration-like object.\n *\n * This function handles TypeScript enums correctly by accounting for the reverse mapping\n * that occurs with numeric enums. It works with pure numeric enums, pure string enums,\n * and mixed enums.\n *\n * @template T - The type of the enum object\n *\n * @param {T} enumObject - The enumeration-like object to extract values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns {(T[keyof T])[]} An array containing all the values from the enum object\n *\n * @example\n * ```typescript\n * import { getEnumValues } from '@kikiutils/shared/enum';\n *\n * // Numeric enum\n * enum Status {\n * Active = 0,\n * Inactive = 1,\n * Pending = 2\n * }\n *\n * console.log(getEnumValues(Status)); // [0, 1, 2]\n *\n * // String enum\n * enum Color {\n * Red = 'RED',\n * Green = 'GREEN',\n * Blue = 'BLUE'\n * }\n *\n * console.log(getEnumValues(Color)); // ['RED', 'GREEN', 'BLUE']\n *\n * // Mixed enum\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown'\n * }\n *\n * console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']\n * ```\n */\nexport function getEnumValues<T extends Record<string, any>>(enumObject: T): (T[keyof T])[] {\n const values = Object.values(enumObject);\n const hasNumberValues = values.some((value) => typeof value === 'number');\n if (!hasNumberValues) return values;\n return Object.keys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACG,SAAU,mBAAmB,CAAgC,UAAa,EAAA;AAC5E,IAAA,OAAO,aAAa,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC;AACjF;AAEA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACG,SAAU,mBAAmB,CAAgC,UAAa,EAAA;AAC5E,IAAA,OAAO,aAAa,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC;AACjF;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CG;AACG,SAAU,aAAa,CAAgC,UAAa,EAAA;IACtE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;AACxC,IAAA,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC;AACzE,IAAA,IAAI,CAAC,eAAe;AAAE,QAAA,OAAO,MAAM;AACnC,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,UAAU,CAAC,GAAG,CAAC,CAAC;AAC3G;;;;"}