@minto-ai/tools 1.0.668 → 1.0.670

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
@@ -805,6 +805,64 @@ await audioPermission.requestPlaybackPermission()
805
805
  await audioPermission.requestMicrophonePermission()
806
806
  ```
807
807
 
808
+ ### `getBrowserFingerprint`
809
+
810
+ > `function getBrowserFingerprint(): string`
811
+
812
+ 生成匿名浏览器指纹,用于区分浏览器匿名用户的唯一 ID。通过收集浏览器环境特征(如 UserAgent、语言、屏幕分辨率、色深、时区、硬件并发、平台,以及 Canvas 渲染指纹等),并使用 MurmurHash3(32 位)生成稳定的十六进制字符串。
813
+
814
+ #### 参数
815
+
816
+ - 无
817
+
818
+ #### 返回
819
+
820
+ `(string)`: 浏览器指纹 ID(十六进制字符串)。在非浏览器环境(如 Node/SSR)返回空字符串 `''`。
821
+
822
+ #### 例子
823
+
824
+ ```typescript
825
+ import { getBrowserFingerprint } from '@minto-ai/tools'
826
+
827
+ // 生成匿名用户唯一ID
828
+ const fingerprint = getBrowserFingerprint()
829
+ console.log(fingerprint) // 例如:'a1b2c3d4'
830
+
831
+ // 建议:结合本地存储缓存以保持一致性
832
+ localStorage.setItem('anonymous_id', fingerprint)
833
+ ```
834
+
835
+ #### 注意事项
836
+
837
+ - 指纹可能随浏览器升级、系统变更或渲染差异而变化,适合作为匿名用户的临时唯一标识,不建议用于强身份识别。
838
+ - 隐私增强模式或跨平台差异可能禁用部分特征(如 deviceMemory、Canvas),函数会自动兼容并尽可能生成可辨识的 ID。
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
+
808
866
  ## 工具
809
867
 
810
868
  ### `getUuid`
@@ -866,6 +924,7 @@ await timeDelay(300)
866
924
  | `PPTX` | `pptx` | PowerPoint 演示文稿 (XML 格式) |
867
925
  | `XLS` | `xls` | Excel 工作簿 |
868
926
  | `XLSX` | `xlsx` | Excel 工作簿 (XML 格式) |
927
+ | `JSON` | `json` | JSON 数据文件 |
869
928
  | `JPG` | `jpg` | JPEG 图像 |
870
929
  | `PNG` | `png` | PNG 图像 |
871
930
  | `JPEG` | `jpeg` | JPEG 图像 (另一种扩展名) |
@@ -923,6 +982,7 @@ await timeDelay(300)
923
982
  | `TXT` | `txt` | 文本文件 |
924
983
  | `XLS` | `xls` | Excel 工作簿 |
925
984
  | `XLSX` | `xlsx` | Excel 工作簿 (XML 格式) |
985
+ | `JSON` | `json` | JSON 数据文件 |
926
986
 
927
987
  #### `MusicFileSuffixEnum`
928
988
 
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 将任意格式的 URL 路径规范化为完整的绝对 URL 地址
3
+ * @param rawUrl - 待规范化的原始 URL 路径,支持空值、相对路径、绝对路径等格式
4
+ * @returns 规范化后的绝对 URL 字符串,空输入返回空字符串
5
+ */
6
+ declare function getAbsoluteUrl(rawUrl: string): string;
7
+ export default getAbsoluteUrl;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 获取浏览器唯一指纹 ID
3
+ * 通过收集浏览器特征(UserAgent, Screen, Language, Timezone, Canvas 等)生成哈希值
4
+ * 注意:此方法生成的 ID 在浏览器环境变化(如升级、窗口大小改变如果包含了窗口大小)时可能会变化,
5
+ * 但作为匿名用户的临时唯一标识通常足够。
6
+ *
7
+ * @returns 浏览器指纹 ID 字符串
8
+ */
9
+ export declare function getBrowserFingerprint(): string;
10
+ export default getBrowserFingerprint;
@@ -1,7 +1,9 @@
1
1
  import { default as copyText } from './copy-text';
2
2
  import { default as createAudioPermission } from './create-audio-permission';
3
+ import { default as getAbsoluteUrl } from './get-absolute-url';
4
+ import { default as getBrowserFingerprint } from './get-browser-fingerprint';
3
5
  import { default as isAndroid } from './is-android';
4
6
  import { default as isIos } from './is-ios';
5
7
  import { default as isMobile } from './is-mobile';
6
8
  import { default as isPc } from './is-pc';
7
- export { copyText, createAudioPermission, isAndroid, isIos, isMobile, isPc };
9
+ export { copyText, createAudioPermission, getAbsoluteUrl, getBrowserFingerprint, isAndroid, isIos, isMobile, isPc, };
@@ -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
  * 音乐文件后缀类型枚举
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 判断是否是有效的文档文件路径(包含doc、docx、pdf、txt、xls、xlsx)。
2
+ * 判断是否是有效的文档文件路径(包含doc、docx、pdf、txt、xls、xlsx、json)。
3
3
  *
4
4
  * @param filePath 文件路径。
5
5
  * @returns 是否是有效的文档文件路径。
package/dist/index.js CHANGED
@@ -13754,6 +13754,137 @@ function createAudioPermission() {
13754
13754
  }
13755
13755
  return audioPermissionInstance;
13756
13756
  }
13757
+ function getAbsoluteUrl(rawUrl) {
13758
+ if (!rawUrl) {
13759
+ return "";
13760
+ }
13761
+ try {
13762
+ var absoluteUrl = new URL(rawUrl).toString();
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
+ }
13775
+ }
13776
+ }
13777
+ function murmurHash332Gc(key) {
13778
+ var seed = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
13779
+ var k1;
13780
+ var h1;
13781
+ var remainder = key.length & 3;
13782
+ var bytes = key.length - remainder;
13783
+ h1 = seed;
13784
+ var c1 = 3432918353;
13785
+ var c2 = 461845907;
13786
+ var i = 0;
13787
+ while (i < bytes) {
13788
+ k1 = key.charCodeAt(i) & 255 | (key.charCodeAt(++i) & 255) << 8 | (key.charCodeAt(++i) & 255) << 16 | (key.charCodeAt(++i) & 255) << 24;
13789
+ ++i;
13790
+ k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
13791
+ k1 = k1 << 15 | k1 >>> 17;
13792
+ k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
13793
+ h1 ^= k1;
13794
+ h1 = h1 << 13 | h1 >>> 19;
13795
+ var h1b = (h1 & 65535) * 5 + (((h1 >>> 16) * 5 & 65535) << 16) & 4294967295;
13796
+ h1 = (h1b & 65535) + 27492 + (((h1b >>> 16) + 58964 & 65535) << 16);
13797
+ }
13798
+ k1 = 0;
13799
+ if (remainder >= 3) {
13800
+ k1 ^= (key.charCodeAt(i + 2) & 255) << 16;
13801
+ }
13802
+ if (remainder >= 2) {
13803
+ k1 ^= (key.charCodeAt(i + 1) & 255) << 8;
13804
+ }
13805
+ if (remainder >= 1) {
13806
+ k1 ^= key.charCodeAt(i) & 255;
13807
+ k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
13808
+ k1 = k1 << 15 | k1 >>> 17;
13809
+ k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
13810
+ h1 ^= k1;
13811
+ }
13812
+ h1 ^= key.length;
13813
+ h1 ^= h1 >>> 16;
13814
+ h1 = (h1 & 65535) * 2246822507 + (((h1 >>> 16) * 2246822507 & 65535) << 16) & 4294967295;
13815
+ h1 ^= h1 >>> 13;
13816
+ h1 = (h1 & 65535) * 3266489909 + (((h1 >>> 16) * 3266489909 & 65535) << 16) & 4294967295;
13817
+ h1 ^= h1 >>> 16;
13818
+ return h1 >>> 0;
13819
+ }
13820
+ function getCanvasFingerprint() {
13821
+ try {
13822
+ var canvas = document.createElement("canvas");
13823
+ var ctx = canvas.getContext("2d");
13824
+ if (!ctx) {
13825
+ return "";
13826
+ }
13827
+ canvas.width = 200;
13828
+ canvas.height = 50;
13829
+ ctx.textBaseline = "top";
13830
+ ctx.font = "14px Arial";
13831
+ ctx.fillStyle = "#f60";
13832
+ ctx.fillRect(125, 1, 62, 20);
13833
+ ctx.fillStyle = "#069";
13834
+ ctx.fillText("Hello, world!", 2, 15);
13835
+ ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
13836
+ ctx.fillText("Hello, world!", 4, 17);
13837
+ ctx.globalCompositeOperation = "multiply";
13838
+ ctx.fillStyle = "rgb(255,0,255)";
13839
+ ctx.beginPath();
13840
+ ctx.arc(50, 50, 50, 0, Math.PI * 2, true);
13841
+ ctx.closePath();
13842
+ ctx.fill();
13843
+ ctx.fillStyle = "rgb(0,255,255)";
13844
+ ctx.beginPath();
13845
+ ctx.arc(100, 50, 50, 0, Math.PI * 2, true);
13846
+ ctx.closePath();
13847
+ ctx.fill();
13848
+ ctx.fillStyle = "rgb(255,255,0)";
13849
+ ctx.beginPath();
13850
+ ctx.arc(75, 100, 50, 0, Math.PI * 2, true);
13851
+ ctx.closePath();
13852
+ ctx.fill();
13853
+ ctx.fillStyle = "rgb(255,0,255)";
13854
+ ctx.arc(75, 75, 75, 0, Math.PI * 2, true);
13855
+ ctx.arc(75, 75, 25, 0, Math.PI * 2, true);
13856
+ ctx.fill("evenodd");
13857
+ return canvas.toDataURL();
13858
+ } catch (_unused) {
13859
+ return "";
13860
+ }
13861
+ }
13862
+ function getBrowserFingerprint() {
13863
+ if (typeof window === "undefined") {
13864
+ return "";
13865
+ }
13866
+ var _window = window, navigator2 = _window.navigator, screen = _window.screen;
13867
+ var components = [];
13868
+ components.push(navigator2.userAgent);
13869
+ components.push(navigator2.language);
13870
+ components.push("".concat(screen.width, "x").concat(screen.height));
13871
+ components.push("".concat(screen.colorDepth));
13872
+ components.push("".concat((/* @__PURE__ */ new Date()).getTimezoneOffset()));
13873
+ if (navigator2.hardwareConcurrency) {
13874
+ components.push("".concat(navigator2.hardwareConcurrency));
13875
+ }
13876
+ if (navigator2.deviceMemory) {
13877
+ components.push("".concat(navigator2.deviceMemory));
13878
+ }
13879
+ if (navigator2.platform) {
13880
+ components.push(navigator2.platform);
13881
+ }
13882
+ var canvasFingerprint = getCanvasFingerprint();
13883
+ components.push(canvasFingerprint);
13884
+ var fingerprintString = components.join("###");
13885
+ var hash = murmurHash332Gc(fingerprintString);
13886
+ return hash.toString(16);
13887
+ }
13757
13888
  function isAndroid() {
13758
13889
  var userAgent2 = navigator.userAgent.toLowerCase();
13759
13890
  return /android/.test(userAgent2);
@@ -13837,6 +13968,7 @@ var FileSuffixEnum = {
13837
13968
  MP3: "mp3",
13838
13969
  WAV: "wav",
13839
13970
  TXT: "txt",
13971
+ JSON: "json",
13840
13972
  ZIP: "zip",
13841
13973
  RAR: "rar",
13842
13974
  HTML: "html"
@@ -13864,7 +13996,8 @@ var DocumentFileSuffixEnum = {
13864
13996
  PDF: FileSuffixEnum.PDF,
13865
13997
  TXT: FileSuffixEnum.TXT,
13866
13998
  XLS: FileSuffixEnum.XLS,
13867
- XLSX: FileSuffixEnum.XLSX
13999
+ XLSX: FileSuffixEnum.XLSX,
14000
+ JSON: FileSuffixEnum.JSON
13868
14001
  };
13869
14002
  var MusicFileSuffixEnum = {
13870
14003
  MP3: FileSuffixEnum.MP3,
@@ -16797,6 +16930,8 @@ export {
16797
16930
  deepFreeze,
16798
16931
  index as default,
16799
16932
  divide2 as divide,
16933
+ getAbsoluteUrl,
16934
+ getBrowserFingerprint,
16800
16935
  getDecimalPlaces,
16801
16936
  getFileIcon,
16802
16937
  getFileName,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@minto-ai/tools",
3
3
  "type": "module",
4
- "version": "1.0.668",
4
+ "version": "1.0.670",
5
5
  "description": "明途公共工具库",
6
6
  "author": "hcc",
7
7
  "license": "ISC",