@whitesev/utils 1.5.3 → 1.5.4

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.
@@ -1745,6 +1745,14 @@ declare class Utils {
1745
1745
  toFormData(data: {
1746
1746
  [key: string]: string | Blob | File | number;
1747
1747
  }, isEncode?: boolean, valueAutoParseToStr?: boolean): FormData;
1748
+ /**
1749
+ * 将链接转为URL对象,自动补充URL的protocol或者origin
1750
+ * @param text 需要转换的链接字符串
1751
+ * @example
1752
+ * Utils.toUrl("//www.baidu.com/s?word=666");
1753
+ * Utils.toUrl("/s?word=666");
1754
+ */
1755
+ toUrl(text: string): URL;
1748
1756
  /**
1749
1757
  * 生成uuid
1750
1758
  * @example
@@ -105,3 +105,6 @@ export declare interface Vue2Object extends AnyObject {
105
105
  deep?: boolean;
106
106
  }) => void;
107
107
  }
108
+ export declare interface HTMLVue2DivElement extends HTMLDivElement {
109
+ __vue__: Vue2Object;
110
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/node/index.esm.js",
package/src/Utils.ts CHANGED
@@ -4869,6 +4869,32 @@ class Utils {
4869
4869
  });
4870
4870
  return formData;
4871
4871
  }
4872
+ /**
4873
+ * 将链接转为URL对象,自动补充URL的protocol或者origin
4874
+ * @param text 需要转换的链接字符串
4875
+ * @example
4876
+ * Utils.toUrl("//www.baidu.com/s?word=666");
4877
+ * Utils.toUrl("/s?word=666");
4878
+ */
4879
+ toUrl(text: string) {
4880
+ if (typeof text !== "string") {
4881
+ throw new TypeError("toUrl: text must be string");
4882
+ }
4883
+ text = text.trim();
4884
+ if (text === "") {
4885
+ throw new TypeError("toUrl: text must not be empty");
4886
+ }
4887
+ if (text.startsWith("//")) {
4888
+ /* //www.baidu.com/xxxxxxx */
4889
+ /* 没有protocol,加上 */
4890
+ text = UtilsCore.globalThis.location.protocol + text;
4891
+ } else if (text.startsWith("/")) {
4892
+ /* /xxx/info?xxx=xxx */
4893
+ /* 没有Origin,加上 */
4894
+ text = UtilsCore.globalThis.location.origin + text;
4895
+ }
4896
+ return new URL(text);
4897
+ }
4872
4898
  /**
4873
4899
  * 生成uuid
4874
4900
  * @example
package/src/VueObject.ts CHANGED
@@ -122,3 +122,7 @@ export declare interface Vue2Object extends AnyObject {
122
122
  }
123
123
  ) => void;
124
124
  }
125
+
126
+ export declare interface HTMLVue2DivElement extends HTMLDivElement {
127
+ __vue__: Vue2Object;
128
+ }