@ezuikit/utils-tools 2.0.0-beta.3 → 2.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezuikit/utils-tools",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0",
4
4
  "description": "tools utils",
5
5
  "main": "dist/index.js",
6
6
  "umd": "dist/index.umd.js",
@@ -1 +0,0 @@
1
- No third parties dependencies
package/dist/index.mjs DELETED
@@ -1,92 +0,0 @@
1
- var getQuery = function(url) {
2
- var query = url.split("?")[1], obj = {};
3
- if (query) for (var vars = query.split("&"), i = 0; i < vars.length; i++) {
4
- var pair = vars[i].split("=");
5
- obj[pair[0]] = decodeURIComponent(pair[1]);
6
- }
7
- return obj;
8
- };
9
-
10
- function parseEzopenUrl(url) {
11
- var obj = {};
12
- if (/^ezopen:\/\//.test(url)) {
13
- if (url.includes("@")) {
14
- var endIndex = url.indexOf("@"), startIndex = url.indexOf("//");
15
- obj.validateCode = url.substring(startIndex + 2, endIndex), url = url.replace(obj.validateCode + "@", "");
16
- }
17
- obj.protocol = url.split("//")[0], obj.search = url.split("?")[1] ? "?" + url.split("?")[1] : "",
18
- obj.hostname = url.split("/")[2], obj.origin = obj.protocol + "//" + obj.hostname,
19
- obj.pathname = url.split("?")[0].replace(obj.origin, ""), obj.href = url;
20
- var pathnames = obj.pathname.split("/"), lastPath = pathnames[2].split(".");
21
- return obj.deviceSerial = pathnames[1], obj.channelNo = lastPath[0], obj.type = lastPath[lastPath.length - 1],
22
- "live" === obj.type && (obj.definition = lastPath.length > 2 ? lastPath[1] : "sd"),
23
- "rec" === obj.type && pathnames[2] && (obj.recType = pathnames[2].includes(".cloud.") ? "cloud" : ""),
24
- obj.searchParams = getQuery(url), obj;
25
- }
26
- return {};
27
- }
28
-
29
- function switchEzopenUrl(url, options) {
30
- var _ref = null != options ? options : {}, type = _ref.type, recType = _ref.recType, search = _ref.search, definition = _ref.definition, channelNo = _ref.channelNo, deviceSerial = _ref.deviceSerial, validateCode = _ref.validateCode, obj = parseEzopenUrl(url);
31
- if (search) {
32
- var ns = Object.assign({}, obj.searchParams, getQuery("?" + search.replace("?", "")));
33
- search = Object.entries(ns).reduce(function(acc, param) {
34
- var key = param[0], value = param[1];
35
- return "" === value ? acc : acc += key + "=" + encodeURIComponent(value) + "&";
36
- }, "?").replace(/&$/, "");
37
- } else search = obj.search;
38
- return type = type || obj.type, recType = null != recType ? recType : obj.recType,
39
- definition = null != definition ? definition : obj.definition, channelNo = channelNo || obj.channelNo,
40
- deviceSerial = deviceSerial || obj.deviceSerial, validateCode = null != validateCode ? validateCode : obj.validateCode,
41
- obj.protocol + "//" + (validateCode ? validateCode + "@" : "") + obj.hostname + "/" + deviceSerial + "/" + channelNo + ("rec" === type && recType ? "." + recType : "") + ("live" === type && "hd" === definition ? "." + definition : "") + "." + type + search;
42
- }
43
-
44
- function isHttp(url) {
45
- return /^http[s]?:\/\//.test(url);
46
- }
47
-
48
- function isMobile(agent) {
49
- var _navigator, _navigator1, _navigator2, _window;
50
- return /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone|Opera Mini)/i.test(null != agent ? agent : null == (_navigator = navigator) ? void 0 : _navigator.userAgent) || /Macintosh/i.test(null == (_navigator1 = navigator) ? void 0 : _navigator1.userAgent) && (null == (_navigator2 = navigator) ? void 0 : _navigator2.maxTouchPoints) > 1 || (null == (_window = window) ? void 0 : _window.__IS_MOBILE_SIMULATOR__);
51
- }
52
-
53
- function pick(obj, keys) {
54
- return Object.entries(obj).reduce(function(acc, param) {
55
- var key = param[0], value = param[1];
56
- return keys.includes(key) && (acc[key] = value), acc;
57
- }, {});
58
- }
59
-
60
- function getStaticPath(path, base) {
61
- void 0 === base && (base = "");
62
- var protocolReg = /^(https?:\/\/|^\/\/)/;
63
- if ("" === path || void 0 === path) return "";
64
- if (protocolReg.test(path)) return path;
65
- path = path.replace(/\/+/g, "/"), base = protocolReg.test(base || "") ? base : window.location.href;
66
- try {
67
- return new URL(path, base).href;
68
- } catch (error) {
69
- return path;
70
- }
71
- }
72
-
73
- var __$codec$__ = {
74
- h264: 1,
75
- h265: 2,
76
- h266: 4,
77
- vp8: 8,
78
- vp9: 16,
79
- av1: 32
80
- };
81
-
82
- function addVc(url, codecs) {
83
- void 0 === codecs && (codecs = [ "h264" ]);
84
- var vc = (codecs || [ "h264" ]).reduce(function(acc, key) {
85
- return key = key.toLowerCase(), acc + (__$codec$__[key] || 0);
86
- }, 0), host = url.split("?")[0], query = url.split("?")[1];
87
- return query = (query || "").split("&").filter(function(item) {
88
- return !/^vc=\d?/.test(item);
89
- }).join("&"), host + "?" + (query += (query ? "&" : "") + "vc=" + vc);
90
- }
91
-
92
- export { addVc, getQuery, getStaticPath, isHttp, isMobile, parseEzopenUrl, pick, switchEzopenUrl };