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 +1 -1
- package/lib/Math/Math.js +4 -2
- package/lib/User/User.d.ts +4 -4
- package/lib/User/User.js +3 -3
- package/lib/Utility/Utility.d.ts +10 -0
- package/lib/Utility/Utility.js +19 -5
- package/package.json +1 -1
package/lib/Index.d.ts
CHANGED
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);
|
package/lib/User/User.d.ts
CHANGED
|
@@ -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():
|
|
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 ||
|
package/lib/Utility/Utility.d.ts
CHANGED
|
@@ -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 文件路径
|
package/lib/Utility/Utility.js
CHANGED
|
@@ -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 {
|
|
181
|
-
* @param {
|
|
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
|
-
|
|
187
|
-
|
|
199
|
+
a.download = fileName || _GetHrefName(href, "image");
|
|
200
|
+
|
|
201
|
+
// 临时将 a 标签添加到 DOM,然后触发点击事件,最后移除
|
|
188
202
|
document.body.appendChild(a);
|
|
189
203
|
a.click();
|
|
190
|
-
|
|
204
|
+
document.body.removeChild(a);
|
|
191
205
|
}
|
|
192
206
|
|
|
193
207
|
/**
|