nhanh-pure-function 1.3.19 → 1.3.20
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/Utility/Utility.d.ts +13 -0
- package/lib/Utility/Utility.js +26 -0
- package/lib/test.ts +7 -2
- package/package.json +1 -1
package/lib/Utility/Utility.d.ts
CHANGED
|
@@ -299,6 +299,19 @@ export class _FileTypeChecker {
|
|
|
299
299
|
*/
|
|
300
300
|
static check(url: string, type: keyof FileExtensions): boolean;
|
|
301
301
|
|
|
302
|
+
/**
|
|
303
|
+
* 静态方法,用于解析地址信息
|
|
304
|
+
* 该方法接受一个URL字符串,将其解析为一个包含地址详情的对象数组
|
|
305
|
+
* 主要用于批量处理以逗号分隔的URL列表,为每个URL生成相应的名称和类型
|
|
306
|
+
*
|
|
307
|
+
* @param {string} url - 以逗号分隔的URL字符串,每个URL代表一个资源的位置
|
|
308
|
+
* @returns {Array} - 包含每个URL及其相关信息(名称和类型)的对象数组
|
|
309
|
+
* @throws {Error} - 如果提供的URL为空或不是字符串,则抛出错误
|
|
310
|
+
*/
|
|
311
|
+
static parseAddresses(
|
|
312
|
+
url: string
|
|
313
|
+
): { url: string; name: string; type: string }[];
|
|
314
|
+
|
|
302
315
|
/**
|
|
303
316
|
* 检查URL是否具有任何指定的文件扩展名
|
|
304
317
|
* @param {string} url - 文件的URL
|
package/lib/Utility/Utility.js
CHANGED
|
@@ -708,6 +708,32 @@ export class _FileTypeChecker {
|
|
|
708
708
|
return _FileTypeChecker._detectFileType(lowerCaseUrl);
|
|
709
709
|
}
|
|
710
710
|
|
|
711
|
+
/**
|
|
712
|
+
* 静态方法,用于解析地址信息
|
|
713
|
+
* 该方法接受一个URL字符串,将其解析为一个包含地址详情的对象数组
|
|
714
|
+
* 主要用于批量处理以逗号分隔的URL列表,为每个URL生成相应的名称和类型
|
|
715
|
+
*
|
|
716
|
+
* @param {string} url - 以逗号分隔的URL字符串,每个URL代表一个资源的位置
|
|
717
|
+
* @returns {Array} - 包含每个URL及其相关信息(名称和类型)的对象数组
|
|
718
|
+
* @throws {Error} - 如果提供的URL为空或不是字符串,则抛出错误
|
|
719
|
+
*/
|
|
720
|
+
static parseAddresses(url) {
|
|
721
|
+
// 确保提供的URL是字符串且非空
|
|
722
|
+
if (!url || typeof url !== "string") {
|
|
723
|
+
throw new Error("Invalid URL provided");
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// 分割URL字符串并映射每个URL到包含其详细信息的对象
|
|
727
|
+
return url.split(",").map((url) => {
|
|
728
|
+
// 从URL中提取名称
|
|
729
|
+
const name = _GetHrefName(url);
|
|
730
|
+
// 检查URL的类型
|
|
731
|
+
const type = this.check(url);
|
|
732
|
+
// 返回包含URL、名称和类型的对象
|
|
733
|
+
return { url, name, type };
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
|
|
711
737
|
/**
|
|
712
738
|
* 检查URL是否具有任何指定的文件扩展名
|
|
713
739
|
* @param {string} url - 文件的URL
|
package/lib/test.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { _GetHrefName } from "./Utility/Utility";
|
|
1
|
+
import { _FileTypeChecker, _GetHrefName } from "./Utility/Utility";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let value: any = _GetHrefName(
|
|
4
4
|
"https://fastly.picsum.photos/id/841/805/453.jpg?hmac=RMVB2BBB6T34wI08nwWz1urBgdzSQxNR6L48hkOsTNo"
|
|
5
5
|
);
|
|
6
6
|
|
|
7
7
|
console.log(value);
|
|
8
|
+
|
|
9
|
+
value = _FileTypeChecker.parseAddresses(
|
|
10
|
+
"https://emergency.wjtsc.com:1128/resources/life-cycle/test/1-110000251006481.pcm,https://emergency.wjtsc.com:1128/resources/life-cycle/test/car-828972667665784.mp3,https://emergency.wjtsc.com:1128/resources/life-cycle/test/317361004975528.jpg"
|
|
11
|
+
);
|
|
12
|
+
console.log(value);
|