@meng-xi/vite-plugin 0.0.9 → 0.1.1

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 (105) hide show
  1. package/README-en.md +467 -269
  2. package/README.md +451 -254
  3. package/dist/common/format/index.cjs +1 -0
  4. package/dist/common/format/index.d.cts +156 -0
  5. package/dist/common/format/index.d.mts +156 -0
  6. package/dist/common/format/index.d.ts +156 -0
  7. package/dist/common/format/index.mjs +1 -0
  8. package/dist/common/fs/index.cjs +1 -0
  9. package/dist/common/fs/index.d.cts +150 -0
  10. package/dist/common/fs/index.d.mts +150 -0
  11. package/dist/common/fs/index.d.ts +150 -0
  12. package/dist/common/fs/index.mjs +1 -0
  13. package/dist/common/html/index.cjs +2 -0
  14. package/dist/common/html/index.d.cts +109 -0
  15. package/dist/common/html/index.d.mts +109 -0
  16. package/dist/common/html/index.d.ts +109 -0
  17. package/dist/common/html/index.mjs +2 -0
  18. package/dist/common/index.cjs +1 -1
  19. package/dist/common/index.d.cts +7 -318
  20. package/dist/common/index.d.mts +7 -318
  21. package/dist/common/index.d.ts +7 -318
  22. package/dist/common/index.mjs +1 -1
  23. package/dist/common/object/index.cjs +1 -0
  24. package/dist/common/object/index.d.cts +30 -0
  25. package/dist/common/object/index.d.mts +30 -0
  26. package/dist/common/object/index.d.ts +30 -0
  27. package/dist/common/object/index.mjs +1 -0
  28. package/dist/common/script/index.cjs +1 -0
  29. package/dist/common/script/index.d.cts +54 -0
  30. package/dist/common/script/index.d.mts +54 -0
  31. package/dist/common/script/index.d.ts +54 -0
  32. package/dist/common/script/index.mjs +1 -0
  33. package/dist/common/validation/index.cjs +1 -0
  34. package/dist/common/validation/index.d.cts +93 -0
  35. package/dist/common/validation/index.d.mts +93 -0
  36. package/dist/common/validation/index.d.ts +93 -0
  37. package/dist/common/validation/index.mjs +1 -0
  38. package/dist/factory/index.cjs +1 -1
  39. package/dist/factory/index.d.cts +1 -1
  40. package/dist/factory/index.d.mts +1 -1
  41. package/dist/factory/index.d.ts +1 -1
  42. package/dist/factory/index.mjs +1 -1
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.d.cts +15 -3
  45. package/dist/index.d.mts +15 -3
  46. package/dist/index.d.ts +15 -3
  47. package/dist/index.mjs +1 -1
  48. package/dist/plugins/buildProgress/index.cjs +2 -0
  49. package/dist/plugins/buildProgress/index.d.cts +187 -0
  50. package/dist/plugins/buildProgress/index.d.mts +187 -0
  51. package/dist/plugins/buildProgress/index.d.ts +187 -0
  52. package/dist/plugins/buildProgress/index.mjs +2 -0
  53. package/dist/plugins/copyFile/index.cjs +1 -0
  54. package/dist/plugins/copyFile/index.d.cts +78 -0
  55. package/dist/plugins/copyFile/index.d.mts +78 -0
  56. package/dist/plugins/copyFile/index.d.ts +78 -0
  57. package/dist/plugins/copyFile/index.mjs +1 -0
  58. package/dist/plugins/faviconManager/index.cjs +1 -0
  59. package/dist/plugins/faviconManager/index.d.cts +143 -0
  60. package/dist/plugins/faviconManager/index.d.mts +143 -0
  61. package/dist/plugins/faviconManager/index.d.ts +143 -0
  62. package/dist/plugins/faviconManager/index.mjs +1 -0
  63. package/dist/plugins/generateRouter/index.cjs +35 -0
  64. package/dist/plugins/generateRouter/index.d.cts +215 -0
  65. package/dist/plugins/generateRouter/index.d.mts +215 -0
  66. package/dist/plugins/generateRouter/index.d.ts +215 -0
  67. package/dist/plugins/generateRouter/index.mjs +35 -0
  68. package/dist/plugins/generateVersion/index.cjs +1 -0
  69. package/dist/plugins/generateVersion/index.d.cts +184 -0
  70. package/dist/plugins/generateVersion/index.d.mts +184 -0
  71. package/dist/plugins/generateVersion/index.d.ts +184 -0
  72. package/dist/plugins/generateVersion/index.mjs +1 -0
  73. package/dist/plugins/htmlInject/index.cjs +7 -0
  74. package/dist/plugins/htmlInject/index.d.cts +278 -0
  75. package/dist/plugins/htmlInject/index.d.mts +278 -0
  76. package/dist/plugins/htmlInject/index.d.ts +278 -0
  77. package/dist/plugins/htmlInject/index.mjs +7 -0
  78. package/dist/plugins/index.cjs +1 -1
  79. package/dist/plugins/index.d.cts +10 -1520
  80. package/dist/plugins/index.d.mts +10 -1520
  81. package/dist/plugins/index.d.ts +10 -1520
  82. package/dist/plugins/index.mjs +1 -1
  83. package/dist/plugins/loadingManager/index.cjs +487 -0
  84. package/dist/plugins/loadingManager/index.d.cts +769 -0
  85. package/dist/plugins/loadingManager/index.d.mts +769 -0
  86. package/dist/plugins/loadingManager/index.d.ts +769 -0
  87. package/dist/plugins/loadingManager/index.mjs +487 -0
  88. package/dist/plugins/versionUpdateChecker/index.cjs +185 -0
  89. package/dist/plugins/versionUpdateChecker/index.d.cts +200 -0
  90. package/dist/plugins/versionUpdateChecker/index.d.mts +200 -0
  91. package/dist/plugins/versionUpdateChecker/index.d.ts +200 -0
  92. package/dist/plugins/versionUpdateChecker/index.mjs +185 -0
  93. package/dist/shared/vite-plugin.Bcg6RW2N.cjs +3 -0
  94. package/dist/shared/{vite-plugin.CiHfwMiN.d.cts → vite-plugin.DRRlWY8P.d.cts} +50 -0
  95. package/dist/shared/{vite-plugin.CiHfwMiN.d.mts → vite-plugin.DRRlWY8P.d.mts} +50 -0
  96. package/dist/shared/{vite-plugin.CiHfwMiN.d.ts → vite-plugin.DRRlWY8P.d.ts} +50 -0
  97. package/dist/shared/{vite-plugin.B88RyRN8.mjs → vite-plugin.DcExl6jd.mjs} +2 -2
  98. package/package.json +72 -2
  99. package/dist/shared/vite-plugin.BI4kA-bR.mjs +0 -526
  100. package/dist/shared/vite-plugin.Ba9646wL.cjs +0 -1
  101. package/dist/shared/vite-plugin.C3ejdBNf.mjs +0 -1
  102. package/dist/shared/vite-plugin.CawoITTT.cjs +0 -1
  103. package/dist/shared/vite-plugin.CsdNNQ-4.cjs +0 -526
  104. package/dist/shared/vite-plugin.DSb6XzBn.mjs +0 -1
  105. package/dist/shared/vite-plugin.IGZeStMa.cjs +0 -3
