@minto-ai/tools 1.0.669 → 1.0.671
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
|
@@ -837,6 +837,32 @@ localStorage.setItem('anonymous_id', fingerprint)
|
|
|
837
837
|
- 指纹可能随浏览器升级、系统变更或渲染差异而变化,适合作为匿名用户的临时唯一标识,不建议用于强身份识别。
|
|
838
838
|
- 隐私增强模式或跨平台差异可能禁用部分特征(如 deviceMemory、Canvas),函数会自动兼容并尽可能生成可辨识的 ID。
|
|
839
839
|
|
|
840
|
+
### `getAbsoluteUrl`
|
|
841
|
+
|
|
842
|
+
> `function getAbsoluteUrl(rawUrl: string): string`
|
|
843
|
+
|
|
844
|
+
将任意格式的 URL 路径规范化为完整的绝对 URL 地址。
|
|
845
|
+
|
|
846
|
+
#### 参数
|
|
847
|
+
|
|
848
|
+
- `rawUrl (string)`: 待规范化的原始 URL 路径,支持空值、相对路径、绝对路径等格式。
|
|
849
|
+
|
|
850
|
+
#### 返回
|
|
851
|
+
|
|
852
|
+
`(string)`: 规范化后的绝对 URL 字符串,空输入返回空字符串。
|
|
853
|
+
|
|
854
|
+
#### 例子
|
|
855
|
+
|
|
856
|
+
```typescript
|
|
857
|
+
import { getAbsoluteUrl } from '@minto-ai/tools'
|
|
858
|
+
|
|
859
|
+
// 假设当前页面 URL 为 https://example.com/page
|
|
860
|
+
|
|
861
|
+
getAbsoluteUrl('/api/data') // 'https://example.com/api/data'
|
|
862
|
+
getAbsoluteUrl('https://other.com/api') // 'https://other.com/api'
|
|
863
|
+
getAbsoluteUrl('') // ''
|
|
864
|
+
```
|
|
865
|
+
|
|
840
866
|
## 工具
|
|
841
867
|
|
|
842
868
|
### `getUuid`
|
|
@@ -898,6 +924,7 @@ await timeDelay(300)
|
|
|
898
924
|
| `PPTX` | `pptx` | PowerPoint 演示文稿 (XML 格式) |
|
|
899
925
|
| `XLS` | `xls` | Excel 工作簿 |
|
|
900
926
|
| `XLSX` | `xlsx` | Excel 工作簿 (XML 格式) |
|
|
927
|
+
| `JSON` | `json` | JSON 数据文件 |
|
|
901
928
|
| `JPG` | `jpg` | JPEG 图像 |
|
|
902
929
|
| `PNG` | `png` | PNG 图像 |
|
|
903
930
|
| `JPEG` | `jpeg` | JPEG 图像 (另一种扩展名) |
|
|
@@ -955,6 +982,7 @@ await timeDelay(300)
|
|
|
955
982
|
| `TXT` | `txt` | 文本文件 |
|
|
956
983
|
| `XLS` | `xls` | Excel 工作簿 |
|
|
957
984
|
| `XLSX` | `xlsx` | Excel 工作簿 (XML 格式) |
|
|
985
|
+
| `JSON` | `json` | JSON 数据文件 |
|
|
958
986
|
|
|
959
987
|
#### `MusicFileSuffixEnum`
|
|
960
988
|
|
|
@@ -21,6 +21,7 @@ declare const FileSuffixEnum: {
|
|
|
21
21
|
readonly MP3: "mp3";
|
|
22
22
|
readonly WAV: "wav";
|
|
23
23
|
readonly TXT: "txt";
|
|
24
|
+
readonly JSON: "json";
|
|
24
25
|
readonly ZIP: "zip";
|
|
25
26
|
readonly RAR: "rar";
|
|
26
27
|
readonly HTML: "html";
|
|
@@ -61,6 +62,7 @@ declare const DocumentFileSuffixEnum: {
|
|
|
61
62
|
readonly TXT: "txt";
|
|
62
63
|
readonly XLS: "xls";
|
|
63
64
|
readonly XLSX: "xlsx";
|
|
65
|
+
readonly JSON: "json";
|
|
64
66
|
};
|
|
65
67
|
/**
|
|
66
68
|
* 音乐文件后缀类型枚举
|
package/dist/index.js
CHANGED
|
@@ -13754,25 +13754,95 @@ function createAudioPermission() {
|
|
|
13754
13754
|
}
|
|
13755
13755
|
return audioPermissionInstance;
|
|
13756
13756
|
}
|
|
13757
|
+
function isNumber(value) {
|
|
13758
|
+
return typeof value === "number";
|
|
13759
|
+
}
|
|
13760
|
+
function isString$1(value) {
|
|
13761
|
+
return typeof value === "string";
|
|
13762
|
+
}
|
|
13763
|
+
function beParsedAsNumber(value) {
|
|
13764
|
+
if (isNumber(value)) {
|
|
13765
|
+
return value;
|
|
13766
|
+
}
|
|
13767
|
+
if (isString$1(value)) {
|
|
13768
|
+
return Number.parseFloat(value);
|
|
13769
|
+
}
|
|
13770
|
+
return Number.NaN;
|
|
13771
|
+
}
|
|
13772
|
+
function canBeParsedAsNumber(value) {
|
|
13773
|
+
return !Number.isNaN(Number.parseFloat(String(value))) && Number.isFinite(Number(value));
|
|
13774
|
+
}
|
|
13775
|
+
function isArray$1(value) {
|
|
13776
|
+
return Array.isArray(value);
|
|
13777
|
+
}
|
|
13778
|
+
function checkArrayEmpty(value) {
|
|
13779
|
+
return isArray$1(value) && value.length === 0;
|
|
13780
|
+
}
|
|
13781
|
+
function isObject$1(value) {
|
|
13782
|
+
return _typeof(value) === "object" && value !== null;
|
|
13783
|
+
}
|
|
13784
|
+
function checkObjectEmpty(value) {
|
|
13785
|
+
return isObject$1(value) && Object.keys(value).length === 0;
|
|
13786
|
+
}
|
|
13787
|
+
function checkEmpty(value) {
|
|
13788
|
+
return [value === "", value === 0, checkArrayEmpty(value), checkObjectEmpty(value), value === null, value === void 0].some(Boolean);
|
|
13789
|
+
}
|
|
13790
|
+
function checkEmptyNotZero(value) {
|
|
13791
|
+
return checkEmpty(value) && value !== 0;
|
|
13792
|
+
}
|
|
13793
|
+
function isBoolean(value) {
|
|
13794
|
+
return typeof value === "boolean";
|
|
13795
|
+
}
|
|
13796
|
+
function isFunction$1(value) {
|
|
13797
|
+
return typeof value === "function";
|
|
13798
|
+
}
|
|
13799
|
+
function isNullOrUndefined2(value) {
|
|
13800
|
+
return value === null || value === void 0;
|
|
13801
|
+
}
|
|
13802
|
+
function isUndefined(value) {
|
|
13803
|
+
return value === void 0;
|
|
13804
|
+
}
|
|
13805
|
+
var DATA_URI_PREFIX = "data:";
|
|
13806
|
+
var BASE64_MARKER = ";base64,";
|
|
13807
|
+
var BASE64_REGEX = /^[A-Z0-9+/]+={0,2}$/i;
|
|
13808
|
+
function isValidBase64(value) {
|
|
13809
|
+
if (!isString$1(value)) {
|
|
13810
|
+
return false;
|
|
13811
|
+
}
|
|
13812
|
+
var str = value.trim();
|
|
13813
|
+
if (!str) {
|
|
13814
|
+
return false;
|
|
13815
|
+
}
|
|
13816
|
+
if (str.startsWith(DATA_URI_PREFIX)) {
|
|
13817
|
+
var markerIndex = str.indexOf(BASE64_MARKER);
|
|
13818
|
+
if (markerIndex === -1) {
|
|
13819
|
+
return false;
|
|
13820
|
+
}
|
|
13821
|
+
str = str.slice(markerIndex + BASE64_MARKER.length);
|
|
13822
|
+
}
|
|
13823
|
+
var content = str.replace(/\s+/g, "");
|
|
13824
|
+
if (content.length % 4 !== 0) {
|
|
13825
|
+
return false;
|
|
13826
|
+
}
|
|
13827
|
+
return BASE64_REGEX.test(content);
|
|
13828
|
+
}
|
|
13829
|
+
var URL_REGEX = /^https?:\/\/(?:[\w-]+:[\w-]+@)?(?:localhost|(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}|(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))(?::\d{1,5})?(?:\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#\S*)?$/i;
|
|
13830
|
+
function isValidUrl(value) {
|
|
13831
|
+
if (!isString$1(value)) {
|
|
13832
|
+
return false;
|
|
13833
|
+
}
|
|
13834
|
+
return URL_REGEX.test(value.trim());
|
|
13835
|
+
}
|
|
13757
13836
|
function getAbsoluteUrl(rawUrl) {
|
|
13758
13837
|
if (!rawUrl) {
|
|
13759
13838
|
return "";
|
|
13760
13839
|
}
|
|
13761
|
-
|
|
13762
|
-
|
|
13763
|
-
return absoluteUrl;
|
|
13764
|
-
} catch (_unused) {
|
|
13765
|
-
try {
|
|
13766
|
-
var currentPageUrl = window.location.href;
|
|
13767
|
-
var _absoluteUrl = new URL(rawUrl, currentPageUrl).toString();
|
|
13768
|
-
return _absoluteUrl;
|
|
13769
|
-
} catch (_unused2) {
|
|
13770
|
-
var siteOrigin = window.location.origin;
|
|
13771
|
-
var normalizedPath = rawUrl.startsWith("/") ? rawUrl : "/".concat(rawUrl);
|
|
13772
|
-
var _absoluteUrl2 = "".concat(siteOrigin).concat(normalizedPath).replace(/\/+/g, "/");
|
|
13773
|
-
return _absoluteUrl2;
|
|
13774
|
-
}
|
|
13840
|
+
if (isValidUrl(rawUrl)) {
|
|
13841
|
+
return rawUrl;
|
|
13775
13842
|
}
|
|
13843
|
+
var currentPageUrl = window.location.href;
|
|
13844
|
+
var absoluteUrl = new URL(rawUrl, currentPageUrl).toString();
|
|
13845
|
+
return absoluteUrl;
|
|
13776
13846
|
}
|
|
13777
13847
|
function murmurHash332Gc(key) {
|
|
13778
13848
|
var seed = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
|
|
@@ -13900,54 +13970,6 @@ function isPc() {
|
|
|
13900
13970
|
return !isMobile();
|
|
13901
13971
|
}
|
|
13902
13972
|
var DEFAULT_USER_AVATAR = "https://1-future-tuzai.obs.cn-southwest-2.myhuaweicloud.com/web_image/default.png";
|
|
13903
|
-
function isNumber(value) {
|
|
13904
|
-
return typeof value === "number";
|
|
13905
|
-
}
|
|
13906
|
-
function isString$1(value) {
|
|
13907
|
-
return typeof value === "string";
|
|
13908
|
-
}
|
|
13909
|
-
function beParsedAsNumber(value) {
|
|
13910
|
-
if (isNumber(value)) {
|
|
13911
|
-
return value;
|
|
13912
|
-
}
|
|
13913
|
-
if (isString$1(value)) {
|
|
13914
|
-
return Number.parseFloat(value);
|
|
13915
|
-
}
|
|
13916
|
-
return Number.NaN;
|
|
13917
|
-
}
|
|
13918
|
-
function canBeParsedAsNumber(value) {
|
|
13919
|
-
return !Number.isNaN(Number.parseFloat(String(value))) && Number.isFinite(Number(value));
|
|
13920
|
-
}
|
|
13921
|
-
function isArray$1(value) {
|
|
13922
|
-
return Array.isArray(value);
|
|
13923
|
-
}
|
|
13924
|
-
function checkArrayEmpty(value) {
|
|
13925
|
-
return isArray$1(value) && value.length === 0;
|
|
13926
|
-
}
|
|
13927
|
-
function isObject$1(value) {
|
|
13928
|
-
return _typeof(value) === "object" && value !== null;
|
|
13929
|
-
}
|
|
13930
|
-
function checkObjectEmpty(value) {
|
|
13931
|
-
return isObject$1(value) && Object.keys(value).length === 0;
|
|
13932
|
-
}
|
|
13933
|
-
function checkEmpty(value) {
|
|
13934
|
-
return [value === "", value === 0, checkArrayEmpty(value), checkObjectEmpty(value), value === null, value === void 0].some(Boolean);
|
|
13935
|
-
}
|
|
13936
|
-
function checkEmptyNotZero(value) {
|
|
13937
|
-
return checkEmpty(value) && value !== 0;
|
|
13938
|
-
}
|
|
13939
|
-
function isBoolean(value) {
|
|
13940
|
-
return typeof value === "boolean";
|
|
13941
|
-
}
|
|
13942
|
-
function isFunction$1(value) {
|
|
13943
|
-
return typeof value === "function";
|
|
13944
|
-
}
|
|
13945
|
-
function isNullOrUndefined2(value) {
|
|
13946
|
-
return value === null || value === void 0;
|
|
13947
|
-
}
|
|
13948
|
-
function isUndefined(value) {
|
|
13949
|
-
return value === void 0;
|
|
13950
|
-
}
|
|
13951
13973
|
var FileSuffixEnum = {
|
|
13952
13974
|
DOCX: "docx",
|
|
13953
13975
|
DOC: "doc",
|
|
@@ -13968,6 +13990,7 @@ var FileSuffixEnum = {
|
|
|
13968
13990
|
MP3: "mp3",
|
|
13969
13991
|
WAV: "wav",
|
|
13970
13992
|
TXT: "txt",
|
|
13993
|
+
JSON: "json",
|
|
13971
13994
|
ZIP: "zip",
|
|
13972
13995
|
RAR: "rar",
|
|
13973
13996
|
HTML: "html"
|
|
@@ -13995,7 +14018,8 @@ var DocumentFileSuffixEnum = {
|
|
|
13995
14018
|
PDF: FileSuffixEnum.PDF,
|
|
13996
14019
|
TXT: FileSuffixEnum.TXT,
|
|
13997
14020
|
XLS: FileSuffixEnum.XLS,
|
|
13998
|
-
XLSX: FileSuffixEnum.XLSX
|
|
14021
|
+
XLSX: FileSuffixEnum.XLSX,
|
|
14022
|
+
JSON: FileSuffixEnum.JSON
|
|
13999
14023
|
};
|
|
14000
14024
|
var MusicFileSuffixEnum = {
|
|
14001
14025
|
MP3: FileSuffixEnum.MP3,
|
|
@@ -14256,37 +14280,6 @@ function isVideoFilePath(filePath) {
|
|
|
14256
14280
|
var fileSuffix = getFileSuffix(filePath);
|
|
14257
14281
|
return Object.values(VideoFileSuffixEnum).includes(fileSuffix);
|
|
14258
14282
|
}
|
|
14259
|
-
var DATA_URI_PREFIX = "data:";
|
|
14260
|
-
var BASE64_MARKER = ";base64,";
|
|
14261
|
-
var BASE64_REGEX = /^[A-Z0-9+/]+={0,2}$/i;
|
|
14262
|
-
function isValidBase64(value) {
|
|
14263
|
-
if (!isString$1(value)) {
|
|
14264
|
-
return false;
|
|
14265
|
-
}
|
|
14266
|
-
var str = value.trim();
|
|
14267
|
-
if (!str) {
|
|
14268
|
-
return false;
|
|
14269
|
-
}
|
|
14270
|
-
if (str.startsWith(DATA_URI_PREFIX)) {
|
|
14271
|
-
var markerIndex = str.indexOf(BASE64_MARKER);
|
|
14272
|
-
if (markerIndex === -1) {
|
|
14273
|
-
return false;
|
|
14274
|
-
}
|
|
14275
|
-
str = str.slice(markerIndex + BASE64_MARKER.length);
|
|
14276
|
-
}
|
|
14277
|
-
var content = str.replace(/\s+/g, "");
|
|
14278
|
-
if (content.length % 4 !== 0) {
|
|
14279
|
-
return false;
|
|
14280
|
-
}
|
|
14281
|
-
return BASE64_REGEX.test(content);
|
|
14282
|
-
}
|
|
14283
|
-
var URL_REGEX = /^https?:\/\/(?:[\w-]+:[\w-]+@)?(?:localhost|(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}|(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))(?::\d{1,5})?(?:\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#\S*)?$/i;
|
|
14284
|
-
function isValidUrl(value) {
|
|
14285
|
-
if (!isString$1(value)) {
|
|
14286
|
-
return false;
|
|
14287
|
-
}
|
|
14288
|
-
return URL_REGEX.test(value.trim());
|
|
14289
|
-
}
|
|
14290
14283
|
function singleDownloadFile(_x, _x2) {
|
|
14291
14284
|
return _singleDownloadFile.apply(this, arguments);
|
|
14292
14285
|
}
|