@ezuikit/utils-tools 2.0.0 → 2.0.1-beta.1

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,82 +1,7 @@
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
- exports.addVc = function(url, codecs) {
41
- void 0 === codecs && (codecs = [ "h264" ]);
42
- var vc = (codecs || [ "h264" ]).reduce(function(acc, key) {
43
- return key = key.toLowerCase(), acc + (__$codec$__[key] || 0);
44
- }, 0), host = url.split("?")[0], query = url.split("?")[1];
45
- return query = (query || "").split("&").filter(function(item) {
46
- return !/^vc=\d?/.test(item);
47
- }).join("&"), host + "?" + (query += (query ? "&" : "") + "vc=" + vc);
48
- }, exports.getQuery = getQuery, exports.getStaticPath = function(path, base) {
49
- void 0 === base && (base = "");
50
- var protocolReg = /^(https?:\/\/|^\/\/)/;
51
- if ("" === path || void 0 === path) return "";
52
- if (protocolReg.test(path)) return path;
53
- path = path.replace(/\/+/g, "/"), base = protocolReg.test(base || "") ? base : window.location.href;
54
- try {
55
- return new URL(path, base).href;
56
- } catch (error) {
57
- return path;
58
- }
59
- }, exports.isHttp = function(url) {
60
- return /^http[s]?:\/\//.test(url);
61
- }, exports.isMobile = function(agent) {
62
- var _navigator, _navigator1, _navigator2, _window;
63
- 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__);
64
- }, exports.parseEzopenUrl = parseEzopenUrl, exports.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
- }, exports.switchEzopenUrl = function(url, options) {
70
- 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);
71
- if (search) {
72
- var ns = Object.assign({}, obj.searchParams, getQuery("?" + search.replace("?", "")));
73
- search = Object.entries(ns).reduce(function(acc, param) {
74
- var key = param[0], value = param[1];
75
- return "" === value ? acc : acc += key + "=" + encodeURIComponent(value) + "&";
76
- }, "?").replace(/&$/, "");
77
- } else search = obj.search;
78
- return type = type || obj.type, recType = null != recType ? recType : obj.recType,
79
- definition = null != definition ? definition : obj.definition, channelNo = channelNo || obj.channelNo,
80
- deviceSerial = deviceSerial || obj.deviceSerial, validateCode = null != validateCode ? validateCode : obj.validateCode,
81
- obj.protocol + "//" + (validateCode ? validateCode + "@" : "") + obj.hostname + "/" + deviceSerial + "/" + channelNo + ("rec" === type && recType ? "." + recType : "") + ("live" === type && "hd" === definition ? "." + definition : "") + "." + type + search;
82
- };
1
+ /*
2
+ * @ezuikit/utils-tools v2.0.1-beta.1
3
+ * tools utils
4
+ * Copyright (c) 2025-11-16 Ezviz-OpenBiz
5
+ * Released under the MIT License.
6
+ */
7
+ "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(agent||(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};
package/dist/index.umd.js CHANGED
@@ -1,82 +1,7 @@
1
- !function(global, factory) {
2
- "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 = {});
3
- }(this, function(exports) {
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
- exports.addVc = function(url, codecs) {
40
- void 0 === codecs && (codecs = [ "h264" ]);
41
- var vc = (codecs || [ "h264" ]).reduce(function(acc, key) {
42
- return key = key.toLowerCase(), acc + (__$codec$__[key] || 0);
43
- }, 0), host = url.split("?")[0], query = url.split("?")[1];
44
- return query = (query || "").split("&").filter(function(item) {
45
- return !/^vc=\d?/.test(item);
46
- }).join("&"), host + "?" + (query += (query ? "&" : "") + "vc=" + vc);
47
- }, exports.getQuery = getQuery, exports.getStaticPath = function(path, base) {
48
- void 0 === base && (base = "");
49
- var protocolReg = /^(https?:\/\/|^\/\/)/;
50
- if ("" === path || void 0 === path) return "";
51
- if (protocolReg.test(path)) return path;
52
- path = path.replace(/\/+/g, "/"), base = protocolReg.test(base || "") ? base : window.location.href;
53
- try {
54
- return new URL(path, base).href;
55
- } catch (error) {
56
- return path;
57
- }
58
- }, exports.isHttp = function(url) {
59
- return /^http[s]?:\/\//.test(url);
60
- }, exports.isMobile = function(agent) {
61
- var _navigator, _navigator1, _navigator2, _window;
62
- 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__);
63
- }, exports.parseEzopenUrl = parseEzopenUrl, exports.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
- }, exports.switchEzopenUrl = function(url, options) {
69
- 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);
70
- if (search) {
71
- var ns = Object.assign({}, obj.searchParams, getQuery("?" + search.replace("?", "")));
72
- search = Object.entries(ns).reduce(function(acc, param) {
73
- var key = param[0], value = param[1];
74
- return "" === value ? acc : acc += key + "=" + encodeURIComponent(value) + "&";
75
- }, "?").replace(/&$/, "");
76
- } else search = obj.search;
77
- return type = type || obj.type, recType = null != recType ? recType : obj.recType,
78
- definition = null != definition ? definition : obj.definition, channelNo = channelNo || obj.channelNo,
79
- deviceSerial = deviceSerial || obj.deviceSerial, validateCode = null != validateCode ? validateCode : obj.validateCode,
80
- obj.protocol + "//" + (validateCode ? validateCode + "@" : "") + obj.hostname + "/" + deviceSerial + "/" + channelNo + ("rec" === type && recType ? "." + recType : "") + ("live" === type && "hd" === definition ? "." + definition : "") + "." + type + search;
81
- };
82
- });
1
+ /*
2
+ * @ezuikit/utils-tools v2.0.1-beta.1
3
+ * tools utils
4
+ * Copyright (c) 2025-11-16 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(agent||(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}}));
@@ -5,5 +5,4 @@ import { getQuery } from './query';
5
5
  import { pick } from './pick';
6
6
  import { getStaticPath } from './getStaticPath';
7
7
  import { addVc } from './addVc';
8
- export type { EzopenURL, SwitchEzpoenOptions, EzopenType, EzopenRecType, EzopenDefinition };
9
- export { parseEzopenUrl, switchEzopenUrl, isHttp, isMobile, getQuery, pick, getStaticPath, addVc };
8
+ export { parseEzopenUrl, switchEzopenUrl, type EzopenURL, type SwitchEzpoenOptions, type EzopenType, type EzopenRecType, type EzopenDefinition, isHttp, isMobile, getQuery, pick, getStaticPath, addVc, };
@@ -1 +1,6 @@
1
+ /**
2
+ * 判断是否是http开头的url
3
+ * @param url
4
+ * @returns boolean
5
+ */
1
6
  export declare function isHttp(url: string): boolean;
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * 判断是不是移动端(包括pad)
3
3
  *
4
- * __IS_MOBILE_SIMULATOR__ 为了解决在 PC 端模拟移动端时判断为移动端
4
+ * `__IS_MOBILE_SIMULATOR__` 为了解决在 PC 端模拟移动端时判断为移动端
5
+ *
5
6
  * @param {string} agent
6
7
  * @returns {boolean}
7
8
  */
8
- export declare function isMobile(agent?: string): any;
9
+ export declare function isMobile(agent?: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezuikit/utils-tools",
3
- "version": "2.0.0",
3
+ "version": "2.0.1-beta.1",
4
4
  "description": "tools utils",
5
5
  "main": "dist/index.js",
6
6
  "umd": "dist/index.umd.js",