@ezuikit/utils-tools 2.0.0-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 +52 -41
- package/dist/index.mjs +53 -54
- package/dist/index.umd.js +52 -43
- package/dist/types/index.d.ts +12 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37,46 +37,57 @@ var codec = {
|
|
|
37
37
|
av1: 32
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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) {
|
|
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) {
|
|
74
66
|
var key = param[0], value = param[1];
|
|
75
|
-
return
|
|
76
|
-
},
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
}
|
|
82
91
|
};
|
|
92
|
+
|
|
93
|
+
module.exports = index;
|
package/dist/index.mjs
CHANGED
|
@@ -26,50 +26,6 @@ function parseEzopenUrl(url) {
|
|
|
26
26
|
return {};
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function switchEzopenUrl(url, options) {
|
|
30
|
-
var _ref = null != options ? options : {}, type = _ref.type, recType = _ref.recType, search = _ref.search, definition = _ref.definition, channelNo = _ref.channelNo, deviceSerial = _ref.deviceSerial, validateCode = _ref.validateCode, obj = parseEzopenUrl(url);
|
|
31
|
-
if (search) {
|
|
32
|
-
var ns = Object.assign({}, obj.searchParams, getQuery("?" + search.replace("?", "")));
|
|
33
|
-
search = Object.entries(ns).reduce(function(acc, param) {
|
|
34
|
-
var key = param[0], value = param[1];
|
|
35
|
-
return "" === value ? acc : acc += key + "=" + encodeURIComponent(value) + "&";
|
|
36
|
-
}, "?").replace(/&$/, "");
|
|
37
|
-
} else search = obj.search;
|
|
38
|
-
return type = type || obj.type, recType = null != recType ? recType : obj.recType,
|
|
39
|
-
definition = null != definition ? definition : obj.definition, channelNo = channelNo || obj.channelNo,
|
|
40
|
-
deviceSerial = deviceSerial || obj.deviceSerial, validateCode = null != validateCode ? validateCode : obj.validateCode,
|
|
41
|
-
obj.protocol + "//" + (validateCode ? validateCode + "@" : "") + obj.hostname + "/" + deviceSerial + "/" + channelNo + ("rec" === type && recType ? "." + recType : "") + ("live" === type && "hd" === definition ? "." + definition : "") + "." + type + search;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function isHttp(url) {
|
|
45
|
-
return /^http[s]?:\/\//.test(url);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function isMobile(agent) {
|
|
49
|
-
var _navigator, _navigator1, _navigator2, _window;
|
|
50
|
-
return /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone|Opera Mini)/i.test(null != agent ? agent : null == (_navigator = navigator) ? void 0 : _navigator.userAgent) || /Macintosh/i.test(null == (_navigator1 = navigator) ? void 0 : _navigator1.userAgent) && (null == (_navigator2 = navigator) ? void 0 : _navigator2.maxTouchPoints) > 1 || (null == (_window = window) ? void 0 : _window.__IS_MOBILE_SIMULATOR__);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function pick(obj, keys) {
|
|
54
|
-
return Object.entries(obj).reduce(function(acc, param) {
|
|
55
|
-
var key = param[0], value = param[1];
|
|
56
|
-
return keys.includes(key) && (acc[key] = value), acc;
|
|
57
|
-
}, {});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function getStaticPath(path, base) {
|
|
61
|
-
void 0 === base && (base = "");
|
|
62
|
-
var protocolReg = /^(https?:\/\/|^\/\/)/;
|
|
63
|
-
if ("" === path || void 0 === path) return "";
|
|
64
|
-
if (protocolReg.test(path)) return path;
|
|
65
|
-
path = path.replace(/\/+/g, "/"), base = protocolReg.test(base || "") ? base : window.location.href;
|
|
66
|
-
try {
|
|
67
|
-
return new URL(path, base).href;
|
|
68
|
-
} catch (error) {
|
|
69
|
-
return path;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
29
|
var codec = {
|
|
74
30
|
h264: 1,
|
|
75
31
|
h265: 2,
|
|
@@ -79,14 +35,57 @@ var codec = {
|
|
|
79
35
|
av1: 32
|
|
80
36
|
};
|
|
81
37
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
+
};
|
|
91
90
|
|
|
92
|
-
export {
|
|
91
|
+
export { index as default };
|
package/dist/index.umd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
!function(global, factory) {
|
|
2
|
-
"object" == typeof exports && "undefined" != typeof module ? factory(
|
|
3
|
-
}(this, function(
|
|
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
4
|
"use strict";
|
|
5
5
|
var getQuery = function(url) {
|
|
6
6
|
var query = url.split("?")[1], obj = {};
|
|
@@ -36,47 +36,56 @@
|
|
|
36
36
|
vp9: 16,
|
|
37
37
|
av1: 32
|
|
38
38
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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) {
|
|
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) {
|
|
73
65
|
var key = param[0], value = param[1];
|
|
74
|
-
return
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
+
}
|
|
81
90
|
};
|
|
82
91
|
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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 {
|
|
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;
|