@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.
- package/dist/index.amd.js +27 -0
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +27 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +27 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +27 -0
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +27 -0
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +27 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Utils.d.ts +8 -0
- package/dist/src/VueObject.d.ts +3 -0
- package/package.json +1 -1
- package/src/Utils.ts +26 -0
- package/src/VueObject.ts +4 -0
package/dist/index.esm.js
CHANGED
|
@@ -6213,6 +6213,33 @@ class Utils {
|
|
|
6213
6213
|
});
|
|
6214
6214
|
return formData;
|
|
6215
6215
|
}
|
|
6216
|
+
/**
|
|
6217
|
+
* 将链接转为URL对象,自动补充URL的protocol或者origin
|
|
6218
|
+
* @param text 需要转换的链接字符串
|
|
6219
|
+
* @example
|
|
6220
|
+
* Utils.toUrl("//www.baidu.com/s?word=666");
|
|
6221
|
+
* Utils.toUrl("/s?word=666");
|
|
6222
|
+
*/
|
|
6223
|
+
toUrl(text) {
|
|
6224
|
+
if (typeof text !== "string") {
|
|
6225
|
+
throw new TypeError("toUrl: text must be string");
|
|
6226
|
+
}
|
|
6227
|
+
text = text.trim();
|
|
6228
|
+
if (text === "") {
|
|
6229
|
+
throw new TypeError("toUrl: text must not be empty");
|
|
6230
|
+
}
|
|
6231
|
+
if (text.startsWith("//")) {
|
|
6232
|
+
/* //www.baidu.com/xxxxxxx */
|
|
6233
|
+
/* 没有protocol,加上 */
|
|
6234
|
+
text = UtilsCore.globalThis.location.protocol + text;
|
|
6235
|
+
}
|
|
6236
|
+
else if (text.startsWith("/")) {
|
|
6237
|
+
/* /xxx/info?xxx=xxx */
|
|
6238
|
+
/* 没有Origin,加上 */
|
|
6239
|
+
text = UtilsCore.globalThis.location.origin + text;
|
|
6240
|
+
}
|
|
6241
|
+
return new URL(text);
|
|
6242
|
+
}
|
|
6216
6243
|
/**
|
|
6217
6244
|
* 生成uuid
|
|
6218
6245
|
* @example
|