tools-min-ns 1.9.3 → 1.9.4

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/README.md CHANGED
@@ -5,6 +5,10 @@ cnpm i tools-min-ns --save
5
5
  ```
6
6
 
7
7
  # updates
8
+ ## v1.9.4
9
+
10
+ > UrlUtil 优化setUrlParamsNotRefresh在web,h5中的路由为hash的兼容性
11
+
8
12
  ## v1.9.3
9
13
 
10
14
  > DateUtil 优化并新增isDateInYearAndMonth方法
@@ -76,19 +76,22 @@ var UrlUtil;
76
76
  * getUrlRequest('https://ss.cn?sdf=213&bdl=231111'); => {sdf: "213", bdl: "231111"}
77
77
  */
78
78
  function getUrlRequest(href) {
79
- var _a;
80
79
  if (href === void 0) {
81
80
  href = window.location.href;
82
81
  }
83
- href = href.replaceAll('#/', '');
82
+ href = "".concat(href === null || href === void 0 ? void 0 : href.slice(-1)) === '/' ? href === null || href === void 0 ? void 0 : href.slice(0, href.length - 1) : href;
84
83
  var theRequest = {};
85
- if (href.includes('?')) {
86
- var strs = (_a = "".concat(href === null || href === void 0 ? void 0 : href.slice(-1)) === '/' ? href === null || href === void 0 ? void 0 : href.slice(0, href.length - 1) : href) === null || _a === void 0 ? void 0 : _a.split('?').slice(-1).toString().split('&');
84
+ if (href.includes('#/')) {
85
+ //hash
86
+ href = "".concat(href.split('/').slice(-1));
87
+ }
88
+ if (href === null || href === void 0 ? void 0 : href.includes('?')) {
89
+ var strs = href === null || href === void 0 ? void 0 : href.split('?').slice(-1).toString().split('&');
87
90
  for (var i = 0; i < strs.length; i++) {
88
- var _b = __read(strs[i].split('='), 2),
89
- key = _b[0],
90
- value = _b[1];
91
- if (key) theRequest[key] = decodeURI(value);
91
+ var _a = __read(strs[i].split('='), 2),
92
+ key = _a[0],
93
+ value = _a[1];
94
+ if (key) theRequest[key] = decodeURIComponent(value);
92
95
  }
93
96
  }
94
97
  return theRequest;
@@ -101,6 +104,14 @@ var UrlUtil;
101
104
  function setUrlParamsNotRefresh(obj) {
102
105
  var urlParams = getUrlRequest();
103
106
  var str = objToUrlParam(ObjectUtil.mergeParams(obj, urlParams));
107
+ var href = window.location.href;
108
+ if (href.includes('#/') && !"".concat(href.split('/').slice(-1)).includes('?')) {
109
+ var url_1 = "".concat(href).concat(str ? "?".concat(str) : '');
110
+ window.history.replaceState({
111
+ url: url_1
112
+ }, '', url_1);
113
+ return;
114
+ }
104
115
  var _arr = window.location.href.split('?');
105
116
  var url = "".concat(_arr.slice(0, _arr.length - 1).join('?')).concat(str ? "?".concat(str) : '');
106
117
  window.history.replaceState({
@@ -86,19 +86,22 @@ var UrlUtil;
86
86
  * getUrlRequest('https://ss.cn?sdf=213&bdl=231111'); => {sdf: "213", bdl: "231111"}
87
87
  */
88
88
  function getUrlRequest(href) {
89
- var _a;
90
89
  if (href === void 0) {
91
90
  href = window.location.href;
92
91
  }
93
- href = href.replaceAll('#/', '');
92
+ href = "".concat(href === null || href === void 0 ? void 0 : href.slice(-1)) === '/' ? href === null || href === void 0 ? void 0 : href.slice(0, href.length - 1) : href;
94
93
  var theRequest = {};
95
- if (href.includes('?')) {
96
- var strs = (_a = "".concat(href === null || href === void 0 ? void 0 : href.slice(-1)) === '/' ? href === null || href === void 0 ? void 0 : href.slice(0, href.length - 1) : href) === null || _a === void 0 ? void 0 : _a.split('?').slice(-1).toString().split('&');
94
+ if (href.includes('#/')) {
95
+ //hash
96
+ href = "".concat(href.split('/').slice(-1));
97
+ }
98
+ if (href === null || href === void 0 ? void 0 : href.includes('?')) {
99
+ var strs = href === null || href === void 0 ? void 0 : href.split('?').slice(-1).toString().split('&');
97
100
  for (var i = 0; i < strs.length; i++) {
98
- var _b = __read(strs[i].split('='), 2),
99
- key = _b[0],
100
- value = _b[1];
101
- if (key) theRequest[key] = decodeURI(value);
101
+ var _a = __read(strs[i].split('='), 2),
102
+ key = _a[0],
103
+ value = _a[1];
104
+ if (key) theRequest[key] = decodeURIComponent(value);
102
105
  }
103
106
  }
104
107
  return theRequest;
@@ -111,6 +114,14 @@ var UrlUtil;
111
114
  function setUrlParamsNotRefresh(obj) {
112
115
  var urlParams = getUrlRequest();
113
116
  var str = objToUrlParam(ObjectUtil_1.default.mergeParams(obj, urlParams));
117
+ var href = window.location.href;
118
+ if (href.includes('#/') && !"".concat(href.split('/').slice(-1)).includes('?')) {
119
+ var url_1 = "".concat(href).concat(str ? "?".concat(str) : '');
120
+ window.history.replaceState({
121
+ url: url_1
122
+ }, '', url_1);
123
+ return;
124
+ }
114
125
  var _arr = window.location.href.split('?');
115
126
  var url = "".concat(_arr.slice(0, _arr.length - 1).join('?')).concat(str ? "?".concat(str) : '');
116
127
  window.history.replaceState({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tools-min-ns",
3
3
  "description": "工具包适用于前端以及node",
4
- "version": "1.9.3",
4
+ "version": "1.9.4",
5
5
  "main": "lib/index.js",
6
6
  "license": "MIT",
7
7
  "author": "nanshen",