@@ -0,0 +1 @@
1
+ "use strict";const crypto=require("crypto");function padNumber(e,t=2){return e.toString().padStart(t,"0")}function generateRandomHash(e=8){const t=Math.max(1,Math.min(64,e));return crypto.randomBytes(Math.ceil(t/2)).toString("hex").slice(0,t)}function getDateFormatParams(e=new Date){return{YYYY:e.getFullYear().toString(),YY:e.getFullYear().toString().slice(-2),MM:padNumber(e.getMonth()+1),DD:padNumber(e.getDate()),HH:padNumber(e.getHours()),mm:padNumber(e.getMinutes()),ss:padNumber(e.getSeconds()),SSS:padNumber(e.getMilliseconds(),3),timestamp:e.getTime().toString()}}function formatDate(e,t){const r=getDateFormatParams(e);let a=t;for(const[o,n]of Object.entries(r))a=a.replace(new RegExp(`\\{${o}\\}`,"g"),n);return a}function parseTemplate(e,t){let r=e;for(const[a,o]of Object.entries(t))r=r.replace(new RegExp(`\\{${a}\\}`,"g"),o);return r}function toCamelCase(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map((r,a)=>a===0?r.toLowerCase():r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function toPascalCase(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function stripJsonComments(e){return e.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function escapeHtmlAttr(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}exports.escapeHtmlAttr=escapeHtmlAttr,exports.formatDate=formatDate,exports.generateRandomHash=generateRandomHash,exports.getDateFormatParams=getDateFormatParams,exports.padNumber=padNumber,exports.parseTemplate=parseTemplate,exports.stripJsonComments=stripJsonComments,exports.toCamelCase=toCamelCase,exports.toPascalCase=toPascalCase;
@@ -0,0 +1,156 @@
1
+ /**
2
+ * 日期格式化选项
3
+ */
4
+ interface DateFormatOptions {
5
+ /** 四位年份 */
6
+ YYYY: string;
7
+ /** 两位年份 */
8
+ YY: string;
9
+ /** 两位月份 */
10
+ MM: string;
11
+ /** 两位日期 */
12
+ DD: string;
13
+ /** 两位小时(24小时制) */
14
+ HH: string;
15
+ /** 两位分钟 */
16
+ mm: string;
17
+ /** 两位秒数 */
18
+ ss: string;
19
+ /** 三位毫秒 */
20
+ SSS: string;
21
+ /** 时间戳(毫秒) */
22
+ timestamp: string;
23
+ }
24
+
25
+ /**
26
+ * 数字补零格式化
27
+ *
28
+ * @param num 要格式化的数字
29
+ * @param length 目标长度
30
+ * @returns 补零后的字符串
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * padNumber(5, 2) // '05'
35
+ * padNumber(12, 3) // '012'
36
+ * padNumber(123, 2) // '123'
37
+ * ```
38
+ */
39
+ declare function padNumber(num: number, length?: number): string;
40
+ /**
41
+ * 生成随机哈希字符串
42
+ *
43
+ * @param length 哈希长度,范围 1-64
44
+ * @returns 随机哈希字符串
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * generateRandomHash(8) // 'a1b2c3d4'
49
+ * generateRandomHash(16) // 'a1b2c3d4e5f6g7h8'
50
+ * ```
51
+ */
52
+ declare function generateRandomHash(length?: number): string;
53
+ /**
54
+ * 获取日期格式化参数
55
+ *
56
+ * @param date 日期对象
57
+ * @returns 日期格式化参数对象
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const params = getDateFormatParams(new Date())
62
+ * // { YYYY: '2026', MM: '02', DD: '03', HH: '15', mm: '30', ss: '00', ... }
63
+ * ```
64
+ */
65
+ declare function getDateFormatParams(date?: Date): DateFormatOptions;
66
+ /**
67
+ * 格式化日期
68
+ *
69
+ * @param date 日期对象
70
+ * @param format 格式模板
71
+ * @returns 格式化后的日期字符串
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * formatDate(new Date(), '{YYYY}-{MM}-{DD}') // '2026-02-03'
76
+ * formatDate(new Date(), '{YYYY}{MM}{DD}{HH}{mm}{ss}') // '20260203153000'
77
+ * formatDate(new Date(), '{YYYY}.{MM}.{DD}') // '2026.02.03'
78
+ * ```
79
+ */
80
+ declare function formatDate(date: Date, format: string): string;
81
+ /**
82
+ * 解析模板字符串,替换占位符
83
+ *
84
+ * @param template 模板字符串
85
+ * @param values 占位符值映射
86
+ * @returns 替换后的字符串
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * parseTemplate('{name}-{version}', { name: 'app', version: '1.0.0' })
91
+ * // 'app-1.0.0'
92
+ * ```
93
+ */
94
+ declare function parseTemplate(template: string, values: Record<string, string>): string;
95
+ /**
96
+ * 将字符串转换为驼峰命名(camelCase)
97
+ *
98
+ * @param str 输入字符串
99
+ * @param separators 分隔符正则,默认为斜杠和横线
100
+ * @returns 驼峰命名字符串
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * toCamelCase('pages/user/profile') // 'pagesUserProfile'
105
+ * toCamelCase('user-profile-page') // 'userProfilePage'
106
+ * toCamelCase('/pages/index') // 'pagesIndex'
107
+ * ```
108
+ */
109
+ declare function toCamelCase(str: string, separators?: RegExp): string;
110
+ /**
111
+ * 将字符串转换为帕斯卡命名(PascalCase)
112
+ *
113
+ * @param str 输入字符串
114
+ * @param separators 分隔符正则,默认为斜杠和横线
115
+ * @returns 帕斯卡命名字符串
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * toPascalCase('pages/user/profile') // 'PagesUserProfile'
120
+ * toPascalCase('user-profile-page') // 'UserProfilePage'
121
+ * toPascalCase('/pages/index') // 'PagesIndex'
122
+ * ```
123
+ */
124
+ declare function toPascalCase(str: string, separators?: RegExp): string;
125
+ /**
126
+ * 移除 JSON 字符串中的注释
127
+ *
128
+ * @param jsonString 包含注释的 JSON 字符串
129
+ * @returns 移除注释后的 JSON 字符串
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * stripJsonComments('{\n // comment\n "name": "test"\n}')
134
+ * // '{\n "name": "test"\n}'
135
+ * ```
136
+ */
137
+ declare function stripJsonComments(jsonString: string): string;
138
+ /**
139
+ * 转义 HTML 属性值中的特殊字符,防止 XSS 注入
140
+ *
141
+ * @param str - 需要转义的字符串
142
+ * @returns 转义后的安全字符串
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * escapeHtmlAttr('hello "world"')
147
+ * // 'hello &quot;world&quot;'
148
+ *
149
+ * escapeHtmlAttr('<script>alert(1)</script>')
150
+ * // '&lt;script&gt;alert(1)&lt;/script&gt;'
151
+ * ```
152
+ */
153
+ declare function escapeHtmlAttr(str: string): string;
154
+
155
+ export { escapeHtmlAttr, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase };
156
+ export type { DateFormatOptions };
@@ -0,0 +1,156 @@
1
+ /**
2
+ * 日期格式化选项
3
+ */
4
+ interface DateFormatOptions {
5
+ /** 四位年份 */
6
+ YYYY: string;
7
+ /** 两位年份 */
8
+ YY: string;
9
+ /** 两位月份 */
10
+ MM: string;
11
+ /** 两位日期 */
12
+ DD: string;
13
+ /** 两位小时(24小时制) */
14
+ HH: string;
15
+ /** 两位分钟 */
16
+ mm: string;
17
+ /** 两位秒数 */
18
+ ss: string;
19
+ /** 三位毫秒 */
20
+ SSS: string;
21
+ /** 时间戳(毫秒) */
22
+ timestamp: string;
23
+ }
24
+
25
+ /**
26
+ * 数字补零格式化
27
+ *
28
+ * @param num 要格式化的数字
29
+ * @param length 目标长度
30
+ * @returns 补零后的字符串
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * padNumber(5, 2) // '05'
35
+ * padNumber(12, 3) // '012'
36
+ * padNumber(123, 2) // '123'
37
+ * ```
38
+ */
39
+ declare function padNumber(num: number, length?: number): string;
40
+ /**
41
+ * 生成随机哈希字符串
42
+ *
43
+ * @param length 哈希长度,范围 1-64
44
+ * @returns 随机哈希字符串
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * generateRandomHash(8) // 'a1b2c3d4'
49
+ * generateRandomHash(16) // 'a1b2c3d4e5f6g7h8'
50
+ * ```
51
+ */
52
+ declare function generateRandomHash(length?: number): string;
53
+ /**
54
+ * 获取日期格式化参数
55
+ *
56
+ * @param date 日期对象
57
+ * @returns 日期格式化参数对象
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const params = getDateFormatParams(new Date())
62
+ * // { YYYY: '2026', MM: '02', DD: '03', HH: '15', mm: '30', ss: '00', ... }
63
+ * ```
64
+ */
65
+ declare function getDateFormatParams(date?: Date): DateFormatOptions;
66
+ /**
67
+ * 格式化日期
68
+ *
69
+ * @param date 日期对象
70
+ * @param format 格式模板
71
+ * @returns 格式化后的日期字符串
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * formatDate(new Date(), '{YYYY}-{MM}-{DD}') // '2026-02-03'
76
+ * formatDate(new Date(), '{YYYY}{MM}{DD}{HH}{mm}{ss}') // '20260203153000'
77
+ * formatDate(new Date(), '{YYYY}.{MM}.{DD}') // '2026.02.03'
78
+ * ```
79
+ */
80
+ declare function formatDate(date: Date, format: string): string;
81
+ /**
82
+ * 解析模板字符串,替换占位符
83
+ *
84
+ * @param template 模板字符串
85
+ * @param values 占位符值映射
86
+ * @returns 替换后的字符串
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * parseTemplate('{name}-{version}', { name: 'app', version: '1.0.0' })
91
+ * // 'app-1.0.0'
92
+ * ```
93
+ */
94
+ declare function parseTemplate(template: string, values: Record<string, string>): string;
95
+ /**
96
+ * 将字符串转换为驼峰命名(camelCase)
97
+ *
98
+ * @param str 输入字符串
99
+ * @param separators 分隔符正则,默认为斜杠和横线
100
+ * @returns 驼峰命名字符串
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * toCamelCase('pages/user/profile') // 'pagesUserProfile'
105
+ * toCamelCase('user-profile-page') // 'userProfilePage'
106
+ * toCamelCase('/pages/index') // 'pagesIndex'
107
+ * ```
108
+ */
109
+ declare function toCamelCase(str: string, separators?: RegExp): string;
110
+ /**
111
+ * 将字符串转换为帕斯卡命名(PascalCase)
112
+ *
113
+ * @param str 输入字符串
114
+ * @param separators 分隔符正则,默认为斜杠和横线
115
+ * @returns 帕斯卡命名字符串
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * toPascalCase('pages/user/profile') // 'PagesUserProfile'
120
+ * toPascalCase('user-profile-page') // 'UserProfilePage'
121
+ * toPascalCase('/pages/index') // 'PagesIndex'
122
+ * ```
123
+ */
124
+ declare function toPascalCase(str: string, separators?: RegExp): string;
125
+ /**
126
+ * 移除 JSON 字符串中的注释
127
+ *
128
+ * @param jsonString 包含注释的 JSON 字符串
129
+ * @returns 移除注释后的 JSON 字符串
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * stripJsonComments('{\n // comment\n "name": "test"\n}')
134
+ * // '{\n "name": "test"\n}'
135
+ * ```
136
+ */
137
+ declare function stripJsonComments(jsonString: string): string;
138
+ /**
139
+ * 转义 HTML 属性值中的特殊字符,防止 XSS 注入
140
+ *
141
+ * @param str - 需要转义的字符串
142
+ * @returns 转义后的安全字符串
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * escapeHtmlAttr('hello "world"')
147
+ * // 'hello &quot;world&quot;'
148
+ *
149
+ * escapeHtmlAttr('<script>alert(1)</script>')
150
+ * // '&lt;script&gt;alert(1)&lt;/script&gt;'
151
+ * ```
152
+ */
153
+ declare function escapeHtmlAttr(str: string): string;
154
+
155
+ export { escapeHtmlAttr, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase };
156
+ export type { DateFormatOptions };
@@ -0,0 +1,156 @@
1
+ /**
2
+ * 日期格式化选项
3
+ */
4
+ interface DateFormatOptions {
5
+ /** 四位年份 */
6
+ YYYY: string;
7
+ /** 两位年份 */
8
+ YY: string;
9
+ /** 两位月份 */
10
+ MM: string;
11
+ /** 两位日期 */
12
+ DD: string;
13
+ /** 两位小时(24小时制) */
14
+ HH: string;
15
+ /** 两位分钟 */
16
+ mm: string;
17
+ /** 两位秒数 */
18
+ ss: string;
19
+ /** 三位毫秒 */
20
+ SSS: string;
21
+ /** 时间戳(毫秒) */
22
+ timestamp: string;
23
+ }
24
+
25
+ /**
26
+ * 数字补零格式化
27
+ *
28
+ * @param num 要格式化的数字
29
+ * @param length 目标长度
30
+ * @returns 补零后的字符串
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * padNumber(5, 2) // '05'
35
+ * padNumber(12, 3) // '012'
36
+ * padNumber(123, 2) // '123'
37
+ * ```
38
+ */
39
+ declare function padNumber(num: number, length?: number): string;
40
+ /**
41
+ * 生成随机哈希字符串
42
+ *
43
+ * @param length 哈希长度,范围 1-64
44
+ * @returns 随机哈希字符串
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * generateRandomHash(8) // 'a1b2c3d4'
49
+ * generateRandomHash(16) // 'a1b2c3d4e5f6g7h8'
50
+ * ```
51
+ */
52
+ declare function generateRandomHash(length?: number): string;
53
+ /**
54
+ * 获取日期格式化参数
55
+ *
56
+ * @param date 日期对象
57
+ * @returns 日期格式化参数对象
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const params = getDateFormatParams(new Date())
62
+ * // { YYYY: '2026', MM: '02', DD: '03', HH: '15', mm: '30', ss: '00', ... }
63
+ * ```
64
+ */
65
+ declare function getDateFormatParams(date?: Date): DateFormatOptions;
66
+ /**
67
+ * 格式化日期
68
+ *
69
+ * @param date 日期对象
70
+ * @param format 格式模板
71
+ * @returns 格式化后的日期字符串
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * formatDate(new Date(), '{YYYY}-{MM}-{DD}') // '2026-02-03'
76
+ * formatDate(new Date(), '{YYYY}{MM}{DD}{HH}{mm}{ss}') // '20260203153000'
77
+ * formatDate(new Date(), '{YYYY}.{MM}.{DD}') // '2026.02.03'
78
+ * ```
79
+ */
80
+ declare function formatDate(date: Date, format: string): string;
81
+ /**
82
+ * 解析模板字符串,替换占位符
83
+ *
84
+ * @param template 模板字符串
85
+ * @param values 占位符值映射
86
+ * @returns 替换后的字符串
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * parseTemplate('{name}-{version}', { name: 'app', version: '1.0.0' })
91
+ * // 'app-1.0.0'
92
+ * ```
93
+ */
94
+ declare function parseTemplate(template: string, values: Record<string, string>): string;
95
+ /**
96
+ * 将字符串转换为驼峰命名(camelCase)
97
+ *
98
+ * @param str 输入字符串
99
+ * @param separators 分隔符正则,默认为斜杠和横线
100
+ * @returns 驼峰命名字符串
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * toCamelCase('pages/user/profile') // 'pagesUserProfile'
105
+ * toCamelCase('user-profile-page') // 'userProfilePage'
106
+ * toCamelCase('/pages/index') // 'pagesIndex'
107
+ * ```
108
+ */
109
+ declare function toCamelCase(str: string, separators?: RegExp): string;
110
+ /**
111
+ * 将字符串转换为帕斯卡命名(PascalCase)
112
+ *
113
+ * @param str 输入字符串
114
+ * @param separators 分隔符正则,默认为斜杠和横线
115
+ * @returns 帕斯卡命名字符串
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * toPascalCase('pages/user/profile') // 'PagesUserProfile'
120
+ * toPascalCase('user-profile-page') // 'UserProfilePage'
121
+ * toPascalCase('/pages/index') // 'PagesIndex'
122
+ * ```
123
+ */
124
+ declare function toPascalCase(str: string, separators?: RegExp): string;
125
+ /**
126
+ * 移除 JSON 字符串中的注释
127
+ *
128
+ * @param jsonString 包含注释的 JSON 字符串
129
+ * @returns 移除注释后的 JSON 字符串
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * stripJsonComments('{\n // comment\n "name": "test"\n}')
134
+ * // '{\n "name": "test"\n}'
135
+ * ```
136
+ */
137
+ declare function stripJsonComments(jsonString: string): string;
138
+ /**
139
+ * 转义 HTML 属性值中的特殊字符,防止 XSS 注入
140
+ *
141
+ * @param str - 需要转义的字符串
142
+ * @returns 转义后的安全字符串
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * escapeHtmlAttr('hello "world"')
147
+ * // 'hello &quot;world&quot;'
148
+ *
149
+ * escapeHtmlAttr('<script>alert(1)</script>')
150
+ * // '&lt;script&gt;alert(1)&lt;/script&gt;'
151
+ * ```
152
+ */
153
+ declare function escapeHtmlAttr(str: string): string;
154
+
155
+ export { escapeHtmlAttr, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase };
156
+ export type { DateFormatOptions };
@@ -0,0 +1 @@
1
+ import{randomBytes as i}from"crypto";function o(e,t=2){return e.toString().padStart(t,"0")}function l(e=8){const t=Math.max(1,Math.min(64,e));return i(Math.ceil(t/2)).toString("hex").slice(0,t)}function s(e=new Date){return{YYYY:e.getFullYear().toString(),YY:e.getFullYear().toString().slice(-2),MM:o(e.getMonth()+1),DD:o(e.getDate()),HH:o(e.getHours()),mm:o(e.getMinutes()),ss:o(e.getSeconds()),SSS:o(e.getMilliseconds(),3),timestamp:e.getTime().toString()}}function p(e,t){const r=s(e);let n=t;for(const[a,c]of Object.entries(r))n=n.replace(new RegExp(`\\{${a}\\}`,"g"),c);return n}function g(e,t){let r=e;for(const[n,a]of Object.entries(t))r=r.replace(new RegExp(`\\{${n}\\}`,"g"),a);return r}function m(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map((r,n)=>n===0?r.toLowerCase():r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function u(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function f(e){return e.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function S(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}export{S as escapeHtmlAttr,p as formatDate,l as generateRandomHash,s as getDateFormatParams,o as padNumber,g as parseTemplate,f as stripJsonComments,m as toCamelCase,u as toPascalCase};
@@ -0,0 +1 @@
1
+ "use strict";const s=require("fs"),u=require("path");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const s__default=_interopDefaultCompat(s),u__default=_interopDefaultCompat(u),S=10;async function checkSourceExists(t){try{await s__default.promises.access(t,s__default.constants.F_OK)}catch(e){const r=e;throw r.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${t}`):r.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${t}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function ensureTargetDir(t){try{await s__default.promises.mkdir(t,{recursive:!0})}catch(e){const r=e;throw r.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${t}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function readDirRecursive(t,e){const r=await s__default.promises.readdir(t,{withFileTypes:!0}),i=[];for(const n of r){const c=u__default.join(t,n.name),l=n.isFile(),F=n.isDirectory();if(i.push({path:c,isFile:l,isDirectory:F}),F&&e){const E=await readDirRecursive(c,e);i.push(...E)}}return i}async function shouldUpdateFile(t,e){try{const[r,i]=await Promise.all([s__default.promises.stat(t),s__default.promises.stat(e)]);return r.mtimeMs>i.mtimeMs||r.size!==i.size}catch{return!0}}async function fileExists(t){try{return await s__default.promises.access(t,s__default.constants.F_OK),!0}catch{return!1}}async function runWithConcurrency(t,e,r){const i=[];let n=0;async function c(){for(;n<t.length;){const F=n++,E=await e(t[F]);i[F]=E}}const l=Array(Math.min(r,t.length)).fill(null).map(()=>c());return await Promise.all(l),i}async function copySourceToTarget(t,e,r){const i=Date.now(),{recursive:n,overwrite:c,incremental:l=!1,parallelLimit:F=S}=r;let E=0,f=0,m=0;if((await s__default.promises.stat(t)).isDirectory()){await ensureTargetDir(e);const a=await readDirRecursive(t,n),D=a.filter(o=>o.isFile);m=a.filter(o=>o.isDirectory).length;const y=new Set;for(const o of D){const d=u__default.relative(t,o.path),p=u__default.dirname(u__default.join(e,d));y.add(p)}await Promise.all([...y].map(o=>ensureTargetDir(o)));const h=await runWithConcurrency(D,async o=>{const d=u__default.relative(t,o.path),p=u__default.join(e,d);let w=c;return w||(w=!await fileExists(p)),l&&w&&(w=await shouldUpdateFile(o.path,p)),w?(await s__default.promises.copyFile(o.path,p),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},F);for(const o of h)o.copied&&E++,o.skipped&&f++}else{await ensureTargetDir(u__default.dirname(e));let a=c;a||(a=!await fileExists(e)),l&&a&&(a=await shouldUpdateFile(t,e)),a?(await s__default.promises.copyFile(t,e),E++):f++}const A=Date.now()-i;return{copiedFiles:E,skippedFiles:f,copiedDirs:m,executionTime:A}}async function writeFileContent(t,e){try{await s__default.promises.writeFile(t,e,"utf-8")}catch(r){const i=r;throw i.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${t}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${i.message}`)}}async function readFileContent(t){try{return await s__default.promises.readFile(t,"utf-8")}catch(e){const r=e;throw r.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${t}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}function readFileSync(t){try{return s__default.readFileSync(t,"utf-8")}catch(e){const r=e;throw r.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${t}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}exports.checkSourceExists=checkSourceExists,exports.copySourceToTarget=copySourceToTarget,exports.ensureTargetDir=ensureTargetDir,exports.fileExists=fileExists,exports.readDirRecursive=readDirRecursive,exports.readFileContent=readFileContent,exports.readFileSync=readFileSync,exports.runWithConcurrency=runWithConcurrency,exports.shouldUpdateFile=shouldUpdateFile,exports.writeFileContent=writeFileContent;
@@ -0,0 +1,150 @@
1
+ /**
2
+ * 复制操作的选项接口
3
+ */
4
+ interface CopyOptions {
5
+ /**
6
+ * 是否支持递归复制
7
+ */
8
+ recursive: boolean;
9
+ /**
10
+ * 是否覆盖同名文件
11
+ */
12
+ overwrite: boolean;
13
+ /**
14
+ * 是否启用增量复制
15
+ */
16
+ incremental?: boolean;
17
+ /**
18
+ * 并行处理的最大文件数
19
+ */
20
+ parallelLimit?: number;
21
+ /**
22
+ * 是否跳过空目录
23
+ */
24
+ skipEmptyDirs?: boolean;
25
+ }
26
+ /**
27
+ * 复制结果接口
28
+ */
29
+ interface CopyResult {
30
+ /**
31
+ * 复制的文件数量
32
+ */
33
+ copiedFiles: number;
34
+ /**
35
+ * 跳过的文件数量
36
+ */
37
+ skippedFiles: number;
38
+ /**
39
+ * 复制的目录数量
40
+ */
41
+ copiedDirs: number;
42
+ /**
43
+ * 总执行时间(毫秒)
44
+ */
45
+ executionTime: number;
46
+ }
47
+
48
+ /**
49
+ * 文件/目录条目信息
50
+ */
51
+ interface FileEntry {
52
+ /** 完整路径 */
53
+ path: string;
54
+ /** 是否为文件 */
55
+ isFile: boolean;
56
+ /** 是否为目录 */
57
+ isDirectory: boolean;
58
+ }
59
+ /**
60
+ * 检查源文件是否存在
61
+ * @param sourcePath 源文件路径
62
+ * @throws 当源文件不存在或无法访问时抛出异常
63
+ */
64
+ declare function checkSourceExists(sourcePath: string): Promise<void>;
65
+ /**
66
+ * 创建目标目录
67
+ * @param targetPath 目标目录路径
68
+ * @throws 当无法创建目标目录时抛出异常
69
+ */
70
+ declare function ensureTargetDir(targetPath: string): Promise<void>;
71
+ /**
72
+ * 读取目录内容(优化版:一次性获取文件类型信息)
73
+ * @param dirPath 目录路径
74
+ * @param recursive 是否递归读取
75
+ * @returns 文件和目录条目列表
76
+ */
77
+ declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
78
+ /**
79
+ * 检查文件是否需要更新
80
+ * @param sourceFile 源文件路径
81
+ * @param targetFile 目标文件路径
82
+ * @returns 是否需要更新
83
+ */
84
+ declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
85
+ /**
86
+ * 检查文件是否存在
87
+ * @param filePath 文件路径
88
+ * @returns 是否存在
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * if (await fileExists('/path/to/file')) {
93
+ * console.log('文件存在')
94
+ * }
95
+ * ```
96
+ */
97
+ declare function fileExists(filePath: string): Promise<boolean>;
98
+ /**
99
+ * 带并发限制的批量执行
100
+ *
101
+ * @param items 待处理项
102
+ * @param handler 处理函数
103
+ * @param concurrency 并发数
104
+ * @returns 处理结果数组,顺序与输入项对应
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const urls = ['url1', 'url2', 'url3', 'url4', 'url5']
109
+ * const results = await runWithConcurrency(
110
+ * urls,
111
+ * async (url) => fetch(url),
112
+ * 3 // 最多同时处理3个请求
113
+ * )
114
+ * ```
115
+ */
116
+ declare function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>;
117
+ /**
118
+ * 执行文件复制操作(优化版:并行IO)
119
+ * @param sourcePath 源文件或目录路径
120
+ * @param targetPath 目标文件或目录路径
121
+ * @param options 复制选项
122
+ * @returns 复制结果
123
+ * @throws 当复制过程中出现错误时抛出异常
124
+ */
125
+ declare function copySourceToTarget(sourcePath: string, targetPath: string, options: CopyOptions): Promise<CopyResult>;
126
+ /**
127
+ * 写入文件内容
128
+ * @param filePath 文件路径
129
+ * @param content 文件内容
130
+ * @throws 当写入过程中出现错误时抛出异常
131
+ */
132
+ declare function writeFileContent(filePath: string, content: string): Promise<void>;
133
+ /**
134
+ * 读取文件内容
135
+ * @param filePath 文件路径
136
+ * @returns 文件内容字符串
137
+ * @throws 当读取过程中出现错误时抛出异常
138
+ */
139
+ declare function readFileContent(filePath: string): Promise<string>;
140
+ /**
141
+ * 同步读取文件内容
142
+ * @param filePath 文件路径
143
+ * @returns 文件内容字符串
144
+ * @throws 当读取过程中出现错误时抛出异常
145
+ * @deprecated 请使用异步版本 readFileContent
146
+ */
147
+ declare function readFileSync(filePath: string): string;
148
+
149
+ export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, shouldUpdateFile, writeFileContent };
150
+ export type { CopyOptions, CopyResult };