@ezuikit/utils-tools 2.0.5 → 2.0.6
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 +3 -3
- package/dist/index.umd.js +3 -3
- package/dist/types/addVc.d.ts +12 -3
- package/dist/types/ezopenUrl.d.ts +11 -4
- package/dist/types/index.d.ts +4 -3
- package/dist/types/isHttp.d.ts +11 -3
- package/dist/types/isMobile.d.ts +25 -6
- package/dist/types/null.d.ts +33 -0
- package/dist/types/pick.d.ts +1 -1
- package/dist/types/query.d.ts +16 -0
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @ezuikit/utils-tools v2.0.
|
|
2
|
+
* @ezuikit/utils-tools v2.0.6
|
|
3
3
|
* tools utils
|
|
4
|
-
* Copyright (c) 2026-
|
|
4
|
+
* Copyright (c) 2026-08-02 Ezviz-OpenBiz
|
|
5
5
|
* Released under the MIT License.
|
|
6
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};function _array_like_to_array(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _instanceof(left,right){return null!=right&&"undefined"!=typeof Symbol&&right[Symbol.hasInstance]?!!right[Symbol.hasInstance](left):left instanceof right}function _create_for_of_iterator_helper_loose(o,allowArrayLike){var it="undefined"!=typeof Symbol&&o[Symbol.iterator]||o["@@iterator"];if(it)return(it=it.call(o)).next.bind(it);if(Array.isArray(o)||(it=function(o,minLen){if(o){if("string"==typeof o)return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_array_like_to_array(o,minLen):void 0}}(o))||allowArrayLike){it&&(o=it);var i=0;return function(){return i>=o.length?{done:!0}:{done:!1,value:o[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var DateTime=function(){function DateTime(){}return DateTime.normalizeUnit=function(unit){return"year"===unit||"y"===unit||"年"===unit?"year":"month"===unit||"M"===unit||"月"===unit?"month":"day"===unit||"d"===unit||"日"===unit?"day":"hour"===unit||"h"===unit||"时"===unit?"hour":"minute"===unit||"m"===unit||"分"===unit?"minute":"second"},DateTime.daysInMonth=function(year,month){return new Date(year,month+1,0).getDate()},DateTime.shiftMonth=function(baseDate,months){var result=new Date(baseDate.getTime()),currentDate=result.getDate();result.setDate(1),result.setMonth(result.getMonth()+months);var maxDate=DateTime.daysInMonth(result.getFullYear(),result.getMonth());return result.setDate(Math.min(currentDate,maxDate)),result},DateTime.add=function(input,value,unit){if(void 0===unit&&(unit="day"),!Number.isFinite(value))throw new Error("Invalid value");var baseDate=DateTime.toDate(input),normalizedUnit=DateTime.normalizeUnit(unit);if("year"===normalizedUnit)return DateTime.shiftMonth(baseDate,12*value);if("month"===normalizedUnit)return DateTime.shiftMonth(baseDate,value);var result=new Date(baseDate.getTime());return result.setTime(result.getTime()+value*{day:864e5,hour:36e5,minute:6e4,second:1e3}[normalizedUnit]),result},DateTime.subtract=function(input,value,unit){return void 0===unit&&(unit="day"),DateTime.add(input,-value,unit)},DateTime.fillZero=function(num,len){return void 0===len&&(len=2),num.toString().padStart(len,"0")},DateTime.format=function(input,format){var date;if(_instanceof(input,Date))date=input;else{if("number"!=typeof input&&"string"!=typeof input)throw new Error("Invalid date input");date=DateTime.toDate(input+"")}for(var _step,result=format,_iterator=_create_for_of_iterator_helper_loose([[/(yyyy|YYYY)/g,function(){return DateTime.fillZero(date.getFullYear(),4)}],[/(yy|YY)/g,function(){return DateTime.fillZero(date.getFullYear()%100,2)}],[/(MM)/g,function(){return DateTime.fillZero(date.getMonth()+1,2)}],[/(M)/g,function(){return(date.getMonth()+1).toString()}],[/(dd|DD)/g,function(){return DateTime.fillZero(date.getDate(),2)}],[/(d|D)/g,function(){return date.getDate().toString()}],[/(HH|hh)/g,function(){return DateTime.fillZero(date.getHours(),2)}],[/(H|h)/g,function(){return date.getHours().toString()}],[/(mm)/g,function(){return DateTime.fillZero(date.getMinutes(),2)}],[/(m)/g,function(){return date.getMinutes().toString()}],[/(ss|SS)/g,function(){return DateTime.fillZero(date.getSeconds(),2)}],[/(s|S)/g,function(){return date.getSeconds().toString()}],[/(fff)/g,function(){return DateTime.fillZero(date.getMilliseconds(),3)}]]);!(_step=_iterator()).done;){var _step_value=_step.value,regexp=_step_value[0],fn=_step_value[1];result=result.replace(regexp,fn)}return result},DateTime.toDate=function(str){if(_instanceof(str,Date))return str;str=(str+"").trim().replace(/\/|\./gi,"-"),/^\d{4}$/.test(str)&&(str+="-01"),/^\d{4}-\d{2}$/.test(str)&&(str+="-01");try{return/^\d{4}-\d{2}-\d{2}$/.test(str)?new Date(+str.slice(0,4),+str.slice(5,7)-1,+str.slice(8,10),0,0,0):/^\d{8}$/.test(str)?(str+="",new Date(+str.slice(0,4),+str.slice(4,6)-1,+str.slice(6,8),0,0,0)):/^\d{14}$/.test(str)?(str+="",new Date(+str.slice(0,4),+str.slice(4,6)-1,+str.slice(6,8),+str.slice(8,10),+str.slice(10,12),+str.slice(12,14))):/^\d{13}$/.test(str)?new Date(Number(str)):/^\d{10}$/.test(str)?new Date(1e3*Number(str)):new Date(str)}catch(error){throw new Error("Invalid date string")}},DateTime.diff=function(date1,date2,type){void 0===type&&(type="second");var d1=DateTime.toDate(date1),d2=DateTime.toDate(date2);return"second"===type?Math.floor((d1.getTime()-d2.getTime())/1e3):"minute"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60):"hour"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60/60):"day"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60/60/24):Math.abs(d1.getTime()-d2.getTime())},DateTime}();exports.DateTime=DateTime,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.isRealMobile=function(agent){var _navigator,ua=(null!=agent?agent:null==(_navigator=navigator)?void 0:_navigator.userAgent).toLowerCase();if(/ipad|tablet|playbook|silk|android(?!.*mobile)/i.test(ua))return!1;var hasTouch="ontouchstart"in window||navigator.maxTouchPoints>0;return/android|webos|iphone|ipod|blackberry|iemobile|opera mini/i.test(ua)&&hasTouch},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};
|
|
7
|
+
"use strict";function isHttp(url){return/^http[s]?:\/\//.test(url)}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}if(isHttp(url))try{var u=new URL(url),file=u.pathname.split("/").pop();if(file){var m=file.match(/^([^_]+)_(\d+)_(\d+)\./);if(m){var deviceSerial=m[1],channelNo=m[2],quality=m[3];return obj.deviceSerial=deviceSerial,obj.channelNo=channelNo,u.searchParams.get("code")&&(obj.validateCode=u.searchParams.get("code")),obj.search=url.split("?")[1]?"?"+url.split("?")[1]:"",obj.protocol=url.split("//")[0],obj.hostname=url.split("/")[2],obj.origin=obj.protocol+"//"+obj.hostname,obj.pathname=url.split("?")[0].replace(obj.origin,""),obj.href=url,obj.type="live",(url.includes("rec=local")||url.includes("rec=cloud"))&&(obj.type="rec",url.includes("rec=cloud")?obj.recType="cloud":obj.recType=""),"live"===obj.type&&(obj.definition="1"===quality?"hd":"sd"),obj.searchParams=getQuery(url),obj}}}catch(e){}return{}}var codec={h264:1,h265:2,h266:4,vp8:8,vp9:16,av1:32},getQueryVC=function(CODECS){return CODECS.reduce((function(acc,key){return key=key.toLowerCase(),acc+(codec[key]||0)}),0)};function _array_like_to_array(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _instanceof(left,right){return null!=right&&"undefined"!=typeof Symbol&&right[Symbol.hasInstance]?!!right[Symbol.hasInstance](left):left instanceof right}function _create_for_of_iterator_helper_loose(o,allowArrayLike){var it="undefined"!=typeof Symbol&&o[Symbol.iterator]||o["@@iterator"];if(it)return(it=it.call(o)).next.bind(it);if(Array.isArray(o)||(it=function(o,minLen){if(o){if("string"==typeof o)return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_array_like_to_array(o,minLen):void 0}}(o))||allowArrayLike){it&&(o=it);var i=0;return function(){return i>=o.length?{done:!0}:{done:!1,value:o[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var DateTime=function(){function DateTime(){}return DateTime.normalizeUnit=function(unit){return"year"===unit||"y"===unit||"年"===unit?"year":"month"===unit||"M"===unit||"月"===unit?"month":"day"===unit||"d"===unit||"日"===unit?"day":"hour"===unit||"h"===unit||"时"===unit?"hour":"minute"===unit||"m"===unit||"分"===unit?"minute":"second"},DateTime.daysInMonth=function(year,month){return new Date(year,month+1,0).getDate()},DateTime.shiftMonth=function(baseDate,months){var result=new Date(baseDate.getTime()),currentDate=result.getDate();result.setDate(1),result.setMonth(result.getMonth()+months);var maxDate=DateTime.daysInMonth(result.getFullYear(),result.getMonth());return result.setDate(Math.min(currentDate,maxDate)),result},DateTime.add=function(input,value,unit){if(void 0===unit&&(unit="day"),!Number.isFinite(value))throw new Error("Invalid value");var baseDate=DateTime.toDate(input),normalizedUnit=DateTime.normalizeUnit(unit);if("year"===normalizedUnit)return DateTime.shiftMonth(baseDate,12*value);if("month"===normalizedUnit)return DateTime.shiftMonth(baseDate,value);var result=new Date(baseDate.getTime());return result.setTime(result.getTime()+value*{day:864e5,hour:36e5,minute:6e4,second:1e3}[normalizedUnit]),result},DateTime.subtract=function(input,value,unit){return void 0===unit&&(unit="day"),DateTime.add(input,-value,unit)},DateTime.fillZero=function(num,len){return void 0===len&&(len=2),num.toString().padStart(len,"0")},DateTime.format=function(input,format){var date;if(_instanceof(input,Date))date=input;else{if("number"!=typeof input&&"string"!=typeof input)throw new Error("Invalid date input");date=DateTime.toDate(input+"")}for(var _step,result=format,_iterator=_create_for_of_iterator_helper_loose([[/(yyyy|YYYY)/g,function(){return DateTime.fillZero(date.getFullYear(),4)}],[/(yy|YY)/g,function(){return DateTime.fillZero(date.getFullYear()%100,2)}],[/(MM)/g,function(){return DateTime.fillZero(date.getMonth()+1,2)}],[/(M)/g,function(){return(date.getMonth()+1).toString()}],[/(dd|DD)/g,function(){return DateTime.fillZero(date.getDate(),2)}],[/(d|D)/g,function(){return date.getDate().toString()}],[/(HH|hh)/g,function(){return DateTime.fillZero(date.getHours(),2)}],[/(H|h)/g,function(){return date.getHours().toString()}],[/(mm)/g,function(){return DateTime.fillZero(date.getMinutes(),2)}],[/(m)/g,function(){return date.getMinutes().toString()}],[/(ss|SS)/g,function(){return DateTime.fillZero(date.getSeconds(),2)}],[/(s|S)/g,function(){return date.getSeconds().toString()}],[/(fff)/g,function(){return DateTime.fillZero(date.getMilliseconds(),3)}]]);!(_step=_iterator()).done;){var _step_value=_step.value,regexp=_step_value[0],fn=_step_value[1];result=result.replace(regexp,fn)}return result},DateTime.toDate=function(str){if(_instanceof(str,Date))return str;str=(str+"").trim().replace(/\/|\./gi,"-"),/^\d{4}$/.test(str)&&(str+="-01"),/^\d{4}-\d{2}$/.test(str)&&(str+="-01");try{return/^\d{4}-\d{2}-\d{2}$/.test(str)?new Date(+str.slice(0,4),+str.slice(5,7)-1,+str.slice(8,10),0,0,0):/^\d{8}$/.test(str)?(str+="",new Date(+str.slice(0,4),+str.slice(4,6)-1,+str.slice(6,8),0,0,0)):/^\d{14}$/.test(str)?(str+="",new Date(+str.slice(0,4),+str.slice(4,6)-1,+str.slice(6,8),+str.slice(8,10),+str.slice(10,12),+str.slice(12,14))):/^\d{13}$/.test(str)?new Date(Number(str)):/^\d{10}$/.test(str)?new Date(1e3*Number(str)):new Date(str)}catch(error){throw new Error("Invalid date string")}},DateTime.diff=function(date1,date2,type){void 0===type&&(type="second");var d1=DateTime.toDate(date1),d2=DateTime.toDate(date2);return"second"===type?Math.floor((d1.getTime()-d2.getTime())/1e3):"minute"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60):"hour"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60/60):"day"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60/60/24):Math.abs(d1.getTime()-d2.getTime())},DateTime}();exports.DateTime=DateTime,exports.addVc=function(url,codecs){void 0===codecs&&(codecs=["h264"]);var vc=getQueryVC(codecs||["h264"]),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.getQueryVC=getQueryVC,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.isEmpty=function(param){return void 0===param||""===param||null===param},exports.isHttp=isHttp,exports.isMobile=function(agent){var _navigator,_navigator1,_navigator2,_window,_navigator_maxTouchPoints;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!=(_navigator_maxTouchPoints=null==(_navigator2=navigator)?void 0:_navigator2.maxTouchPoints)?_navigator_maxTouchPoints:0)>1||!!(null==(_window=window)?void 0:_window.__IS_MOBILE_SIMULATOR__)},exports.isRealMobile=function(agent){var _navigator,_ref,ua=(null!=(_ref=null!=agent?agent:null==(_navigator=navigator)?void 0:_navigator.userAgent)?_ref:"").toLowerCase();if(/ipad|tablet|playbook|silk|android(?!.*mobile)/i.test(ua))return!1;var hasTouch="ontouchstart"in window||navigator.maxTouchPoints>0;return/android|webos|iphone|ipod|blackberry|iemobile|opera mini/i.test(ua)&&hasTouch},exports.objectIsNull=function(obj){try{return"{}"===JSON.stringify(obj)}catch(error){return!1}},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,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @ezuikit/utils-tools v2.0.
|
|
2
|
+
* @ezuikit/utils-tools v2.0.6
|
|
3
3
|
* tools utils
|
|
4
|
-
* Copyright (c) 2026-
|
|
4
|
+
* Copyright (c) 2026-08-02 Ezviz-OpenBiz
|
|
5
5
|
* Released under the MIT License.
|
|
6
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};function _array_like_to_array(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _instanceof(left,right){return null!=right&&"undefined"!=typeof Symbol&&right[Symbol.hasInstance]?!!right[Symbol.hasInstance](left):left instanceof right}function _create_for_of_iterator_helper_loose(o,allowArrayLike){var it="undefined"!=typeof Symbol&&o[Symbol.iterator]||o["@@iterator"];if(it)return(it=it.call(o)).next.bind(it);if(Array.isArray(o)||(it=function(o,minLen){if(o){if("string"==typeof o)return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_array_like_to_array(o,minLen):void 0}}(o))||allowArrayLike){it&&(o=it);var i=0;return function(){return i>=o.length?{done:!0}:{done:!1,value:o[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var DateTime=function(){function DateTime(){}return DateTime.normalizeUnit=function(unit){return"year"===unit||"y"===unit||"年"===unit?"year":"month"===unit||"M"===unit||"月"===unit?"month":"day"===unit||"d"===unit||"日"===unit?"day":"hour"===unit||"h"===unit||"时"===unit?"hour":"minute"===unit||"m"===unit||"分"===unit?"minute":"second"},DateTime.daysInMonth=function(year,month){return new Date(year,month+1,0).getDate()},DateTime.shiftMonth=function(baseDate,months){var result=new Date(baseDate.getTime()),currentDate=result.getDate();result.setDate(1),result.setMonth(result.getMonth()+months);var maxDate=DateTime.daysInMonth(result.getFullYear(),result.getMonth());return result.setDate(Math.min(currentDate,maxDate)),result},DateTime.add=function(input,value,unit){if(void 0===unit&&(unit="day"),!Number.isFinite(value))throw new Error("Invalid value");var baseDate=DateTime.toDate(input),normalizedUnit=DateTime.normalizeUnit(unit);if("year"===normalizedUnit)return DateTime.shiftMonth(baseDate,12*value);if("month"===normalizedUnit)return DateTime.shiftMonth(baseDate,value);var result=new Date(baseDate.getTime());return result.setTime(result.getTime()+value*{day:864e5,hour:36e5,minute:6e4,second:1e3}[normalizedUnit]),result},DateTime.subtract=function(input,value,unit){return void 0===unit&&(unit="day"),DateTime.add(input,-value,unit)},DateTime.fillZero=function(num,len){return void 0===len&&(len=2),num.toString().padStart(len,"0")},DateTime.format=function(input,format){var date;if(_instanceof(input,Date))date=input;else{if("number"!=typeof input&&"string"!=typeof input)throw new Error("Invalid date input");date=DateTime.toDate(input+"")}for(var _step,result=format,_iterator=_create_for_of_iterator_helper_loose([[/(yyyy|YYYY)/g,function(){return DateTime.fillZero(date.getFullYear(),4)}],[/(yy|YY)/g,function(){return DateTime.fillZero(date.getFullYear()%100,2)}],[/(MM)/g,function(){return DateTime.fillZero(date.getMonth()+1,2)}],[/(M)/g,function(){return(date.getMonth()+1).toString()}],[/(dd|DD)/g,function(){return DateTime.fillZero(date.getDate(),2)}],[/(d|D)/g,function(){return date.getDate().toString()}],[/(HH|hh)/g,function(){return DateTime.fillZero(date.getHours(),2)}],[/(H|h)/g,function(){return date.getHours().toString()}],[/(mm)/g,function(){return DateTime.fillZero(date.getMinutes(),2)}],[/(m)/g,function(){return date.getMinutes().toString()}],[/(ss|SS)/g,function(){return DateTime.fillZero(date.getSeconds(),2)}],[/(s|S)/g,function(){return date.getSeconds().toString()}],[/(fff)/g,function(){return DateTime.fillZero(date.getMilliseconds(),3)}]]);!(_step=_iterator()).done;){var _step_value=_step.value,regexp=_step_value[0],fn=_step_value[1];result=result.replace(regexp,fn)}return result},DateTime.toDate=function(str){if(_instanceof(str,Date))return str;str=(str+"").trim().replace(/\/|\./gi,"-"),/^\d{4}$/.test(str)&&(str+="-01"),/^\d{4}-\d{2}$/.test(str)&&(str+="-01");try{return/^\d{4}-\d{2}-\d{2}$/.test(str)?new Date(+str.slice(0,4),+str.slice(5,7)-1,+str.slice(8,10),0,0,0):/^\d{8}$/.test(str)?(str+="",new Date(+str.slice(0,4),+str.slice(4,6)-1,+str.slice(6,8),0,0,0)):/^\d{14}$/.test(str)?(str+="",new Date(+str.slice(0,4),+str.slice(4,6)-1,+str.slice(6,8),+str.slice(8,10),+str.slice(10,12),+str.slice(12,14))):/^\d{13}$/.test(str)?new Date(Number(str)):/^\d{10}$/.test(str)?new Date(1e3*Number(str)):new Date(str)}catch(error){throw new Error("Invalid date string")}},DateTime.diff=function(date1,date2,type){void 0===type&&(type="second");var d1=DateTime.toDate(date1),d2=DateTime.toDate(date2);return"second"===type?Math.floor((d1.getTime()-d2.getTime())/1e3):"minute"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60):"hour"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60/60):"day"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60/60/24):Math.abs(d1.getTime()-d2.getTime())},DateTime}();exports.DateTime=DateTime,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.isRealMobile=function(agent){var _navigator,ua=(null!=agent?agent:null==(_navigator=navigator)?void 0:_navigator.userAgent).toLowerCase();if(/ipad|tablet|playbook|silk|android(?!.*mobile)/i.test(ua))return!1;var hasTouch="ontouchstart"in window||navigator.maxTouchPoints>0;return/android|webos|iphone|ipod|blackberry|iemobile|opera mini/i.test(ua)&&hasTouch},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}}));
|
|
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";function isHttp(url){return/^http[s]?:\/\//.test(url)}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}if(isHttp(url))try{var u=new URL(url),file=u.pathname.split("/").pop();if(file){var m=file.match(/^([^_]+)_(\d+)_(\d+)\./);if(m){var deviceSerial=m[1],channelNo=m[2],quality=m[3];return obj.deviceSerial=deviceSerial,obj.channelNo=channelNo,u.searchParams.get("code")&&(obj.validateCode=u.searchParams.get("code")),obj.search=url.split("?")[1]?"?"+url.split("?")[1]:"",obj.protocol=url.split("//")[0],obj.hostname=url.split("/")[2],obj.origin=obj.protocol+"//"+obj.hostname,obj.pathname=url.split("?")[0].replace(obj.origin,""),obj.href=url,obj.type="live",(url.includes("rec=local")||url.includes("rec=cloud"))&&(obj.type="rec",url.includes("rec=cloud")?obj.recType="cloud":obj.recType=""),"live"===obj.type&&(obj.definition="1"===quality?"hd":"sd"),obj.searchParams=getQuery(url),obj}}}catch(e){}return{}}var codec={h264:1,h265:2,h266:4,vp8:8,vp9:16,av1:32},getQueryVC=function(CODECS){return CODECS.reduce((function(acc,key){return key=key.toLowerCase(),acc+(codec[key]||0)}),0)};function _array_like_to_array(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _instanceof(left,right){return null!=right&&"undefined"!=typeof Symbol&&right[Symbol.hasInstance]?!!right[Symbol.hasInstance](left):left instanceof right}function _create_for_of_iterator_helper_loose(o,allowArrayLike){var it="undefined"!=typeof Symbol&&o[Symbol.iterator]||o["@@iterator"];if(it)return(it=it.call(o)).next.bind(it);if(Array.isArray(o)||(it=function(o,minLen){if(o){if("string"==typeof o)return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_array_like_to_array(o,minLen):void 0}}(o))||allowArrayLike){it&&(o=it);var i=0;return function(){return i>=o.length?{done:!0}:{done:!1,value:o[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var DateTime=function(){function DateTime(){}return DateTime.normalizeUnit=function(unit){return"year"===unit||"y"===unit||"年"===unit?"year":"month"===unit||"M"===unit||"月"===unit?"month":"day"===unit||"d"===unit||"日"===unit?"day":"hour"===unit||"h"===unit||"时"===unit?"hour":"minute"===unit||"m"===unit||"分"===unit?"minute":"second"},DateTime.daysInMonth=function(year,month){return new Date(year,month+1,0).getDate()},DateTime.shiftMonth=function(baseDate,months){var result=new Date(baseDate.getTime()),currentDate=result.getDate();result.setDate(1),result.setMonth(result.getMonth()+months);var maxDate=DateTime.daysInMonth(result.getFullYear(),result.getMonth());return result.setDate(Math.min(currentDate,maxDate)),result},DateTime.add=function(input,value,unit){if(void 0===unit&&(unit="day"),!Number.isFinite(value))throw new Error("Invalid value");var baseDate=DateTime.toDate(input),normalizedUnit=DateTime.normalizeUnit(unit);if("year"===normalizedUnit)return DateTime.shiftMonth(baseDate,12*value);if("month"===normalizedUnit)return DateTime.shiftMonth(baseDate,value);var result=new Date(baseDate.getTime());return result.setTime(result.getTime()+value*{day:864e5,hour:36e5,minute:6e4,second:1e3}[normalizedUnit]),result},DateTime.subtract=function(input,value,unit){return void 0===unit&&(unit="day"),DateTime.add(input,-value,unit)},DateTime.fillZero=function(num,len){return void 0===len&&(len=2),num.toString().padStart(len,"0")},DateTime.format=function(input,format){var date;if(_instanceof(input,Date))date=input;else{if("number"!=typeof input&&"string"!=typeof input)throw new Error("Invalid date input");date=DateTime.toDate(input+"")}for(var _step,result=format,_iterator=_create_for_of_iterator_helper_loose([[/(yyyy|YYYY)/g,function(){return DateTime.fillZero(date.getFullYear(),4)}],[/(yy|YY)/g,function(){return DateTime.fillZero(date.getFullYear()%100,2)}],[/(MM)/g,function(){return DateTime.fillZero(date.getMonth()+1,2)}],[/(M)/g,function(){return(date.getMonth()+1).toString()}],[/(dd|DD)/g,function(){return DateTime.fillZero(date.getDate(),2)}],[/(d|D)/g,function(){return date.getDate().toString()}],[/(HH|hh)/g,function(){return DateTime.fillZero(date.getHours(),2)}],[/(H|h)/g,function(){return date.getHours().toString()}],[/(mm)/g,function(){return DateTime.fillZero(date.getMinutes(),2)}],[/(m)/g,function(){return date.getMinutes().toString()}],[/(ss|SS)/g,function(){return DateTime.fillZero(date.getSeconds(),2)}],[/(s|S)/g,function(){return date.getSeconds().toString()}],[/(fff)/g,function(){return DateTime.fillZero(date.getMilliseconds(),3)}]]);!(_step=_iterator()).done;){var _step_value=_step.value,regexp=_step_value[0],fn=_step_value[1];result=result.replace(regexp,fn)}return result},DateTime.toDate=function(str){if(_instanceof(str,Date))return str;str=(str+"").trim().replace(/\/|\./gi,"-"),/^\d{4}$/.test(str)&&(str+="-01"),/^\d{4}-\d{2}$/.test(str)&&(str+="-01");try{return/^\d{4}-\d{2}-\d{2}$/.test(str)?new Date(+str.slice(0,4),+str.slice(5,7)-1,+str.slice(8,10),0,0,0):/^\d{8}$/.test(str)?(str+="",new Date(+str.slice(0,4),+str.slice(4,6)-1,+str.slice(6,8),0,0,0)):/^\d{14}$/.test(str)?(str+="",new Date(+str.slice(0,4),+str.slice(4,6)-1,+str.slice(6,8),+str.slice(8,10),+str.slice(10,12),+str.slice(12,14))):/^\d{13}$/.test(str)?new Date(Number(str)):/^\d{10}$/.test(str)?new Date(1e3*Number(str)):new Date(str)}catch(error){throw new Error("Invalid date string")}},DateTime.diff=function(date1,date2,type){void 0===type&&(type="second");var d1=DateTime.toDate(date1),d2=DateTime.toDate(date2);return"second"===type?Math.floor((d1.getTime()-d2.getTime())/1e3):"minute"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60):"hour"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60/60):"day"===type?Math.floor((d1.getTime()-d2.getTime())/1e3/60/60/24):Math.abs(d1.getTime()-d2.getTime())},DateTime}();exports.DateTime=DateTime,exports.addVc=function(url,codecs){void 0===codecs&&(codecs=["h264"]);var vc=getQueryVC(codecs||["h264"]),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.getQueryVC=getQueryVC,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.isEmpty=function(param){return void 0===param||""===param||null===param},exports.isHttp=isHttp,exports.isMobile=function(agent){var _navigator,_navigator1,_navigator2,_window,_navigator_maxTouchPoints;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!=(_navigator_maxTouchPoints=null==(_navigator2=navigator)?void 0:_navigator2.maxTouchPoints)?_navigator_maxTouchPoints:0)>1||!!(null==(_window=window)?void 0:_window.__IS_MOBILE_SIMULATOR__)},exports.isRealMobile=function(agent){var _navigator,_ref,ua=(null!=(_ref=null!=agent?agent:null==(_navigator=navigator)?void 0:_navigator.userAgent)?_ref:"").toLowerCase();if(/ipad|tablet|playbook|silk|android(?!.*mobile)/i.test(ua))return!1;var hasTouch="ontouchstart"in window||navigator.maxTouchPoints>0;return/android|webos|iphone|ipod|blackberry|iemobile|opera mini/i.test(ua)&&hasTouch},exports.objectIsNull=function(obj){try{return"{}"===JSON.stringify(obj)}catch(error){return!1}},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/types/addVc.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 根据编码格式名称数组,计算 SDK 支持的视频编码位掩码(vc)值。
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* 每种编码对应一个二进制位:`h264=1`、`h265=2`、`h266=4`、`vp8=8`、`vp9=16`、`av1=32`。
|
|
6
|
+
* 多个编码通过按位求和组合,未知编码按 `0` 处理。编码名称大小写不敏感。
|
|
7
|
+
*
|
|
8
|
+
* @param CODECS - 编码格式名称数组,如 `['h264', 'h265']`
|
|
9
|
+
* @returns 组合后的 vc 数值
|
|
3
10
|
* @example
|
|
4
|
-
* ```
|
|
5
|
-
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* getQueryVC(['h264']); // 1
|
|
13
|
+
* getQueryVC(['h264', 'h265']); // 3
|
|
14
|
+
* getQueryVC(['H265']); // 2(大小写不敏感)
|
|
6
15
|
* ```
|
|
7
16
|
*/
|
|
8
17
|
export declare const getQueryVC: (CODECS: string[]) => number;
|
|
@@ -27,12 +27,19 @@ export interface EzopenURL {
|
|
|
27
27
|
definition?: EzopenDefinition;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* 解析ezopen 协议
|
|
31
|
-
* @param {string} url ezopen url
|
|
32
|
-
* @returns {EzopenURL}
|
|
30
|
+
* 解析 ezopen 协议 URL,提取设备序列号、通道号、播放类型等信息。
|
|
33
31
|
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* 支持形如 `ezopen://[验证码@]host/设备序列号/通道号.[清晰度|存储类型].类型?query` 的地址。
|
|
34
|
+
* 当传入的 URL 不是 ezopen 协议时,返回空对象 `{}`。
|
|
35
|
+
*
|
|
36
|
+
* @param url - ezopen 协议地址
|
|
37
|
+
* @returns 解析后的 {@link EzopenURL}(部分字段可选);非 ezopen 协议时返回空对象
|
|
38
|
+
* @example
|
|
34
39
|
* ```ts
|
|
35
|
-
* parseEzopenUrl(
|
|
40
|
+
* parseEzopenUrl(
|
|
41
|
+
* 'ezopen://open.ys7.com/C116331000/1.cloud.rec?a=00000&b=23&c=%E4%BD%A0%E5%A5%BD%E5%95%8A',
|
|
42
|
+
* );
|
|
36
43
|
* ```
|
|
37
44
|
*/
|
|
38
45
|
export declare function parseEzopenUrl(url: string): Partial<EzopenURL>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { isMobile, isRealMobile } from './isMobile';
|
|
|
4
4
|
import { getQuery } from './query';
|
|
5
5
|
import { pick } from './pick';
|
|
6
6
|
import { getStaticPath } from './getStaticPath';
|
|
7
|
-
import { addVc } from './addVc';
|
|
8
|
-
import
|
|
9
|
-
|
|
7
|
+
import { addVc, getQueryVC } from './addVc';
|
|
8
|
+
import { isEmpty, objectIsNull } from './null';
|
|
9
|
+
import DateTime, { type DateLike, type DateUnit } from './datetime';
|
|
10
|
+
export { parseEzopenUrl, switchEzopenUrl, type EzopenURL, type SwitchEzpoenOptions, type EzopenType, type EzopenRecType, type EzopenDefinition, type DateLike, type DateUnit, isHttp, isMobile, isRealMobile, getQuery, pick, getStaticPath, addVc, getQueryVC, isEmpty, objectIsNull, DateTime, };
|
package/dist/types/isHttp.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
2
|
+
* 判断给定的 URL 是否以 `http://` 或 `https://` 开头。
|
|
3
|
+
*
|
|
4
|
+
* @param url - 待判断的 URL 字符串
|
|
5
|
+
* @returns 当 URL 以 `http://` 或 `https://` 开头时返回 `true`,否则返回 `false`
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* isHttp('https://open.ys7.com'); // true
|
|
9
|
+
* isHttp('http://open.ys7.com'); // true
|
|
10
|
+
* isHttp('//open.ys7.com'); // false
|
|
11
|
+
* isHttp('ezopen://open.ys7.com'); // false
|
|
12
|
+
* ```
|
|
5
13
|
*/
|
|
6
14
|
export declare function isHttp(url: string): boolean;
|
package/dist/types/isMobile.d.ts
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 判断是否为移动端(包含 iPad 等平板设备)。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* - 不直接使用 `window`,以兼容在 Worker 环境中调用。
|
|
6
|
+
* - 通过 `navigator.maxTouchPoints` 识别使用桌面 UA 的 iPad。
|
|
7
|
+
* - 全局变量 `__IS_MOBILE_SIMULATOR__` 用于在 PC 端模拟移动端时强制判定为移动端。
|
|
5
8
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @returns
|
|
9
|
+
* @param agent - 可选的 User-Agent 字符串,默认取 `navigator.userAgent`
|
|
10
|
+
* @returns 判定为移动端时返回 `true`,否则返回 `false`
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* isMobile(); // 依据当前环境判断
|
|
14
|
+
* isMobile('Mozilla/5.0 (iPhone; ...)'); // true
|
|
15
|
+
* ```
|
|
8
16
|
*/
|
|
9
17
|
export declare function isMobile(agent?: string): boolean;
|
|
10
18
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
19
|
+
* 判断是否为真正的手机移动端(不包含 iPad 等平板设备)。
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* 先通过 UA 排除平板(iPad、tablet、playbook、silk、非 mobile 的 android),
|
|
23
|
+
* 再结合移动设备 UA 特征与触摸支持共同判定。
|
|
24
|
+
*
|
|
25
|
+
* @param agent - 可选的 User-Agent 字符串,默认取 `navigator.userAgent`
|
|
26
|
+
* @returns 判定为手机端时返回 `true`,否则返回 `false`
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* isRealMobile('Mozilla/5.0 (iPhone; ...)'); // true
|
|
30
|
+
* isRealMobile('Mozilla/5.0 (iPad; ...)'); // false
|
|
31
|
+
* ```
|
|
13
32
|
*/
|
|
14
33
|
export declare const isRealMobile: (agent?: string) => boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断值是否为空,即 `undefined`、空字符串 `''` 或 `null`。
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* 仅判断上述三种情况,不会将 `0`、`false`、`NaN` 视为空。
|
|
6
|
+
*
|
|
7
|
+
* @param param - 待判断的值
|
|
8
|
+
* @returns 当值为 `undefined`、`''` 或 `null` 时返回 `true`,否则返回 `false`
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* isEmpty(undefined); // true
|
|
12
|
+
* isEmpty(''); // true
|
|
13
|
+
* isEmpty(null); // true
|
|
14
|
+
* isEmpty(0); // false
|
|
15
|
+
* isEmpty('a'); // false
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function isEmpty(param: unknown): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 判断对象是否为空对象(不含任何自有可枚举属性)。
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* 内部通过 `JSON.stringify(obj) === '{}'` 判断,因此不可序列化的入参会被捕获异常并返回 `false`。
|
|
24
|
+
*
|
|
25
|
+
* @param obj - 待判断的对象
|
|
26
|
+
* @returns 当对象为 `{}` 时返回 `true`,否则返回 `false`
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* objectIsNull({}); // true
|
|
30
|
+
* objectIsNull({ a: 1 }); // false
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function objectIsNull(obj: object): boolean;
|
package/dist/types/pick.d.ts
CHANGED
package/dist/types/query.d.ts
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 解析 URL 中的查询字符串(query string),返回键值对对象。
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* - 值会经过 {@link decodeURIComponent} 解码。
|
|
6
|
+
* - 暂不支持数组形式的参数(如 `a=1&a=2`,后者会覆盖前者)。
|
|
7
|
+
* - 当 URL 不含 `?` 或查询字符串为空时,返回空对象。
|
|
8
|
+
*
|
|
9
|
+
* @param url - 完整或带查询字符串的 URL
|
|
10
|
+
* @returns 查询参数键值对对象
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* getQuery('https://open.ys7.com/help?a=1&b=2&c=3'); // { a: '1', b: '2', c: '3' }
|
|
14
|
+
* getQuery('https://open.ys7.com/help'); // {}
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
1
17
|
export declare const getQuery: (url: string) => Record<string, string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezuikit/utils-tools",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "tools utils",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"umd": "dist/index.umd.js",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"keywords": [
|
|
12
12
|
"ezuikit",
|
|
13
13
|
"ezuikit-utils",
|
|
14
|
-
"utils"
|
|
14
|
+
"utils",
|
|
15
|
+
"ezviz"
|
|
15
16
|
],
|
|
16
17
|
"author": "Ezviz-OpenBiz",
|
|
17
18
|
"license": "MIT",
|