@ezuikit/utils-tools 1.1.1-beta.1 → 2.0.0-beta.2

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.js CHANGED
@@ -1,7 +1,93 @@
1
- /*
2
- * @ezuikit/utils-tools v1.1.1-beta.1
3
- * tools utils
4
- * Copyright (c) 2025-09-01 Ezviz-OpenBiz
5
- * Released under the MIT License.
6
- */
7
- "use strict";const getQuery=url=>{const query=url.split("?")[1],obj={};if(query){const vars=query.split("&");for(let i=0;i<vars.length;i++){const pair=vars[i].split("=");obj[pair[0]]=decodeURIComponent(pair[1])}}return obj};function parseEzopenUrl(url){const obj={};if(/^ezopen:\/\//.test(url)){if(url.includes("@")){const endIndex=url.indexOf("@"),startIndex=url.indexOf("//");obj.validateCode=url.substring(startIndex+2,endIndex),url=url.replace(obj.validateCode+"@","")}obj.protocol=url.split("//")[0],obj.search=url.split("?")[1]?"?"+url.split("?")[1]:"",obj.hostname=url.split("/")[2],obj.origin=obj.protocol+"//"+obj.hostname,obj.pathname=url.split("?")[0].replace(obj.origin,""),obj.href=url;const pathnames=obj.pathname.split("/"),lastPath=pathnames[2].split(".");return obj.deviceSerial=pathnames[1],obj.channelNo=lastPath[0],obj.type=lastPath[lastPath.length-1],"live"===obj.type&&(obj.definition=lastPath.length>2?lastPath[1]:"sd"),"rec"===obj.type&&pathnames[2]&&(obj.recType=pathnames[2].includes(".cloud.")?"cloud":""),obj.searchParams=getQuery(url),obj}return{}}const codec={h264:1,h265:2,h266:4,vp8:8,vp9:16,av1:32};exports.addVc=function(url){const vc=((arguments.length>1&&void 0!==arguments[1]?arguments[1]:["h264"])||["h264"]).reduce(((acc,key)=>(key=key.toLowerCase(),acc+(codec[key]||0))),0),host=url.split("?")[0];let query=url.split("?")[1];return query=(query||"").split("&").filter((item=>!/^vc=\d?/.test(item))).join("&"),query+=`${query?"&":""}vc=${vc}`,host+"?"+query},exports.getQuery=getQuery,exports.getStaticPath=function(path){let base=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const protocolReg=/^(https?:\/\/|^\/\/)/;if(""===path||void 0===path)return"";if(protocolReg.test(path))return path;path=path.replace(/\/+/g,"/"),base=protocolReg.test(base||"")?base:window.location.href;try{return new URL(path,base).href}catch(error){return path}},exports.isHttp=function(url){return/^http[s]?:\/\//.test(url)},exports.isMobile=function(agent){var _navigator,_navigator1,_navigator2,_window;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__)},exports.parseEzopenUrl=parseEzopenUrl,exports.pick=function(obj,keys){return Object.entries(obj).reduce(((acc,_ref)=>{let[key,value]=_ref;return keys.includes(key)&&(acc[key]=value),acc}),{})},exports.switchEzopenUrl=function(url,options){let{type:type,recType:recType,search:search,definition:definition,channelNo:channelNo,deviceSerial:deviceSerial,validateCode:validateCode}=null!=options?options:{};const obj=parseEzopenUrl(url);if(search){const ns=Object.assign({},obj.searchParams,getQuery("?"+search.replace("?","")));search=Object.entries(ns).reduce(((acc,_ref)=>{let[key,value]=_ref;return""===value?acc:acc+=`${key}=${encodeURIComponent(value)}&`}),"?").replace(/&$/,"")}else search=obj.search;return type=type||obj.type,recType=null!=recType?recType:obj.recType,definition=null!=definition?definition:obj.definition,channelNo=channelNo||obj.channelNo,deviceSerial=deviceSerial||obj.deviceSerial,validateCode=null!=validateCode?validateCode:obj.validateCode,`${obj.protocol}//${validateCode?`${validateCode}@`:""}${obj.hostname}/${deviceSerial}/${channelNo}${"rec"===type&&recType?"."+recType:""}${"live"===type&&"hd"===definition?"."+definition:""}.${type}${search}`};
1
+ "use strict";
2
+
3
+ var getQuery = function(url) {
4
+ var query = url.split("?")[1], obj = {};
5
+ if (query) for (var vars = query.split("&"), i = 0; i < vars.length; i++) {
6
+ var pair = vars[i].split("=");
7
+ obj[pair[0]] = decodeURIComponent(pair[1]);
8
+ }
9
+ return obj;
10
+ };
11
+
12
+ function parseEzopenUrl(url) {
13
+ var obj = {};
14
+ if (/^ezopen:\/\//.test(url)) {
15
+ if (url.includes("@")) {
16
+ var endIndex = url.indexOf("@"), startIndex = url.indexOf("//");
17
+ obj.validateCode = url.substring(startIndex + 2, endIndex), url = url.replace(obj.validateCode + "@", "");
18
+ }
19
+ obj.protocol = url.split("//")[0], obj.search = url.split("?")[1] ? "?" + url.split("?")[1] : "",
20
+ obj.hostname = url.split("/")[2], obj.origin = obj.protocol + "//" + obj.hostname,
21
+ obj.pathname = url.split("?")[0].replace(obj.origin, ""), obj.href = url;
22
+ var pathnames = obj.pathname.split("/"), lastPath = pathnames[2].split(".");
23
+ return obj.deviceSerial = pathnames[1], obj.channelNo = lastPath[0], obj.type = lastPath[lastPath.length - 1],
24
+ "live" === obj.type && (obj.definition = lastPath.length > 2 ? lastPath[1] : "sd"),
25
+ "rec" === obj.type && pathnames[2] && (obj.recType = pathnames[2].includes(".cloud.") ? "cloud" : ""),
26
+ obj.searchParams = getQuery(url), obj;
27
+ }
28
+ return {};
29
+ }
30
+
31
+ var codec = {
32
+ h264: 1,
33
+ h265: 2,
34
+ h266: 4,
35
+ vp8: 8,
36
+ vp9: 16,
37
+ av1: 32
38
+ };
39
+
40
+ var index = {
41
+ parseEzopenUrl: parseEzopenUrl,
42
+ switchEzopenUrl: function(url, options) {
43
+ 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);
44
+ if (search) {
45
+ var ns = Object.assign({}, obj.searchParams, getQuery("?" + search.replace("?", "")));
46
+ search = Object.entries(ns).reduce(function(acc, param) {
47
+ var key = param[0], value = param[1];
48
+ return "" === value ? acc : acc += key + "=" + encodeURIComponent(value) + "&";
49
+ }, "?").replace(/&$/, "");
50
+ } else search = obj.search;
51
+ return type = type || obj.type, recType = null != recType ? recType : obj.recType,
52
+ definition = null != definition ? definition : obj.definition, channelNo = channelNo || obj.channelNo,
53
+ deviceSerial = deviceSerial || obj.deviceSerial, validateCode = null != validateCode ? validateCode : obj.validateCode,
54
+ obj.protocol + "//" + (validateCode ? validateCode + "@" : "") + obj.hostname + "/" + deviceSerial + "/" + channelNo + ("rec" === type && recType ? "." + recType : "") + ("live" === type && "hd" === definition ? "." + definition : "") + "." + type + search;
55
+ },
56
+ isHttp: function(url) {
57
+ return /^http[s]?:\/\//.test(url);
58
+ },
59
+ isMobile: function(agent) {
60
+ var _navigator, _navigator1, _navigator2, _window;
61
+ 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__);
62
+ },
63
+ getQuery: getQuery,
64
+ pick: function(obj, keys) {
65
+ return Object.entries(obj).reduce(function(acc, param) {
66
+ var key = param[0], value = param[1];
67
+ return keys.includes(key) && (acc[key] = value), acc;
68
+ }, {});
69
+ },
70
+ getStaticPath: function(path, base) {
71
+ void 0 === base && (base = "");
72
+ var protocolReg = /^(https?:\/\/|^\/\/)/;
73
+ if ("" === path || void 0 === path) return "";
74
+ if (protocolReg.test(path)) return path;
75
+ path = path.replace(/\/+/g, "/"), base = protocolReg.test(base || "") ? base : window.location.href;
76
+ try {
77
+ return new URL(path, base).href;
78
+ } catch (error) {
79
+ return path;
80
+ }
81
+ },
82
+ addVc: function(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
+
93
+ module.exports = index;
package/dist/index.mjs CHANGED
@@ -1,7 +1,91 @@
1
- /*
2
- * @ezuikit/utils-tools v1.1.1-beta.1
3
- * tools utils
4
- * Copyright (c) 2025-09-01 Ezviz-OpenBiz
5
- * Released under the MIT License.
6
- */
7
- const getQuery=url=>{const query=url.split("?")[1],obj={};if(query){const vars=query.split("&");for(let i=0;i<vars.length;i++){const pair=vars[i].split("=");obj[pair[0]]=decodeURIComponent(pair[1])}}return obj};function parseEzopenUrl(url){const obj={};if(/^ezopen:\/\//.test(url)){if(url.includes("@")){const endIndex=url.indexOf("@"),startIndex=url.indexOf("//");obj.validateCode=url.substring(startIndex+2,endIndex),url=url.replace(obj.validateCode+"@","")}obj.protocol=url.split("//")[0],obj.search=url.split("?")[1]?"?"+url.split("?")[1]:"",obj.hostname=url.split("/")[2],obj.origin=obj.protocol+"//"+obj.hostname,obj.pathname=url.split("?")[0].replace(obj.origin,""),obj.href=url;const pathnames=obj.pathname.split("/"),lastPath=pathnames[2].split(".");return obj.deviceSerial=pathnames[1],obj.channelNo=lastPath[0],obj.type=lastPath[lastPath.length-1],"live"===obj.type&&(obj.definition=lastPath.length>2?lastPath[1]:"sd"),"rec"===obj.type&&pathnames[2]&&(obj.recType=pathnames[2].includes(".cloud.")?"cloud":""),obj.searchParams=getQuery(url),obj}return{}}function switchEzopenUrl(url,options){let{type:type,recType:recType,search:search,definition:definition,channelNo:channelNo,deviceSerial:deviceSerial,validateCode:validateCode}=null!=options?options:{};const obj=parseEzopenUrl(url);if(search){const ns=Object.assign({},obj.searchParams,getQuery("?"+search.replace("?","")));search=Object.entries(ns).reduce(((acc,_ref)=>{let[key,value]=_ref;return""===value?acc:acc+=`${key}=${encodeURIComponent(value)}&`}),"?").replace(/&$/,"")}else search=obj.search;return type=type||obj.type,recType=null!=recType?recType:obj.recType,definition=null!=definition?definition:obj.definition,channelNo=channelNo||obj.channelNo,deviceSerial=deviceSerial||obj.deviceSerial,validateCode=null!=validateCode?validateCode:obj.validateCode,`${obj.protocol}//${validateCode?`${validateCode}@`:""}${obj.hostname}/${deviceSerial}/${channelNo}${"rec"===type&&recType?"."+recType:""}${"live"===type&&"hd"===definition?"."+definition:""}.${type}${search}`}function isHttp(url){return/^http[s]?:\/\//.test(url)}function isMobile(agent){var _navigator,_navigator1,_navigator2,_window;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__)}function pick(obj,keys){return Object.entries(obj).reduce(((acc,_ref)=>{let[key,value]=_ref;return keys.includes(key)&&(acc[key]=value),acc}),{})}function getStaticPath(path){let base=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const protocolReg=/^(https?:\/\/|^\/\/)/;if(""===path||void 0===path)return"";if(protocolReg.test(path))return path;path=path.replace(/\/+/g,"/"),base=protocolReg.test(base||"")?base:window.location.href;try{return new URL(path,base).href}catch(error){return path}}const codec={h264:1,h265:2,h266:4,vp8:8,vp9:16,av1:32};function addVc(url){const vc=((arguments.length>1&&void 0!==arguments[1]?arguments[1]:["h264"])||["h264"]).reduce(((acc,key)=>(key=key.toLowerCase(),acc+(codec[key]||0))),0);const host=url.split("?")[0];let query=url.split("?")[1];return query=(query||"").split("&").filter((item=>!/^vc=\d?/.test(item))).join("&"),query+=`${query?"&":""}vc=${vc}`,host+"?"+query}export{addVc,getQuery,getStaticPath,isHttp,isMobile,parseEzopenUrl,pick,switchEzopenUrl};
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
+ var codec = {
30
+ h264: 1,
31
+ h265: 2,
32
+ h266: 4,
33
+ vp8: 8,
34
+ vp9: 16,
35
+ av1: 32
36
+ };
37
+
38
+ var index = {
39
+ parseEzopenUrl: parseEzopenUrl,
40
+ switchEzopenUrl: function(url, options) {
41
+ 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);
42
+ if (search) {
43
+ var ns = Object.assign({}, obj.searchParams, getQuery("?" + search.replace("?", "")));
44
+ search = Object.entries(ns).reduce(function(acc, param) {
45
+ var key = param[0], value = param[1];
46
+ return "" === value ? acc : acc += key + "=" + encodeURIComponent(value) + "&";
47
+ }, "?").replace(/&$/, "");
48
+ } else search = obj.search;
49
+ return type = type || obj.type, recType = null != recType ? recType : obj.recType,
50
+ definition = null != definition ? definition : obj.definition, channelNo = channelNo || obj.channelNo,
51
+ deviceSerial = deviceSerial || obj.deviceSerial, validateCode = null != validateCode ? validateCode : obj.validateCode,
52
+ obj.protocol + "//" + (validateCode ? validateCode + "@" : "") + obj.hostname + "/" + deviceSerial + "/" + channelNo + ("rec" === type && recType ? "." + recType : "") + ("live" === type && "hd" === definition ? "." + definition : "") + "." + type + search;
53
+ },
54
+ isHttp: function(url) {
55
+ return /^http[s]?:\/\//.test(url);
56
+ },
57
+ isMobile: function(agent) {
58
+ var _navigator, _navigator1, _navigator2, _window;
59
+ 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__);
60
+ },
61
+ getQuery: getQuery,
62
+ pick: function(obj, keys) {
63
+ return Object.entries(obj).reduce(function(acc, param) {
64
+ var key = param[0], value = param[1];
65
+ return keys.includes(key) && (acc[key] = value), acc;
66
+ }, {});
67
+ },
68
+ getStaticPath: function(path, base) {
69
+ void 0 === base && (base = "");
70
+ var protocolReg = /^(https?:\/\/|^\/\/)/;
71
+ if ("" === path || void 0 === path) return "";
72
+ if (protocolReg.test(path)) return path;
73
+ path = path.replace(/\/+/g, "/"), base = protocolReg.test(base || "") ? base : window.location.href;
74
+ try {
75
+ return new URL(path, base).href;
76
+ } catch (error) {
77
+ return path;
78
+ }
79
+ },
80
+ addVc: function(url, codecs) {
81
+ void 0 === codecs && (codecs = [ "h264" ]);
82
+ var vc = (codecs || [ "h264" ]).reduce(function(acc, key) {
83
+ return key = key.toLowerCase(), acc + (codec[key] || 0);
84
+ }, 0), host = url.split("?")[0], query = url.split("?")[1];
85
+ return query = (query || "").split("&").filter(function(item) {
86
+ return !/^vc=\d?/.test(item);
87
+ }).join("&"), host + "?" + (query += (query ? "&" : "") + "vc=" + vc);
88
+ }
89
+ };
90
+
91
+ export { index as default };
package/dist/index.umd.js CHANGED
@@ -1,7 +1,91 @@
1
- /*
2
- * @ezuikit/utils-tools v1.1.1-beta.1
3
- * tools utils
4
- * Copyright (c) 2025-09-01 Ezviz-OpenBiz
5
- * Released under the MIT License.
6
- */
7
- !function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).Tools={})}(this,(function(exports){"use strict";var getQuery=function(url){var query=url.split("?")[1],obj={};if(query)for(var vars=query.split("&"),i=0;i<vars.length;i++){var pair=vars[i].split("=");obj[pair[0]]=decodeURIComponent(pair[1])}return obj};function parseEzopenUrl(url){var obj={};if(/^ezopen:\/\//.test(url)){if(url.includes("@")){var endIndex=url.indexOf("@"),startIndex=url.indexOf("//");obj.validateCode=url.substring(startIndex+2,endIndex),url=url.replace(obj.validateCode+"@","")}obj.protocol=url.split("//")[0],obj.search=url.split("?")[1]?"?"+url.split("?")[1]:"",obj.hostname=url.split("/")[2],obj.origin=obj.protocol+"//"+obj.hostname,obj.pathname=url.split("?")[0].replace(obj.origin,""),obj.href=url;var pathnames=obj.pathname.split("/"),lastPath=pathnames[2].split(".");return obj.deviceSerial=pathnames[1],obj.channelNo=lastPath[0],obj.type=lastPath[lastPath.length-1],"live"===obj.type&&(obj.definition=lastPath.length>2?lastPath[1]:"sd"),"rec"===obj.type&&pathnames[2]&&(obj.recType=pathnames[2].includes(".cloud.")?"cloud":""),obj.searchParams=getQuery(url),obj}return{}}var codec={h264:1,h265:2,h266:4,vp8:8,vp9:16,av1:32};exports.addVc=function(url,codecs){void 0===codecs&&(codecs=["h264"]);var vc=(codecs||["h264"]).reduce((function(acc,key){return key=key.toLowerCase(),acc+(codec[key]||0)}),0),host=url.split("?")[0],query=url.split("?")[1];return query=(query||"").split("&").filter((function(item){return!/^vc=\d?/.test(item)})).join("&"),host+"?"+(query+=(query?"&":"")+"vc="+vc)},exports.getQuery=getQuery,exports.getStaticPath=function(path,base){void 0===base&&(base="");var protocolReg=/^(https?:\/\/|^\/\/)/;if(""===path||void 0===path)return"";if(protocolReg.test(path))return path;path=path.replace(/\/+/g,"/"),base=protocolReg.test(base||"")?base:window.location.href;try{return new URL(path,base).href}catch(error){return path}},exports.isHttp=function(url){return/^http[s]?:\/\//.test(url)},exports.isMobile=function(agent){var _navigator,_navigator1,_navigator2,_window;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__)},exports.parseEzopenUrl=parseEzopenUrl,exports.pick=function(obj,keys){return Object.entries(obj).reduce((function(acc,param){var key=param[0],value=param[1];return keys.includes(key)&&(acc[key]=value),acc}),{})},exports.switchEzopenUrl=function(url,options){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);if(search){var ns=Object.assign({},obj.searchParams,getQuery("?"+search.replace("?","")));search=Object.entries(ns).reduce((function(acc,param){var key=param[0],value=param[1];return""===value?acc:acc+=key+"="+encodeURIComponent(value)+"&"}),"?").replace(/&$/,"")}else search=obj.search;return type=type||obj.type,recType=null!=recType?recType:obj.recType,definition=null!=definition?definition:obj.definition,channelNo=channelNo||obj.channelNo,deviceSerial=deviceSerial||obj.deviceSerial,validateCode=null!=validateCode?validateCode:obj.validateCode,obj.protocol+"//"+(validateCode?validateCode+"@":"")+obj.hostname+"/"+deviceSerial+"/"+channelNo+("rec"===type&&recType?"."+recType:"")+("live"===type&&"hd"===definition?"."+definition:"")+"."+type+search}}));
1
+ !function(global, factory) {
2
+ "object" == typeof exports && "undefined" != typeof module ? module.exports = factory() : "function" == typeof define && define.amd ? define(factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self).Tools = factory();
3
+ }(this, function() {
4
+ "use strict";
5
+ var getQuery = function(url) {
6
+ var query = url.split("?")[1], obj = {};
7
+ if (query) for (var vars = query.split("&"), i = 0; i < vars.length; i++) {
8
+ var pair = vars[i].split("=");
9
+ obj[pair[0]] = decodeURIComponent(pair[1]);
10
+ }
11
+ return obj;
12
+ };
13
+ function parseEzopenUrl(url) {
14
+ var obj = {};
15
+ if (/^ezopen:\/\//.test(url)) {
16
+ if (url.includes("@")) {
17
+ var endIndex = url.indexOf("@"), startIndex = url.indexOf("//");
18
+ obj.validateCode = url.substring(startIndex + 2, endIndex), url = url.replace(obj.validateCode + "@", "");
19
+ }
20
+ obj.protocol = url.split("//")[0], obj.search = url.split("?")[1] ? "?" + url.split("?")[1] : "",
21
+ obj.hostname = url.split("/")[2], obj.origin = obj.protocol + "//" + obj.hostname,
22
+ obj.pathname = url.split("?")[0].replace(obj.origin, ""), obj.href = url;
23
+ var pathnames = obj.pathname.split("/"), lastPath = pathnames[2].split(".");
24
+ return obj.deviceSerial = pathnames[1], obj.channelNo = lastPath[0], obj.type = lastPath[lastPath.length - 1],
25
+ "live" === obj.type && (obj.definition = lastPath.length > 2 ? lastPath[1] : "sd"),
26
+ "rec" === obj.type && pathnames[2] && (obj.recType = pathnames[2].includes(".cloud.") ? "cloud" : ""),
27
+ obj.searchParams = getQuery(url), obj;
28
+ }
29
+ return {};
30
+ }
31
+ var codec = {
32
+ h264: 1,
33
+ h265: 2,
34
+ h266: 4,
35
+ vp8: 8,
36
+ vp9: 16,
37
+ av1: 32
38
+ };
39
+ return {
40
+ parseEzopenUrl: parseEzopenUrl,
41
+ switchEzopenUrl: function(url, options) {
42
+ 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);
43
+ if (search) {
44
+ var ns = Object.assign({}, obj.searchParams, getQuery("?" + search.replace("?", "")));
45
+ search = Object.entries(ns).reduce(function(acc, param) {
46
+ var key = param[0], value = param[1];
47
+ return "" === value ? acc : acc += key + "=" + encodeURIComponent(value) + "&";
48
+ }, "?").replace(/&$/, "");
49
+ } else search = obj.search;
50
+ return type = type || obj.type, recType = null != recType ? recType : obj.recType,
51
+ definition = null != definition ? definition : obj.definition, channelNo = channelNo || obj.channelNo,
52
+ deviceSerial = deviceSerial || obj.deviceSerial, validateCode = null != validateCode ? validateCode : obj.validateCode,
53
+ obj.protocol + "//" + (validateCode ? validateCode + "@" : "") + obj.hostname + "/" + deviceSerial + "/" + channelNo + ("rec" === type && recType ? "." + recType : "") + ("live" === type && "hd" === definition ? "." + definition : "") + "." + type + search;
54
+ },
55
+ isHttp: function(url) {
56
+ return /^http[s]?:\/\//.test(url);
57
+ },
58
+ isMobile: function(agent) {
59
+ var _navigator, _navigator1, _navigator2, _window;
60
+ 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__);
61
+ },
62
+ getQuery: getQuery,
63
+ pick: function(obj, keys) {
64
+ return Object.entries(obj).reduce(function(acc, param) {
65
+ var key = param[0], value = param[1];
66
+ return keys.includes(key) && (acc[key] = value), acc;
67
+ }, {});
68
+ },
69
+ getStaticPath: function(path, base) {
70
+ void 0 === base && (base = "");
71
+ var protocolReg = /^(https?:\/\/|^\/\/)/;
72
+ if ("" === path || void 0 === path) return "";
73
+ if (protocolReg.test(path)) return path;
74
+ path = path.replace(/\/+/g, "/"), base = protocolReg.test(base || "") ? base : window.location.href;
75
+ try {
76
+ return new URL(path, base).href;
77
+ } catch (error) {
78
+ return path;
79
+ }
80
+ },
81
+ addVc: function(url, codecs) {
82
+ void 0 === codecs && (codecs = [ "h264" ]);
83
+ var vc = (codecs || [ "h264" ]).reduce(function(acc, key) {
84
+ return key = key.toLowerCase(), acc + (codec[key] || 0);
85
+ }, 0), host = url.split("?")[0], query = url.split("?")[1];
86
+ return query = (query || "").split("&").filter(function(item) {
87
+ return !/^vc=\d?/.test(item);
88
+ }).join("&"), host + "?" + (query += (query ? "&" : "") + "vc=" + vc);
89
+ }
90
+ };
91
+ });
@@ -1,8 +1,18 @@
1
1
  import { parseEzopenUrl, switchEzopenUrl, type EzopenURL, type SwitchEzpoenOptions, type EzopenType, type EzopenRecType, type EzopenDefinition } from './ezopenUrl';
2
2
  import { isHttp } from './isHttp';
3
3
  import { isMobile } from './isMobile';
4
- import { getQuery } from './query';
5
4
  import { pick } from './pick';
6
5
  import { getStaticPath } from './getStaticPath';
7
6
  import { addVc } from './addVc';
8
- export { parseEzopenUrl, switchEzopenUrl, type EzopenURL, type SwitchEzpoenOptions, type EzopenType, type EzopenRecType, type EzopenDefinition, isHttp, isMobile, getQuery, pick, getStaticPath, addVc, };
7
+ export type { EzopenURL, SwitchEzpoenOptions, EzopenType, EzopenRecType, EzopenDefinition };
8
+ declare const _default: {
9
+ parseEzopenUrl: typeof parseEzopenUrl;
10
+ switchEzopenUrl: typeof switchEzopenUrl;
11
+ isHttp: typeof isHttp;
12
+ isMobile: typeof isMobile;
13
+ getQuery: (url: string) => Record<string, string>;
14
+ pick: typeof pick;
15
+ getStaticPath: typeof getStaticPath;
16
+ addVc: typeof addVc;
17
+ };
18
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezuikit/utils-tools",
3
- "version": "1.1.1-beta.1",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "tools utils",
5
5
  "main": "dist/index.js",
6
6
  "umd": "dist/index.umd.js",