nhanh-pure-function 1.3.7 → 1.3.9

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/lib/Index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from "./Utility/Utility";
2
2
  export * from "./User/User";
3
3
  export * from "./Math/Math";
4
4
 
5
- // 提取单个函数的参数类型
5
+ /** 提取单个函数的参数类型 */
6
6
  export type ExtractParameters<T> = T extends (...args: infer P) => any
7
7
  ? P
8
8
  : never;
package/lib/Math/Math.js CHANGED
@@ -118,9 +118,11 @@ export function _FormatNumberWithUnit(number, config = {}) {
118
118
  "载",
119
119
  "极",
120
120
  ];
121
- const digits = Math.floor(Math.log10(number) / 4); // 计算位数
122
121
 
123
- // 不超过万位的数字直接返回
122
+ /** 计算位数 */
123
+ const digits = Math.floor(Math.log10(number) / 4);
124
+
125
+ /** 不超过万位的数字直接返回 */
124
126
  if (digits === 0) {
125
127
  if (integer) {
126
128
  return _join(number, suffix, plus);
@@ -183,12 +183,12 @@ export class _LocalDrag {
183
183
  finish(): void;
184
184
  }
185
185
 
186
- // 进入全屏模式
186
+ /** 进入全屏模式 */
187
187
  export function _EnterFullscreen(content: HTMLElement): void;
188
- // 退出全屏模式
188
+ /** 退出全屏模式 */
189
189
  export function _ExitFullscreen(): void;
190
- // 判断是否处于全屏模式
191
- export function _IsFullscreen(): boolean;
190
+ /** 判断是否处于全屏模式 */
191
+ export function _IsFullscreen(): HTMLElement | undefined;
192
192
 
193
193
  /**
194
194
  * 返回一个用于切换全屏模式的函数
package/lib/User/User.js CHANGED
@@ -483,7 +483,7 @@ export class _LocalDrag {
483
483
  }
484
484
  }
485
485
 
486
- // 进入全屏模式
486
+ /** 进入全屏模式 */
487
487
  export function _EnterFullscreen(content) {
488
488
  if (!content) return console.error("No DOM: ", content);
489
489
  if (content.requestFullscreen) {
@@ -499,7 +499,7 @@ export function _EnterFullscreen(content) {
499
499
  content.msRequestFullscreen();
500
500
  }
501
501
  }
502
- // 退出全屏模式
502
+ /** 退出全屏模式 */
503
503
  export function _ExitFullscreen() {
504
504
  if (document.exitFullscreen) {
505
505
  document.exitFullscreen();
@@ -514,7 +514,7 @@ export function _ExitFullscreen() {
514
514
  document.msExitFullscreen();
515
515
  }
516
516
  }
517
- // 判断是否处于全屏模式
517
+ /** 判断是否处于全屏模式 */
518
518
  export function _IsFullscreen() {
519
519
  return (
520
520
  document.fullscreenElement ||
@@ -78,6 +78,16 @@ export function _TimeTransition(
78
78
  */
79
79
  export function _ReadFile(src: string): Promise<string>;
80
80
 
81
+ /**
82
+ * 从给定的URL中提取文件名
83
+ * 如果无法提取文件名,则返回默认的文件名
84
+ *
85
+ * @param {string} href - 包含文件路径的URL
86
+ * @param {string} [defaultName="file"] - 默认的文件名,当无法提取时使用
87
+ * @returns {string} 提取到的文件名或默认的文件名
88
+ */
89
+ export function _GetHrefName(href: string, defaultName = "file"): string;
90
+
81
91
  /**
82
92
  * 下载文件
83
93
  * @param {string} href 文件路径
@@ -175,19 +175,33 @@ export function _ReadFile(src) {
175
175
  });
176
176
  }
177
177
 
178
+ /**
179
+ * 从给定的URL中提取文件名
180
+ * 如果无法提取文件名,则返回默认的文件名
181
+ *
182
+ * @param {string} href - 包含文件路径的URL
183
+ * @param {string} [defaultName="file"] - 默认的文件名,当无法提取时使用
184
+ * @returns {string} 提取到的文件名或默认的文件名
185
+ */
186
+ export function _GetHrefName(href, defaultName = "file") {
187
+ // 分割URL并获取最后一个路径段,然后去除查询字符串,最后返回文件名或默认名
188
+ return href.split("/").pop().split("?")[0] || defaultName;
189
+ }
190
+
178
191
  /**
179
192
  * 下载文件
180
- * @param {文件路径} href
181
- * @param {导出文件名} download
193
+ * @param {string} href - 文件路径
194
+ * @param {string} [fileName] - 导出文件名
182
195
  */
183
196
  export function _DownloadFile(href, fileName) {
184
197
  const a = document.createElement("a");
185
198
  a.href = href;
186
- if (fileName) a.download = fileName;
187
- a.style.display = "none";
199
+ a.download = fileName || _GetHrefName(href, "image");
200
+
201
+ // 临时将 a 标签添加到 DOM,然后触发点击事件,最后移除
188
202
  document.body.appendChild(a);
189
203
  a.click();
190
- a.remove();
204
+ document.body.removeChild(a);
191
205
  }
192
206
 
193
207
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhanh-pure-function",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "description": "纯函数工具",
5
5
  "main": "lib/Index.js",
6
6
  "scripts": {