@base-web-kits/base-tools-web 1.3.5 → 1.3.8

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.
package/README.md CHANGED
@@ -98,3 +98,96 @@ setBaseToolsConfig({
98
98
  </body>
99
99
  </html>
100
100
  ```
101
+
102
+ ## 🤖 AI 智能助手 (Skill)
103
+
104
+ 本项目提供了强大的 AI Skill,可让 Cursor、Trae、Claude Code 等 AI 助手深度理解 `@base-web-kits` 的能力,为您精准推荐最佳实践函数,并自动处理依赖安装。
105
+
106
+ ### 安装方式
107
+
108
+ 在项目根目录下执行以下命令:
109
+
110
+ ```bash
111
+ npx skills add gancao-web/base-tools
112
+ ```
113
+
114
+ ### 验证生效
115
+
116
+ 安装完成后,可以在对话框中输入以下问题进行测试。如果 AI 推荐了 `@base-web-kits` 下的相关包或函数,说明配置已生效。
117
+
118
+ | 测试场景 | 推荐提问 | 预期 AI 回答 |
119
+ | :-- | :-- | :-- |
120
+ | **JS工具库** | "我需要深拷贝一个对象,请编写或推荐一个函数,优先考虑已配置的skill" | 推荐使用 `base-tools-ts` 的 `cloneDeep` |
121
+ | **JS正则验证** | "我需要校验邮箱格式,请编写或推荐一个函数,优先考虑已配置的skill" | 推荐使用 `base-tools-ts` 的 `isEmail` |
122
+ | **通用web** | "我需要复制文本到剪贴板,请编写或推荐一个函数,优先考虑已配置的skill" | 推荐使用 `base-tools-web` 的 `copyText` |
123
+ | **React项目** | "我需要监听dom元素的尺寸变化,请编写或推荐一个函数,优先考虑已配置的skill" | 推荐使用 `base-tools-react` 的 `useSize` |
124
+ | **Vue项目** | "我需要监听元素外部点击事件,请编写或推荐一个函数,优先考虑已配置的skill" | 推荐使用 `base-tools-vue` 的 `onClickOutside` |
125
+ | **UniApp项目** | "我需要保存网络图片到系统相册,请编写或推荐一个函数,优先考虑已配置的skill" | 推荐使用 `base-tools-uni` 的 `saveImageToPhotosAlbum` 函数 |
126
+
127
+ ## 兼容性
128
+
129
+ 本工具库和相关依赖可能涉及的新特性及其最低兼容版本:
130
+
131
+ | 特性 | ES 版本 | 最低兼容版本 (Browser/OS) |
132
+ | :---------------------------------------- | :------ | :---------------------------------- |
133
+ | **Array.prototype.includes** | ES2016 | Chrome 47+, iOS 9+, Android 6.0+ |
134
+ | **Object.values / entries** | ES2017 | Chrome 54+, iOS 10.3+, Android 7.0+ |
135
+ | **String.prototype.padStart / padEnd** | ES2017 | Chrome 57+, iOS 10.3+, Android 8.0+ |
136
+ | **Object.getOwnPropertyDescriptors** | ES2017 | Chrome 54+, iOS 10.3+, Android 7.0+ |
137
+ | **Promise.prototype.finally** | ES2018 | Chrome 63+, iOS 11.3+, Android 9.0+ |
138
+ | **Async Iterator (Symbol.asyncIterator)** | ES2018 | Chrome 63+, iOS 12.0+, Android 9.0+ |
139
+ | **Object.fromEntries** | ES2019 | Chrome 73+, iOS 12.2+, Android 10+ |
140
+ | **Array.prototype.flat / flatMap** | ES2019 | Chrome 69+, iOS 12.0+, Android 9.0+ |
141
+ | **String.prototype.trimStart / trimEnd** | ES2019 | Chrome 66+, iOS 12.0+, Android 9.0+ |
142
+ | **Promise.allSettled** | ES2020 | Chrome 76+, iOS 13.0+, Android 10+ |
143
+ | **String.prototype.matchAll** | ES2020 | Chrome 80+, iOS 13.0+, Android 10+ |
144
+ | **BigInt** | ES2020 | Chrome 67+, iOS 14.0+, Android 11+ |
145
+ | **globalThis** | ES2020 | Chrome 71+, iOS 12.2+, Android 9.0+ |
146
+ | **String.prototype.replaceAll** | ES2021 | Chrome 85+, iOS 13.4+, Android 11+ |
147
+ | **Promise.any** | ES2021 | Chrome 85+, iOS 14.0+, Android 11+ |
148
+ | **WeakRef / FinalizationRegistry** | ES2021 | Chrome 84+, iOS 14.5+, Android 11+ |
149
+ | **Array/String.prototype.at** | ES2022 | Chrome 92+, iOS 15.4+, Android 12+ |
150
+ | **Error.prototype.cause** | ES2022 | Chrome 93+, iOS 15.0+, Android 12+ |
151
+ | **Object.hasOwn** | ES2022 | Chrome 93+, iOS 15.4+, Android 12+ |
152
+
153
+ 本工具库构建目标为 **ES2015+**。但不内置 Polyfill, 如需支持低版本浏览器, 请务必在项目中配置 Polyfill。
154
+
155
+ ### 配置 Polyfill
156
+
157
+ 需经过两步:
158
+
159
+ 1. 配置打包工具, 将ES6+代码转换为ES5。
160
+ 2. 在入口文件顶部引入 `core-js` 进行 Polyfill。
161
+
162
+ 以 Vite 项目为例:
163
+
164
+ 1. 使用 `@vitejs/plugin-legacy` 插件,将ES6+代码转换为ES5。
165
+
166
+ ```ts
167
+ // vite.config.ts
168
+ import legacy from '@vitejs/plugin-legacy'; // 安装命令: npm install -D @vitejs/plugin-legacy
169
+
170
+ export default {
171
+ plugins: [
172
+ legacy({
173
+ // 与antd4兼容性对齐 https://4x-ant-design.antgroup.com/docs/react/introduce-cn
174
+ // targets: ['defaults', 'not IE 11'],
175
+
176
+ // 与vant4兼容性对齐 https://vant4.ylhtest.com/#/zh-CN/home
177
+ // targets: ['chrome >= 51', 'android >= 5', 'ios >= 10'],
178
+
179
+ // 与Element对齐: https://element-plus.org/zh-CN/guide/installation
180
+ targets: ['Chrome >= 64', 'Edge >= 79', 'Firefox >= 78', 'Safari >= 12', 'not IE 11'],
181
+
182
+ renderLegacyChunks: true, // 必须开启, 确保生成 ES5 兼容包
183
+ modernPolyfills: false, // 关闭按需注入polyfill, 因为legacy无法全量分析项目代码间接依赖了哪些新API, 需在入口文件 main.ts 全量引入 'core-js/stable'
184
+ }),
185
+ ],
186
+ };
187
+ ```
188
+
189
+ 2. 入口文件 main.ts 顶部引入 core-js/stable 进行 Polyfill
190
+
191
+ ```ts
192
+ import 'core-js/stable'; // 安装命令: npm install core-js
193
+ ```
@@ -2164,7 +2164,8 @@ var baseToolsWeb = (() => {
2164
2164
  reject(timeoutError);
2165
2165
  return;
2166
2166
  }
2167
- if (!isAbortError && toastError) (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25" });
2167
+ if (!isAbortError && toastError)
2168
+ (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: `\u8BF7\u6C42\u5931\u8D25,${String(e)}` });
2168
2169
  logRequestInfo({ status, config: logConfig, startTime, e });
2169
2170
  reject(e);
2170
2171
  } finally {
@@ -2214,7 +2215,7 @@ var baseToolsWeb = (() => {
2214
2215
  info.res = cloneDeep(res);
2215
2216
  log("info", info);
2216
2217
  } else {
2217
- info.e = e;
2218
+ info.e = e instanceof Error ? { name: e.name, message: e.message, stack: e.stack } : String(e);
2218
2219
  log("error", info);
2219
2220
  }
2220
2221
  }
@@ -2233,9 +2234,11 @@ var baseToolsWeb = (() => {
2233
2234
  }
2234
2235
  function handleStreamResponse(response, sseTask) {
2235
2236
  return __async(this, null, function* () {
2236
- if (!response.body) return "Stream is empty";
2237
+ if (!response.body) throw new Error("Response body is null");
2237
2238
  if (sseTask.parser === void 0) {
2238
- return "onMessage is undefined \u2192 Stream parser skipped";
2239
+ throw new Error(
2240
+ "Stream parser missing: Please set config.onMessage when enableChunked is true"
2241
+ );
2239
2242
  }
2240
2243
  const reader = response.body.getReader();
2241
2244
  while (true) {