@ezuikit/utils-tools 1.0.4 → 1.1.0-alpha.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 +3 -3
- package/dist/index.mjs +8 -0
- package/dist/index.umd.js +3 -3
- package/dist/types/ezopenUrl.d.ts +3 -9
- package/dist/types/pick.d.ts +3 -3
- package/package.json +3 -4
- package/dist/index.esm.js +0 -8
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
2
|
*
|
|
3
|
-
* @ezuikit/utils-tools v1.0.
|
|
4
|
-
* Copyright (c)
|
|
3
|
+
* @ezuikit/utils-tools v1.1.0-alpha.1
|
|
4
|
+
* Copyright (c) 2025-6-11 Ezviz-OpenBiz
|
|
5
5
|
* Released under MIT the License.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
"use strict";
|
|
8
|
+
"use strict";const e=e=>{const t=e.split("?")[1],n={};if(t){const e=t.split("&");for(let t=0;t<e.length;t++){const r=e[t].split("=");n[r[0]]=decodeURIComponent(r[1])}}return n};function t(t){const n={};if(/^ezopen:\/\//.test(t)){if(t.includes("@")){const e=t.indexOf("@"),r=t.indexOf("//");n.validateCode=t.substring(r+2,e),t=t.replace(n.validateCode+"@","")}n.protocol=t.split("//")[0],n.search=t.split("?")[1]?"?"+t.split("?")[1]:"",n.hostname=t.split("/")[2],n.origin=n.protocol+"//"+n.hostname,n.pathname=t.split("?")[0].replace(n.origin,""),n.href=t;const r=n.pathname.split("/"),o=r[2].split(".");return n.deviceSerial=r[1],n.channelNo=o[0],n.type=o[o.length-1],"live"===n.type&&(n.definition=o.length>2?o[1]:"sd"),"rec"===n.type&&(n.recType=o.length>2?o[1]:""),n.searchParams=e(t),n}return{}}const n={h264:1,h265:2,h266:4,vp8:8,vp9:16,av1:32};exports.addVc=function(e,t=["h264"]){const r=(t||["h264"]).reduce(((e,t)=>(t=t.toLowerCase(),e+(n[t]||0))),0),o=e.split("?")[0];let i=e.split("?")[1];return i=(i||"").split("&").filter((e=>!/^vc=\d?/.test(e))).join("&"),i+=`${i?"&":""}vc=${r}`,o+"?"+i},exports.getQuery=e,exports.getStaticPath=function(e,t=""){const n=/^(https?:\/\/|^\/\/)/;if(""===e||void 0===e)return"";if(n.test(e))return e;e=e.replace(/\/+/g,"/"),t=n.test(t||"")?t:window.location.href;try{return new URL(e,t).href}catch(t){return e}},exports.isHttp=function(e){return/^http[s]?:\/\//.test(e)},exports.isMobile=function(e){var t,n;return!!((null!=e?e:null==(n=window)||null==(t=n.navigator)?void 0:t.userAgent)||"").match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)},exports.parseEzopenUrl=t,exports.pick=function(e,t){return Object.entries(e).reduce(((e,[n,r])=>(t.includes(n)&&(e[n]=r),e)),{})},exports.switchEzopenUrl=function(n,r){let{type:o,recType:i,search:s,definition:c,channelNo:l,deviceSerial:p,validateCode:a}=null!=r?r:{};const d=t(n);if(s){const t=Object.assign({},d.searchParams,e("?"+s.replace("?","")));s=Object.entries(t).reduce(((e,[t,n])=>""===n?e:e+=`${t}=${encodeURIComponent(n)}&`),"?").replace(/&$/,"")}else s=d.search;return o=o||d.type,i=null!=i?i:d.recType,c=null!=c?c:d.definition,l=l||d.channelNo,p=p||d.deviceSerial,a=null!=a?a:d.validateCode,`${d.protocol}//${a?`${a}@`:""}${d.hostname}/${p}/${l}${"rec"===o&&i?"."+i:""}${"live"===o&&"hd"===c?"."+c:""}.${o}${s}`};
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* @ezuikit/utils-tools v1.1.0-alpha.1
|
|
4
|
+
* Copyright (c) 2025-6-11 Ezviz-OpenBiz
|
|
5
|
+
* Released under MIT the License.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
const e=e=>{const t=e.split("?")[1],n={};if(t){const e=t.split("&");for(let t=0;t<e.length;t++){const i=e[t].split("=");n[i[0]]=decodeURIComponent(i[1])}}return n};function t(t){const n={};if(/^ezopen:\/\//.test(t)){if(t.includes("@")){const e=t.indexOf("@"),i=t.indexOf("//");n.validateCode=t.substring(i+2,e),t=t.replace(n.validateCode+"@","")}n.protocol=t.split("//")[0],n.search=t.split("?")[1]?"?"+t.split("?")[1]:"",n.hostname=t.split("/")[2],n.origin=n.protocol+"//"+n.hostname,n.pathname=t.split("?")[0].replace(n.origin,""),n.href=t;const i=n.pathname.split("/"),o=i[2].split(".");return n.deviceSerial=i[1],n.channelNo=o[0],n.type=o[o.length-1],"live"===n.type&&(n.definition=o.length>2?o[1]:"sd"),"rec"===n.type&&(n.recType=o.length>2?o[1]:""),n.searchParams=e(t),n}return{}}function n(n,i){let{type:o,recType:r,search:c,definition:l,channelNo:s,deviceSerial:a,validateCode:p}=null!=i?i:{};const d=t(n);if(c){const t=Object.assign({},d.searchParams,e("?"+c.replace("?","")));c=Object.entries(t).reduce(((e,[t,n])=>""===n?e:e+=`${t}=${encodeURIComponent(n)}&`),"?").replace(/&$/,"")}else c=d.search;return o=o||d.type,r=null!=r?r:d.recType,l=null!=l?l:d.definition,s=s||d.channelNo,a=a||d.deviceSerial,p=null!=p?p:d.validateCode,`${d.protocol}//${p?`${p}@`:""}${d.hostname}/${a}/${s}${"rec"===o&&r?"."+r:""}${"live"===o&&"hd"===l?"."+l:""}.${o}${c}`}function i(e){return/^http[s]?:\/\//.test(e)}function o(e){var t,n;return!!((null!=e?e:null==(n=window)||null==(t=n.navigator)?void 0:t.userAgent)||"").match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)}function r(e,t){return Object.entries(e).reduce(((e,[n,i])=>(t.includes(n)&&(e[n]=i),e)),{})}function c(e,t=""){const n=/^(https?:\/\/|^\/\/)/;if(""===e||void 0===e)return"";if(n.test(e))return e;e=e.replace(/\/+/g,"/"),t=n.test(t||"")?t:window.location.href;try{return new URL(e,t).href}catch(t){return e}}const l={h264:1,h265:2,h266:4,vp8:8,vp9:16,av1:32};function s(e,t=["h264"]){const n=(t||["h264"]).reduce(((e,t)=>(t=t.toLowerCase(),e+(l[t]||0))),0);const i=e.split("?")[0];let o=e.split("?")[1];return o=(o||"").split("&").filter((e=>!/^vc=\d?/.test(e))).join("&"),o+=`${o?"&":""}vc=${n}`,i+"?"+o}export{s as addVc,e as getQuery,c as getStaticPath,i as isHttp,o as isMobile,t as parseEzopenUrl,r as pick,n as switchEzopenUrl};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
2
|
*
|
|
3
|
-
* @ezuikit/utils-tools v1.0.
|
|
4
|
-
* Copyright (c)
|
|
3
|
+
* @ezuikit/utils-tools v1.1.0-alpha.1
|
|
4
|
+
* Copyright (c) 2025-6-11 Ezviz-OpenBiz
|
|
5
5
|
* Released under MIT the License.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Tools={})}(this,(function(e){"use strict";
|
|
8
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Tools={})}(this,(function(e){"use strict";const t=e=>{const t=e.split("?")[1],n={};if(t){const e=t.split("&");for(let t=0;t<e.length;t++){const i=e[t].split("=");n[i[0]]=decodeURIComponent(i[1])}}return n};function n(e){const n={};if(/^ezopen:\/\//.test(e)){if(e.includes("@")){const t=e.indexOf("@"),i=e.indexOf("//");n.validateCode=e.substring(i+2,t),e=e.replace(n.validateCode+"@","")}n.protocol=e.split("//")[0],n.search=e.split("?")[1]?"?"+e.split("?")[1]:"",n.hostname=e.split("/")[2],n.origin=n.protocol+"//"+n.hostname,n.pathname=e.split("?")[0].replace(n.origin,""),n.href=e;const i=n.pathname.split("/"),o=i[2].split(".");return n.deviceSerial=i[1],n.channelNo=o[0],n.type=o[o.length-1],"live"===n.type&&(n.definition=o.length>2?o[1]:"sd"),"rec"===n.type&&(n.recType=o.length>2?o[1]:""),n.searchParams=t(e),n}return{}}const i={h264:1,h265:2,h266:4,vp8:8,vp9:16,av1:32};e.addVc=function(e,t=["h264"]){const n=(t||["h264"]).reduce(((e,t)=>(t=t.toLowerCase(),e+(i[t]||0))),0),o=e.split("?")[0];let r=e.split("?")[1];return r=(r||"").split("&").filter((e=>!/^vc=\d?/.test(e))).join("&"),r+=`${r?"&":""}vc=${n}`,o+"?"+r},e.getQuery=t,e.getStaticPath=function(e,t=""){const n=/^(https?:\/\/|^\/\/)/;if(""===e||void 0===e)return"";if(n.test(e))return e;e=e.replace(/\/+/g,"/"),t=n.test(t||"")?t:window.location.href;try{return new URL(e,t).href}catch(t){return e}},e.isHttp=function(e){return/^http[s]?:\/\//.test(e)},e.isMobile=function(e){var t,n;return!!((null!=e?e:null==(n=window)||null==(t=n.navigator)?void 0:t.userAgent)||"").match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)},e.parseEzopenUrl=n,e.pick=function(e,t){return Object.entries(e).reduce(((e,[n,i])=>(t.includes(n)&&(e[n]=i),e)),{})},e.switchEzopenUrl=function(e,i){let{type:o,recType:r,search:s,definition:l,channelNo:c,deviceSerial:a,validateCode:p}=null!=i?i:{};const d=n(e);if(s){const e=Object.assign({},d.searchParams,t("?"+s.replace("?","")));s=Object.entries(e).reduce(((e,[t,n])=>""===n?e:e+=`${t}=${encodeURIComponent(n)}&`),"?").replace(/&$/,"")}else s=d.search;return o=o||d.type,r=null!=r?r:d.recType,l=null!=l?l:d.definition,c=c||d.channelNo,a=a||d.deviceSerial,p=null!=p?p:d.validateCode,`${d.protocol}//${p?`${p}@`:""}${d.hostname}/${a}/${c}${"rec"===o&&r?"."+r:""}${"live"===o&&"hd"===l?"."+l:""}.${o}${s}`}}));
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
/** 播放类型 live/rec */
|
|
2
1
|
export type EzopenType = 'live' | 'rec' | string;
|
|
3
|
-
/** 现在仅支持 cloud */
|
|
4
2
|
export type EzopenRecType = 'cloud' | string;
|
|
5
|
-
/** 直播的清晰度 */
|
|
6
3
|
export type EzopenDefinition = 'sd' | 'hd' | string;
|
|
7
|
-
/** ezopen 协议地址 解析后的结果 */
|
|
8
4
|
export interface EzopenURL {
|
|
9
5
|
protocol: string;
|
|
10
6
|
search?: string;
|
|
11
|
-
searchParams?: Record<string,
|
|
7
|
+
searchParams?: Record<string, any>;
|
|
12
8
|
pathname: string;
|
|
13
9
|
origin: string;
|
|
14
10
|
href: string;
|
|
@@ -26,7 +22,7 @@ export interface EzopenURL {
|
|
|
26
22
|
/**
|
|
27
23
|
* @description 解析ezopen 协议 url
|
|
28
24
|
* @param {string} url ezopen url
|
|
29
|
-
* @returns {
|
|
25
|
+
* @returns {EzopenParams}
|
|
30
26
|
*
|
|
31
27
|
* ```ts
|
|
32
28
|
* parseEzopenUrl("ezopen://open.ys7.com/C116331000/1.cloud.rec?a=00000&b=23&c=%E4%BD%A0%E5%A5%BD%E5%95%8A")
|
|
@@ -37,9 +33,7 @@ export interface SwitchEzpoenOptions {
|
|
|
37
33
|
deviceSerial?: string;
|
|
38
34
|
channelNo?: string;
|
|
39
35
|
type?: EzopenType;
|
|
40
|
-
/** 仅 rec */
|
|
41
36
|
recType?: EzopenRecType;
|
|
42
|
-
/** 仅 live */
|
|
43
37
|
definition?: EzopenDefinition;
|
|
44
38
|
search?: string;
|
|
45
39
|
validateCode?: string;
|
|
@@ -48,7 +42,7 @@ export interface SwitchEzpoenOptions {
|
|
|
48
42
|
* @description exopen 协议播放地址切换(search 中值为空会覆盖url中的值并移除这个参数)
|
|
49
43
|
* @param {string} url exopen 协议播放地址
|
|
50
44
|
* @param {SwitchEzpoenOptions} options
|
|
51
|
-
* @returns
|
|
45
|
+
* @returns
|
|
52
46
|
*
|
|
53
47
|
* @example
|
|
54
48
|
* ```ts
|
package/dist/types/pick.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezuikit/utils-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-alpha.1",
|
|
4
4
|
"description": "tools utils",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"umd": "dist/index.umd.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
8
|
-
"module": "dist/index.
|
|
8
|
+
"module": "dist/index.mjs",
|
|
9
9
|
"exports": {
|
|
10
10
|
"types": "./dist/types/index.d.ts",
|
|
11
|
-
"import": "./dist/index.
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"keywords": [
|
|
30
|
-
"logger",
|
|
31
30
|
"ezuikit",
|
|
32
31
|
"ezuikit-utils",
|
|
33
32
|
"utils"
|
package/dist/index.esm.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
*
|
|
3
|
-
* @ezuikit/utils-tools v1.0.4
|
|
4
|
-
* Copyright (c) 2024-10-29 Ezviz-OpenBiz
|
|
5
|
-
* Released under MIT the License.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
var e=function(e){var n=e.split("?")[1],r={};if(n)for(var t=n.split("&"),i=0;i<t.length;i++){var o=t[i].split("=");r[o[0]]=decodeURIComponent(o[1])}return r};function n(n){var r={};if(/^ezopen:\/\//.test(n)){if(n.includes("@")){var t=n.indexOf("@"),i=n.indexOf("//");r.validateCode=n.substring(i+2,t),n=n.replace(r.validateCode+"@","")}r.protocol=n.split("//")[0],r.search=n.split("?")[1]?"?"+n.split("?")[1]:"",r.hostname=n.split("/")[2],r.origin=r.protocol+"//"+r.hostname,r.pathname=n.split("?")[0].replace(r.origin,""),r.href=n;var o=r.pathname.split("/"),a=o[2].split(".");return r.deviceSerial=o[1],r.channelNo=a[0],r.type=a[a.length-1],"live"===r.type&&(r.definition=a.length>2?a[1]:"sd"),"rec"===r.type&&o[2]&&(r.recType=o[2].includes(".cloud.")?"cloud":""),r.searchParams=e(n),r}return{}}function r(r,t){var i=null!=t?t:{},o=i.type,a=i.recType,l=i.search,c=i.definition,s=i.channelNo,u=i.deviceSerial,d=i.validateCode,p=n(r);if(l){var v=Object.assign({},p.searchParams,e("?"+l.replace("?","")));l=Object.entries(v).reduce((function(e,n){var r=n[0],t=n[1];return""===t?e:e+=r+"="+encodeURIComponent(t)+"&"}),"?").replace(/&$/,"")}else l=p.search;return o=o||p.type,a=null!=a?a:p.recType,c=null!=c?c:p.definition,s=s||p.channelNo,u=u||p.deviceSerial,d=null!=d?d:p.validateCode,p.protocol+"//"+(d?d+"@":"")+p.hostname+"/"+u+"/"+s+("rec"===o&&a?"."+a:"")+("live"===o&&"hd"===c?"."+c:"")+"."+o+l}function t(e){return/^http[s]?:\/\//.test(e)}function i(e){var n,r;return!!((null!=e?e:null==(r=window)||null==(n=r.navigator)?void 0:n.userAgent)||"").match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)}function o(e,n){return Object.entries(e).reduce((function(e,r){var t=r[0],i=r[1];return n.includes(t)&&(e[t]=i),e}),{})}function a(e,n){void 0===n&&(n="");var r=/^(https?:\/\/|^\/\/)/;if(""===e||void 0===e)return"";if(r.test(e))return e;e=e.replace(/\/+/g,"/"),n=r.test(n||"")?n:window.location.href;try{return new URL(e,n).href}catch(n){return e}}var l={h264:1,h265:2,h266:4,vp8:8,vp9:16,av1:32};function c(e,n){void 0===n&&(n=["h264"]);var r=(n||["h264"]).reduce((function(e,n){return n=n.toLowerCase(),e+(l[n]||0)}),0),t=e.split("?")[0],i=e.split("?")[1];return i=(i||"").split("&").filter((function(e){return!/^vc=\d?/.test(e)})).join("&"),t+"?"+(i+=(i?"&":"")+"vc="+r)}export{c as addVc,e as getQuery,a as getStaticPath,t as isHttp,i as isMobile,n as parseEzopenUrl,o as pick,r as switchEzopenUrl};
|