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

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
@@ -28,7 +28,7 @@ function parseEzopenUrl(url) {
28
28
  return {};
29
29
  }
30
30
 
31
- var codec = {
31
+ var __$codec$__ = {
32
32
  h264: 1,
33
33
  h265: 2,
34
34
  h266: 4,
@@ -37,57 +37,46 @@ var codec = {
37
37
  av1: 32
38
38
  };
39
39
 
40
- var index = {
41
- parseEzopenUrl: parseEzopenUrl,
42
- switchEzopenUrl: function(url, options) {
43
- var _ref = null != options ? options : {}, type = _ref.type, recType = _ref.recType, search = _ref.search, definition = _ref.definition, channelNo = _ref.channelNo, deviceSerial = _ref.deviceSerial, validateCode = _ref.validateCode, obj = parseEzopenUrl(url);
44
- if (search) {
45
- var ns = Object.assign({}, obj.searchParams, getQuery("?" + search.replace("?", "")));
46
- search = Object.entries(ns).reduce(function(acc, param) {
47
- var key = param[0], value = param[1];
48
- return "" === value ? acc : acc += key + "=" + encodeURIComponent(value) + "&";
49
- }, "?").replace(/&$/, "");
50
- } else search = obj.search;
51
- return type = type || obj.type, recType = null != recType ? recType : obj.recType,
52
- definition = null != definition ? definition : obj.definition, channelNo = channelNo || obj.channelNo,
53
- deviceSerial = deviceSerial || obj.deviceSerial, validateCode = null != validateCode ? validateCode : obj.validateCode,
54
- obj.protocol + "//" + (validateCode ? validateCode + "@" : "") + obj.hostname + "/" + deviceSerial + "/" + channelNo + ("rec" === type && recType ? "." + recType : "") + ("live" === type && "hd" === definition ? "." + definition : "") + "." + type + search;
55
- },
56
- isHttp: function(url) {
57
- return /^http[s]?:\/\//.test(url);
58
- },
59
- isMobile: function(agent) {
60
- var _navigator, _navigator1, _navigator2, _window;
61
- return /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone|Opera Mini)/i.test(null != agent ? agent : null == (_navigator = navigator) ? void 0 : _navigator.userAgent) || /Macintosh/i.test(null == (_navigator1 = navigator) ? void 0 : _navigator1.userAgent) && (null == (_navigator2 = navigator) ? void 0 : _navigator2.maxTouchPoints) > 1 || (null == (_window = window) ? void 0 : _window.__IS_MOBILE_SIMULATOR__);
62
- },
63
- getQuery: getQuery,
64
- pick: function(obj, keys) {
65
- return Object.entries(obj).reduce(function(acc, param) {
66
- var key = param[0], value = param[1];
67
- return keys.includes(key) && (acc[key] = value), acc;
68
- }, {});
69
- },
70
- getStaticPath: function(path, base) {
71
- void 0 === base && (base = "");
72
- var protocolReg = /^(https?:\/\/|^\/\/)/;
73
- if ("" === path || void 0 === path) return "";
74
- if (protocolReg.test(path)) return path;
75
- path = path.replace(/\/+/g, "/"), base = protocolReg.test(base || "") ? base : window.location.href;
76
- try {
77
- return new URL(path, base).href;
78
- } catch (error) {
79
- return path;
80
- }
81
- },
82
- addVc: function(url, codecs) {
83
- void 0 === codecs && (codecs = [ "h264" ]);
84
- var vc = (codecs || [ "h264" ]).reduce(function(acc, key) {
85
- return key = key.toLowerCase(), acc + (codec[key] || 0);
86
- }, 0), host = url.split("?")[0], query = url.split("?")[1];
87
- return query = (query || "").split("&").filter(function(item) {
88
- return !/^vc=\d?/.test(item);
89
- }).join("&"), host + "?" + (query += (query ? "&" : "") + "vc=" + vc);
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;
90
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;
91
82
  };
92
-
93
- module.exports = index;
package/dist/index.umd.js CHANGED
@@ -1,6 +1,6 @@
1
1
  !function(global, factory) {
2
- "object" == typeof exports && "undefined" != typeof module ? module.exports = factory() : "function" == typeof define && define.amd ? define(factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self).Tools = factory();
3
- }(this, function() {
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
4
  "use strict";
5
5
  var getQuery = function(url) {
6
6
  var query = url.split("?")[1], obj = {};
@@ -28,7 +28,7 @@
28
28
  }
29
29
  return {};
30
30
  }
31
- var codec = {
31
+ var __$codec$__ = {
32
32
  h264: 1,
33
33
  h265: 2,
34
34
  h266: 4,
@@ -36,56 +36,47 @@
36
36
  vp9: 16,
37
37
  av1: 32
38
38
  };
39
- return {
40
- parseEzopenUrl: parseEzopenUrl,
41
- switchEzopenUrl: function(url, options) {
42
- var _ref = null != options ? options : {}, type = _ref.type, recType = _ref.recType, search = _ref.search, definition = _ref.definition, channelNo = _ref.channelNo, deviceSerial = _ref.deviceSerial, validateCode = _ref.validateCode, obj = parseEzopenUrl(url);
43
- if (search) {
44
- var ns = Object.assign({}, obj.searchParams, getQuery("?" + search.replace("?", "")));
45
- search = Object.entries(ns).reduce(function(acc, param) {
46
- var key = param[0], value = param[1];
47
- return "" === value ? acc : acc += key + "=" + encodeURIComponent(value) + "&";
48
- }, "?").replace(/&$/, "");
49
- } else search = obj.search;
50
- return type = type || obj.type, recType = null != recType ? recType : obj.recType,
51
- definition = null != definition ? definition : obj.definition, channelNo = channelNo || obj.channelNo,
52
- deviceSerial = deviceSerial || obj.deviceSerial, validateCode = null != validateCode ? validateCode : obj.validateCode,
53
- obj.protocol + "//" + (validateCode ? validateCode + "@" : "") + obj.hostname + "/" + deviceSerial + "/" + channelNo + ("rec" === type && recType ? "." + recType : "") + ("live" === type && "hd" === definition ? "." + definition : "") + "." + type + search;
54
- },
55
- isHttp: function(url) {
56
- return /^http[s]?:\/\//.test(url);
57
- },
58
- isMobile: function(agent) {
59
- var _navigator, _navigator1, _navigator2, _window;
60
- return /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone|Opera Mini)/i.test(null != agent ? agent : null == (_navigator = navigator) ? void 0 : _navigator.userAgent) || /Macintosh/i.test(null == (_navigator1 = navigator) ? void 0 : _navigator1.userAgent) && (null == (_navigator2 = navigator) ? void 0 : _navigator2.maxTouchPoints) > 1 || (null == (_window = window) ? void 0 : _window.__IS_MOBILE_SIMULATOR__);
61
- },
62
- getQuery: getQuery,
63
- pick: function(obj, keys) {
64
- return Object.entries(obj).reduce(function(acc, param) {
65
- var key = param[0], value = param[1];
66
- return keys.includes(key) && (acc[key] = value), acc;
67
- }, {});
68
- },
69
- getStaticPath: function(path, base) {
70
- void 0 === base && (base = "");
71
- var protocolReg = /^(https?:\/\/|^\/\/)/;
72
- if ("" === path || void 0 === path) return "";
73
- if (protocolReg.test(path)) return path;
74
- path = path.replace(/\/+/g, "/"), base = protocolReg.test(base || "") ? base : window.location.href;
75
- try {
76
- return new URL(path, base).href;
77
- } catch (error) {
78
- return path;
79
- }
80
- },
81
- addVc: function(url, codecs) {
82
- void 0 === codecs && (codecs = [ "h264" ]);
83
- var vc = (codecs || [ "h264" ]).reduce(function(acc, key) {
84
- return key = key.toLowerCase(), acc + (codec[key] || 0);
85
- }, 0), host = url.split("?")[0], query = url.split("?")[1];
86
- return query = (query || "").split("&").filter(function(item) {
87
- return !/^vc=\d?/.test(item);
88
- }).join("&"), host + "?" + (query += (query ? "&" : "") + "vc=" + vc);
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;
89
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;
90
81
  };
91
82
  });
@@ -1,18 +1,9 @@
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';
4
5
  import { pick } from './pick';
5
6
  import { getStaticPath } from './getStaticPath';
6
7
  import { addVc } from './addVc';
7
8
  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;
9
+ export { parseEzopenUrl, switchEzopenUrl, isHttp, isMobile, getQuery, pick, getStaticPath, addVc };
package/package.json CHANGED
@@ -1,16 +1,10 @@
1
1
  {
2
2
  "name": "@ezuikit/utils-tools",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0",
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.mjs",
9
- "exports": {
10
- "types": "./dist/types/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "default": "./dist/index.js"
13
- },
14
8
  "scripts": {
15
9
  "dev": "cross-env NODE_ENV=development rollup --config rollup.config.mjs --watch",
16
10
  "build": "npm run clean && cross-env NODE_ENV=production rollup --config rollup.config.mjs && npm run types && npm run docs",
@@ -1 +0,0 @@
1
- No third parties dependencies
package/dist/index.mjs DELETED
@@ -1,91 +0,0 @@
1
- var getQuery = function(url) {
2
- var query = url.split("?")[1], obj = {};
3
- if (query) for (var vars = query.split("&"), i = 0; i < vars.length; i++) {
4
- var pair = vars[i].split("=");
5
- obj[pair[0]] = decodeURIComponent(pair[1]);
6
- }
7
- return obj;
8
- };
9
-
10
- function parseEzopenUrl(url) {
11
- var obj = {};
12
- if (/^ezopen:\/\//.test(url)) {
13
- if (url.includes("@")) {
14
- var endIndex = url.indexOf("@"), startIndex = url.indexOf("//");
15
- obj.validateCode = url.substring(startIndex + 2, endIndex), url = url.replace(obj.validateCode + "@", "");
16
- }
17
- obj.protocol = url.split("//")[0], obj.search = url.split("?")[1] ? "?" + url.split("?")[1] : "",
18
- obj.hostname = url.split("/")[2], obj.origin = obj.protocol + "//" + obj.hostname,
19
- obj.pathname = url.split("?")[0].replace(obj.origin, ""), obj.href = url;
20
- var pathnames = obj.pathname.split("/"), lastPath = pathnames[2].split(".");
21
- return obj.deviceSerial = pathnames[1], obj.channelNo = lastPath[0], obj.type = lastPath[lastPath.length - 1],
22
- "live" === obj.type && (obj.definition = lastPath.length > 2 ? lastPath[1] : "sd"),
23
- "rec" === obj.type && pathnames[2] && (obj.recType = pathnames[2].includes(".cloud.") ? "cloud" : ""),
24
- obj.searchParams = getQuery(url), obj;
25
- }
26
- return {};
27
- }
28
-
29
- var codec = {
30
- h264: 1,
31
- h265: 2,
32
- h266: 4,
33
- vp8: 8,
34
- vp9: 16,
35
- av1: 32
36
- };
37
-
38
- var index = {
39
- parseEzopenUrl: parseEzopenUrl,
40
- switchEzopenUrl: function(url, options) {
41
- var _ref = null != options ? options : {}, type = _ref.type, recType = _ref.recType, search = _ref.search, definition = _ref.definition, channelNo = _ref.channelNo, deviceSerial = _ref.deviceSerial, validateCode = _ref.validateCode, obj = parseEzopenUrl(url);
42
- if (search) {
43
- var ns = Object.assign({}, obj.searchParams, getQuery("?" + search.replace("?", "")));
44
- search = Object.entries(ns).reduce(function(acc, param) {
45
- var key = param[0], value = param[1];
46
- return "" === value ? acc : acc += key + "=" + encodeURIComponent(value) + "&";
47
- }, "?").replace(/&$/, "");
48
- } else search = obj.search;
49
- return type = type || obj.type, recType = null != recType ? recType : obj.recType,
50
- definition = null != definition ? definition : obj.definition, channelNo = channelNo || obj.channelNo,
51
- deviceSerial = deviceSerial || obj.deviceSerial, validateCode = null != validateCode ? validateCode : obj.validateCode,
52
- obj.protocol + "//" + (validateCode ? validateCode + "@" : "") + obj.hostname + "/" + deviceSerial + "/" + channelNo + ("rec" === type && recType ? "." + recType : "") + ("live" === type && "hd" === definition ? "." + definition : "") + "." + type + search;
53
- },
54
- isHttp: function(url) {
55
- return /^http[s]?:\/\//.test(url);
56
- },
57
- isMobile: function(agent) {
58
- var _navigator, _navigator1, _navigator2, _window;
59
- return /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone|Opera Mini)/i.test(null != agent ? agent : null == (_navigator = navigator) ? void 0 : _navigator.userAgent) || /Macintosh/i.test(null == (_navigator1 = navigator) ? void 0 : _navigator1.userAgent) && (null == (_navigator2 = navigator) ? void 0 : _navigator2.maxTouchPoints) > 1 || (null == (_window = window) ? void 0 : _window.__IS_MOBILE_SIMULATOR__);
60
- },
61
- getQuery: getQuery,
62
- pick: function(obj, keys) {
63
- return Object.entries(obj).reduce(function(acc, param) {
64
- var key = param[0], value = param[1];
65
- return keys.includes(key) && (acc[key] = value), acc;
66
- }, {});
67
- },
68
- getStaticPath: function(path, base) {
69
- void 0 === base && (base = "");
70
- var protocolReg = /^(https?:\/\/|^\/\/)/;
71
- if ("" === path || void 0 === path) return "";
72
- if (protocolReg.test(path)) return path;
73
- path = path.replace(/\/+/g, "/"), base = protocolReg.test(base || "") ? base : window.location.href;
74
- try {
75
- return new URL(path, base).href;
76
- } catch (error) {
77
- return path;
78
- }
79
- },
80
- addVc: function(url, codecs) {
81
- void 0 === codecs && (codecs = [ "h264" ]);
82
- var vc = (codecs || [ "h264" ]).reduce(function(acc, key) {
83
- return key = key.toLowerCase(), acc + (codec[key] || 0);
84
- }, 0), host = url.split("?")[0], query = url.split("?")[1];
85
- return query = (query || "").split("&").filter(function(item) {
86
- return !/^vc=\d?/.test(item);
87
- }).join("&"), host + "?" + (query += (query ? "&" : "") + "vc=" + vc);
88
- }
89
- };
90
-
91
- export { index as default };