nhanh-pure-function 1.3.21 → 1.3.22

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.
@@ -269,48 +269,6 @@ export function _DownloadFile(href, fileName) {
269
269
  }
270
270
  })
271
271
  .catch(reject);
272
-
273
- // try {
274
- // // 验证 href 和 fileName 是否为合法字符串
275
- // if (typeof href !== "string" || !href.trim()) {
276
- // throw new Error("无效的 href 参数");
277
- // }
278
- // if (typeof fileName !== "string") {
279
- // fileName = _GetHrefName(href, "downloaded_file");
280
- // }
281
-
282
- // fetch(href)
283
- // .then((response) => {
284
- // if (!response.ok) {
285
- // throw new Error(`文件下载失败,状态码: ${response.status}`);
286
- // }
287
- // return response.blob();
288
- // })
289
- // .then((blob) => {
290
- // const url = URL.createObjectURL(blob); // 创建文件 URL
291
-
292
- // const a = document.createElement("a");
293
- // a.href = url;
294
- // a.download = decodeURIComponent(fileName);
295
-
296
- // // 临时将 a 标签添加到 DOM,然后触发点击事件,最后移除
297
- // document.body.appendChild(a);
298
- // a.click();
299
- // document.body.removeChild(a);
300
-
301
- // // 释放 URL 对象
302
- // URL.revokeObjectURL(url);
303
-
304
- // resolve();
305
- // })
306
- // .catch((error) => {
307
- // console.error("下载文件时发生错误:", error.message);
308
- // reject(error);
309
- // });
310
- // } catch (error) {
311
- // console.error("下载文件时发生错误:", error.message);
312
- // reject(error);
313
- // }
314
272
  });
315
273
  }
316
274
 
@@ -448,13 +406,17 @@ export function _Debounce(fn, delay) {
448
406
  * @returns {Function}
449
407
  */
450
408
  export function _Throttle(fn, delay) {
451
- let timer;
409
+ let lastCallTime = -Infinity;
410
+
452
411
  return function (...args) {
453
- if (!timer) {
454
- timer = setTimeout(() => {
455
- fn.apply(this, args);
456
- timer = null;
457
- }, delay);
412
+ const now = performance.now();
413
+ if (now - lastCallTime > delay) {
414
+ lastCallTime = now;
415
+ try {
416
+ fn(...args);
417
+ } catch (error) {
418
+ console.error("Throttled function execution failed:", error);
419
+ }
458
420
  }
459
421
  };
460
422
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhanh-pure-function",
3
- "version": "1.3.21",
3
+ "version": "1.3.22",
4
4
  "description": "纯函数工具",
5
5
  "main": "lib/Index.js",
6
6
  "scripts": {