@lingxiteam/assets 1.0.11-alpha.7 → 1.0.11

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.
Files changed (2) hide show
  1. package/es/utils/url.js +49 -36
  2. package/package.json +1 -1
package/es/utils/url.js CHANGED
@@ -1,9 +1,9 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
3
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
4
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
5
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
6
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
7
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
8
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
9
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -49,41 +49,54 @@ href 当前文档的完整url
49
49
  */
50
50
  export var parseUrlExpression = function parseUrlExpression(urlStr) {
51
51
  var urlParamsContext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
52
- var _ref = window.location || {},
53
- protocol = _ref.protocol,
54
- _ref$href = _ref.href,
55
- href = _ref$href === void 0 ? '' : _ref$href,
56
- port = _ref.port,
57
- pathname = _ref.pathname,
58
- host = _ref.host,
59
- hostname = _ref.hostname,
60
- hash = _ref.hash;
61
- var defaultParams = {
62
- protocol: protocol,
63
- href: href,
64
- port: port,
65
- pathname: pathname,
66
- host: host,
67
- hostname: hostname,
68
- searchObj: getSearchObj(href),
69
- search: decodeURIComponent(href.split('?').pop() || ''),
70
- hash: decodeURIComponent(hash)
71
- };
72
- var evalVariableExpression = function evalVariableExpression(text) {
73
- var params = _objectSpread(_objectSpread({}, defaultParams), urlParamsContext);
74
- try {
75
- return Function('context', "\n with(context) {\n return (function(){\n \"use strict\";\n return ".concat(text.slice(2, text.length - 1), ";\n })();\n }\n "))(params);
76
- } catch (error) {
77
- console.warn("".concat(text, "\u8868\u8FBE\u5F0F\u6267\u884C\u6709\u8BEF:"), error);
78
- return text;
79
- }
80
- };
81
- var regexp = /\$\{(.+?)\}/g;
52
+ if (urlStr && typeof urlStr !== 'string') {
53
+ console.error("parseUrlExpression\u5904\u7406".concat(urlStr, "\u65F6\u89E3\u6790\u9519\u8BEF:\u8868\u8FBE\u5F0F\u9700\u4E3A\u5B57\u7B26\u4E32\u683C\u5F0F"));
54
+ return '';
55
+ }
56
+ var extend = urlParamsContext;
82
57
  var result = urlStr;
83
- if (result) {
84
- result = result.replace(regexp, function (str) {
85
- return evalVariableExpression(str);
86
- });
58
+ if (_typeof(urlParamsContext) !== 'object') {
59
+ console.warn("parseUrlExpression\u53C2\u6570\u9519\u8BEF:\u6269\u5C55\u53C2\u6570\u9700\u4E3A\u5BF9\u8C61");
60
+ extend = {};
61
+ }
62
+ try {
63
+ var _ref = window.location || {},
64
+ protocol = _ref.protocol,
65
+ _ref$href = _ref.href,
66
+ href = _ref$href === void 0 ? '' : _ref$href,
67
+ port = _ref.port,
68
+ pathname = _ref.pathname,
69
+ host = _ref.host,
70
+ hostname = _ref.hostname,
71
+ hash = _ref.hash;
72
+ var defaultParams = {
73
+ protocol: protocol,
74
+ href: href,
75
+ port: port,
76
+ pathname: pathname,
77
+ host: host,
78
+ hostname: hostname,
79
+ searchObj: getSearchObj(href),
80
+ search: decodeURIComponent(href.split('?').pop() || ''),
81
+ hash: decodeURIComponent(hash)
82
+ };
83
+ var evalVariableExpression = function evalVariableExpression(text) {
84
+ var params = _objectSpread(_objectSpread({}, defaultParams), extend);
85
+ try {
86
+ return Function('context', "\n with(context) {\n return (function(){\n \"use strict\";\n return ".concat(text.slice(2, text.length - 1), ";\n })();\n }\n "))(params);
87
+ } catch (error) {
88
+ console.warn("parseUrlExpression\u5904\u7406".concat(text, "\u65F6\u89E3\u6790\u9519\u8BEF:"), error);
89
+ return text;
90
+ }
91
+ };
92
+ var regexp = /\$\{(.+?)\}/g;
93
+ if (result) {
94
+ result = result.replace(regexp, function (str) {
95
+ return evalVariableExpression(str);
96
+ });
97
+ }
98
+ } catch (e) {
99
+ console.error("parseUrlExpression\u6267\u884C\u9519\u8BEF:", e);
87
100
  }
88
- return result;
101
+ return result || '';
89
102
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxiteam/assets",
3
- "version": "1.0.11-alpha.7",
3
+ "version": "1.0.11",
4
4
  "description": "灵犀低代码平台移动端 - 工具类",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",