amos-tool 1.5.2 → 1.5.3

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/docs/Logger.html CHANGED
@@ -336,7 +336,7 @@ isDebug: true
336
336
  <br class="clear">
337
337
 
338
338
  <footer>
339
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu Mar 09 2023 13:58:14 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
339
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu Mar 16 2023 10:03:24 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
340
340
  </footer>
341
341
 
342
342
  <script>prettyPrint();</script>
package/docs/global.html CHANGED
@@ -16595,7 +16595,7 @@ schedule <code>callback</code> to execute after <code>delay</code> ms.</p></td>
16595
16595
  <br class="clear">
16596
16596
 
16597
16597
  <footer>
16598
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu Mar 09 2023 13:58:14 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
16598
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu Mar 16 2023 10:03:24 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
16599
16599
  </footer>
16600
16600
 
16601
16601
  <script>prettyPrint();</script>
package/docs/index.html CHANGED
@@ -785,7 +785,7 @@ convert2BMP(canvas, width, height)</p>
785
785
  <br class="clear">
786
786
 
787
787
  <footer>
788
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu Mar 09 2023 13:58:14 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
788
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu Mar 16 2023 10:03:24 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
789
789
  </footer>
790
790
 
791
791
  <script>prettyPrint();</script>
package/index.d.ts CHANGED
@@ -252,17 +252,46 @@ declare namespace LocationParam {
252
252
  * completeParam({ token: 'xxddf', id: null }, '/main/sub', true); // `/main/sub?token=xxddf&id=`
253
253
  * // 使用 location.href, 传入两个参数,强制转化 null 值
254
254
  * completeParam({ token: 'xxddf', id: null }, true); // `http://localhost:8080/aaa?token=xxddf&id=`
255
+ *
256
+ * // 叠加值,该方法只会叠加参数,如果需要更新已有字段,以及叠加参数,可以使用 `changeParam`
257
+ * completeParam({ token: 'aa-bb-cc', id: '654321' }, 'a/b/c?token=aaa&id=bcdef'); // `a/b/c?token=aaa&id=bcdef&token=aa-bb-cc&id=654321`
255
258
  */
256
259
  export function completeParam(param: Object, url: string, forceCast: Boolean): string;
257
260
  /**
258
- * 替换 url 参数
259
- * @param href 需要替换参数的 url
260
- * @param params 参数对象
261
+ * 替换 url 参数。如果url中无指定的参数,则自动追加。
262
+ *
263
+ * 自动将对象中的 undefined 值,转化为 ''。null 值则直接返回 null 字符串。
264
+ *
265
+ * params 参数中的数据格式,建议调用处统一处理为 string 格式。内部仅统一处理 undefined 和 {} 格式。
266
+ * @param href 需要替换参数的 url。为空字符串则直接返回 href
267
+ * @param params 参数对象。为空对象,则直接返回 href。
261
268
  * @example
269
+ * // 无参数,自动追加
270
+ * changeParam('a/b/d/g', { a: 1, b: 2, c: 3 }); // 'a/b/d/g?a=1&b=2&c=3'
271
+ * // 更新已有参数的值
262
272
  * changeParam('a/b/d/g?a=aa&b=bb&c=cc', { a: 1, b: 2, c: 3 }); // 'a/b/d/g?a=1&b=2&c=3'
263
- * changeParam('a/b/d/g?a=aa&b=bb&c=cc', { a: 1, b: 2, c: 3, d: 5 }); // 'a/b/d/g?a=1&b=2&c=3&d=5'
273
+ * // url 中无参数 d,自动追加参数
274
+ * changeParam('a/b/d/g?a=aa&b=bb&c=cc', { a: 1, b: 2, c: 3, d: 5 }); // 'a/b/d/g?a=1&b=2&c=3&d=5'
275
+ * // undefined 值转化为 ''
276
+ * changeParam('a/b/d/g', { a: 1, b: 2, c: undefined }); // 'a/b/d/g?a=1&b=2&c='
277
+ * // null 值转化为 'null'
278
+ * changeParam('a/b/d/g', { a: 1, b: null, c: undefined }); // 'a/b/d/g?a=1&b=null&c='
279
+ * // [] 和 {} 值。最好不要给参数中传入 {} 值
280
+ * changeParam('a/b/d/g', { a: { m: 3 }, b: [1,2] }); // a/b/d/g?a={"m":3}&b=1,2
264
281
  */
265
282
  export function changeParam(href: String, params: Object): String;
283
+ /**
284
+ * encode 参数中的值
285
+ * @param param
286
+ * @param keys 需要执行 encode 的字段
287
+ * @param processor 自定义 encode 方法,默认采用 `encodeURIComponent`
288
+ * @example
289
+ * encodeParam({ name: 'ilex', email: 'aa@qq.com' }, 'email'); // { name: 'ilex', email: 'aa%40qq.com' }
290
+ * encodeParam({ info: { hobby: 'coding', phone: '155666688881' } }, 'info'); // { info: '%7B%22hobby%22%3A%22coding%22%2C%22phone%22%3A%22155666688881%22%7D' }
291
+ * encodeParam({ split: [1,2,3] }, 'split'); // { split: '%5B1%2C2%2C3%5D' }
292
+ * encodeParam({ star: 18 }, 'star', v => v * 2); // { star: 36 }
293
+ */
294
+ export function encodeParam(param: {}, keys: String | String[], processor: (arg) => String): {};
266
295
  /**
267
296
  * 更新浏览器地址栏地址
268
297
  * @param param
@@ -1,141 +1,151 @@
1
1
  "use strict";
2
2
 
3
3
  var utils = require("./utils"), _LSFN = function() {
4
- var n = [];
4
+ var t = [];
5
5
  return function() {
6
- var t = window.location.search;
7
- if (utils.isEmpty(t)) throw new Error("the [window.location.search] not empty!");
8
- var e = t.length > 1 ? t.substring(1) : null;
9
- utils.isNull(e) || (n = [].slice.call(e.split("&")));
6
+ var n = window.location.search;
7
+ if (utils.isEmpty(n)) throw new Error("the [window.location.search] not empty!");
8
+ var i = n.length > 1 ? n.substring(1) : null;
9
+ utils.isNull(i) || (t = [].slice.call(i.split("&")));
10
10
  }(), {
11
- getValue: function(t) {
12
- n.forEach((function(n) {
13
- var e = n.split("=");
14
- if (e[0] === t) return e[1];
11
+ getValue: function(n) {
12
+ t.forEach((function(t) {
13
+ var i = t.split("=");
14
+ if (i[0] === n) return i[1];
15
15
  }));
16
16
  },
17
17
  getParameters: function() {
18
- var t = [];
19
- return n.forEach((function(n) {
20
- t.push(n.split("=")[0]);
21
- })), t;
18
+ var n = [];
19
+ return t.forEach((function(t) {
20
+ n.push(t.split("=")[0]);
21
+ })), n;
22
22
  }
23
23
  };
24
24
  }, _LocationSearch = {
25
25
  _keyValuePairs: [],
26
26
  init: function() {
27
- var n = window.location.search;
28
- if (utils.isEmpty(n)) throw new Error("the [window.location.search] not empty!");
29
- var t = n.length > 1 ? n.substring(1) : null;
30
- return utils.isNull(t) || (_LocationSearch._keyValuePairs = [].slice.call(t.split("&"))),
27
+ var t = window.location.search;
28
+ if (utils.isEmpty(t)) throw new Error("the [window.location.search] not empty!");
29
+ var n = t.length > 1 ? t.substring(1) : null;
30
+ return utils.isNull(n) || (_LocationSearch._keyValuePairs = [].slice.call(n.split("&"))),
31
31
  this;
32
32
  },
33
- getValue: function(n) {
34
- _LocationSearch._keyValuePairs.forEach((function(t) {
35
- var e = t.split("=");
36
- if (e[0] === n) return e[1];
33
+ getValue: function(t) {
34
+ _LocationSearch._keyValuePairs.forEach((function(n) {
35
+ var i = n.split("=");
36
+ if (i[0] === t) return i[1];
37
37
  }));
38
38
  },
39
39
  getParameters: function() {
40
- var n = [];
41
- return _LocationSearch._keyValuePairs.forEach((function(t) {
42
- n.push(t.split("=")[0]);
43
- })), n;
40
+ var t = [];
41
+ return _LocationSearch._keyValuePairs.forEach((function(n) {
42
+ t.push(n.split("=")[0]);
43
+ })), t;
44
44
  }
45
45
  }, LocationParam = {
46
- parse: function(n) {
47
- var t, e, i, r, o;
48
- n || (n = window.location.search);
49
- var a = {}, c = [];
50
- if (!utils.isEmpty(n) && n.length > 1) for (r = 0, o = (c = n.slice(1 + n.indexOf("?"), n.length).split("&")).length; r < o; r++) t = (e = (e = c[r]).split("="))[0],
51
- i = e[1], t in a ? (utils.isArray(a[t]) || (a[t] = [ a[t] ]), a[t].push(decodeURIComponent(i))) : a[t] = decodeURIComponent(i);
46
+ parse: function(t) {
47
+ var n, i, e, r, o;
48
+ t || (t = window.location.search);
49
+ var a = {}, s = [];
50
+ if (!utils.isEmpty(t) && t.length > 1) for (r = 0, o = (s = t.slice(1 + t.indexOf("?"), t.length).split("&")).length; r < o; r++) n = (i = (i = s[r]).split("="))[0],
51
+ e = i[1], n in a ? (utils.isArray(a[n]) || (a[n] = [ a[n] ]), a[n].push(decodeURIComponent(e))) : a[n] = decodeURIComponent(e);
52
52
  return a;
53
53
  },
54
- paramSearch: function(n, t) {
55
- if (utils.isUndefined(t) || utils.isNull(t)) {
56
- if (t = window.location.search, utils.isUndefined(n) || utils.isNull(n)) {
57
- for (var e = t.substr(1, t.length - 1).split("&"), i = {}, r = 0; r < e.length; r++) {
58
- var o = e[r].split("=");
59
- 1 === o.length ? i[o[0]] = "" : 2 === o.length ? i[o[0]] = decodeURIComponent(o[1]) : console.log("there is something wrong when use [paramSearch]!");
54
+ paramSearch: function(t, n) {
55
+ if (utils.isUndefined(n) || utils.isNull(n)) {
56
+ if (n = window.location.search, utils.isUndefined(t) || utils.isNull(t)) {
57
+ for (var i = n.substr(1, n.length - 1).split("&"), e = {}, r = 0; r < i.length; r++) {
58
+ var o = i[r].split("=");
59
+ 1 === o.length ? e[o[0]] = "" : 2 === o.length ? e[o[0]] = decodeURIComponent(o[1]) : console.log("there is something wrong when use [paramSearch]!");
60
60
  }
61
- return i;
61
+ return e;
62
62
  }
63
63
  try {
64
- var a = new RegExp(n + "=([^&]+)?");
65
- return decodeURIComponent(t.match(a)[1]);
66
- } catch (n) {
64
+ var a = new RegExp(t + "=([^&]+)?");
65
+ return decodeURIComponent(n.match(a)[1]);
66
+ } catch (t) {
67
67
  return null;
68
68
  }
69
69
  }
70
70
  },
71
71
  getLocationParams: function() {
72
- var n, t, e = {}, i = window.location.href;
73
- if (!utils.isEmpty(i)) {
74
- var r = i.indexOf("?");
75
- if (r < -1) console.log("the location.href is invalid!"); else for (var o = (i = i.substr(r + 1)).split("&"), a = 0; a < o.length; a++) (r = o[a].indexOf("=")) > 0 && (n = o[a].substring(0, r),
76
- t = o[a].substr(r + 1), e[n] = decodeURIComponent(t));
72
+ var t, n, i = {}, e = window.location.href;
73
+ if (!utils.isEmpty(e)) {
74
+ var r = e.indexOf("?");
75
+ if (r < -1) console.log("the location.href is invalid!"); else for (var o = (e = e.substr(r + 1)).split("&"), a = 0; a < o.length; a++) (r = o[a].indexOf("=")) > 0 && (t = o[a].substring(0, r),
76
+ n = o[a].substr(r + 1), i[t] = decodeURIComponent(n));
77
77
  }
78
- return e;
78
+ return i;
79
79
  },
80
- getLocationParamByName: function(n) {
81
- var t = new RegExp("(^|&?)".concat(n, "=([^&]*)(&|$)")), e = window.location.search.substr(1).match(t);
82
- return null != e ? decodeURIComponent(e[2]) : null;
80
+ getLocationParamByName: function(t) {
81
+ var n = new RegExp("(^|&?)".concat(t, "=([^&]*)(&|$)")), i = window.location.search.substr(1).match(n);
82
+ return null != i ? decodeURIComponent(i[2]) : null;
83
83
  },
84
- getParameter: function(n, t) {
85
- var e = new RegExp("(\\?|#|&)" + t + "=([^&#]*)(&|#|$)"), i = n.match(e);
86
- return i ? i[2] : "";
84
+ getParameter: function(t, n) {
85
+ var i = new RegExp("(\\?|#|&)" + n + "=([^&#]*)(&|#|$)"), e = t.match(i);
86
+ return e ? e[2] : "";
87
87
  },
88
- extractParam: function(n, t) {
89
- if (!n) return null;
90
- var e = new RegExp("(^|&?)".concat(t, "=([^&]*)(&|$)")), i = n.substr(1).match(e);
91
- return utils.isNil(i) ? null : decodeURIComponent(i[2]);
88
+ extractParam: function(t, n) {
89
+ if (!t) return null;
90
+ var i = new RegExp("(^|&?)".concat(n, "=([^&]*)(&|$)")), e = t.substr(1).match(i);
91
+ return utils.isNil(e) ? null : decodeURIComponent(e[2]);
92
92
  },
93
- extractParams: function(n) {
94
- var t, e, i = {}, r = n || window.location.href;
93
+ extractParams: function(t) {
94
+ var n, i, e = {}, r = t || window.location.href;
95
95
  if (!utils.isEmpty(r)) {
96
96
  var o = r.indexOf("?");
97
- if (o < -1) console.log("the location.href is invalid!"); else for (var a = (r = r.substr(o + 1)).split("&"), c = 0; c < a.length; c++) (o = a[c].indexOf("=")) > 0 && (t = a[c].substring(0, o),
98
- e = a[c].substr(o + 1), i[t] = decodeURIComponent(e));
97
+ if (o < -1) console.log("the location.href is invalid!"); else for (var a = (r = r.substr(o + 1)).split("&"), s = 0; s < a.length; s++) (o = a[s].indexOf("=")) > 0 && (n = a[s].substring(0, o),
98
+ i = a[s].substr(o + 1), e[n] = decodeURIComponent(i));
99
99
  }
100
- return i;
100
+ return e;
101
101
  },
102
- extractParamAll: function(n) {
103
- var t, e, i = arguments.length > 1 && void 0 !== arguments[1] && arguments[1], r = {}, o = n || window.location.href;
102
+ extractParamAll: function(t) {
103
+ var n, i, e = arguments.length > 1 && void 0 !== arguments[1] && arguments[1], r = {}, o = t || window.location.href;
104
104
  if (!utils.isEmpty(o)) {
105
105
  var a = o.indexOf("?");
106
- if (a < -1) console.log("the location.href is invalid!"); else for (var c = (o = o.substr(a + 1)).split("&"), l = 0; l < c.length; l++) (a = c[l].indexOf("=")) > 0 && (t = c[l].substring(0, a),
107
- e = c[l].substr(a + 1), r[t] = i ? decodeURIComponent(e) : e);
106
+ if (a < -1) console.log("the location.href is invalid!"); else for (var s = (o = o.substr(a + 1)).split("&"), l = 0; l < s.length; l++) (a = s[l].indexOf("=")) > 0 && (n = s[l].substring(0, a),
107
+ i = s[l].substr(a + 1), r[n] = e ? decodeURIComponent(i) : i);
108
108
  }
109
109
  return r;
110
110
  },
111
- completeParam: function(n, t, e) {
112
- var i = arguments;
113
- 1 === i.length ? t || (t = window.location.href) : 2 === i.length && utils.isBoolean(t) && (e = t,
114
- t = window.location.href), utils.isUndefined(e) && (e = !1), t || (t = window.location.href);
115
- var r = (Object.keys(n) || []).reduce((function(t, i) {
116
- var r = n[i];
117
- return e && (utils.isNull(r) || utils.isUndefined(r)) && (r = ""), t += "&".concat(i, "=").concat(r);
111
+ completeParam: function(t, n, i) {
112
+ var e = arguments;
113
+ 1 === e.length ? n || (n = window.location.href) : 2 === e.length && utils.isBoolean(n) && (i = n,
114
+ n = window.location.href), utils.isUndefined(i) && (i = !1), n || (n = window.location.href);
115
+ var r = (Object.keys(t) || []).reduce((function(n, e) {
116
+ var r = t[e];
117
+ return i && (utils.isNull(r) || utils.isUndefined(r)) && (r = ""), n += "&".concat(e, "=").concat(r);
118
118
  }), "");
119
- return r ? (r = r.slice(1), -1 !== t.indexOf("?") ? t.endsWith("?") ? "".concat(t).concat(r) : "".concat(t, "&").concat(r) : "".concat(t, "?").concat(r)) : t;
119
+ return r ? (r = r.slice(1), -1 !== n.indexOf("?") ? n.endsWith("?") ? "".concat(n).concat(r) : "".concat(n, "&").concat(r) : "".concat(n, "?").concat(r)) : n;
120
120
  },
121
- changeParam: function(n, t) {
122
- if (!n || utils.isEmpty(t)) return n;
123
- var e = n;
124
- return Object.keys(t).forEach((function(n) {
125
- var i = t[n];
126
- utils.isUndefined(i) && (i = ""), e = function(n, t, e) {
127
- var i = t + "=([^&]*)", r = t + "=" + e;
128
- if (n.match(i)) {
129
- var o = new RegExp("(".concat(t, "=)([^&]*)"), "gi");
130
- return n.replace(o, r);
121
+ changeParam: function(t, n) {
122
+ if (!t || utils.isEmpty(n)) return t;
123
+ var i = t;
124
+ return Object.keys(n).forEach((function(t) {
125
+ var e = n[t];
126
+ utils.isUndefined(e) ? e = "" : utils.isArray(e) || utils.isObject(e) && (e = JSON.stringify(e)),
127
+ i = function(t, n, i) {
128
+ var e = n + "=([^&]*)", r = n + "=" + i;
129
+ if (t.match(e)) {
130
+ var o = new RegExp("(".concat(n, "=)([^&]*)"), "gi");
131
+ return t.replace(o, r);
131
132
  }
132
- return n.match("[?]") ? n + "&" + r : n + "?" + r;
133
- }(e, n, i);
134
- })), e;
133
+ return t.match("[?]") ? t + "&" + r : t + "?" + r;
134
+ }(i, t, e);
135
+ })), i;
136
+ },
137
+ encodeParam: function(t, n, i) {
138
+ if (utils.isNil(n) || !utils.isObject(t)) return t;
139
+ utils.isString(n) && (n = [ n ]);
140
+ for (var e = utils.clone(t), r = 0, o = n.length; r < o; r++) {
141
+ var a = n[r];
142
+ utils.isNil(e[a]) || (i ? e[a] = i(e[a]) : utils.isString(e[a]) ? e[a] = encodeURIComponent(e[a]) : (utils.isOnlyObject(e[a]) || utils.isArray(e[a])) && (e[a] = encodeURIComponent(JSON.stringify(e[a]))));
143
+ }
144
+ return e;
135
145
  },
136
- replaceUrl: function(n, t) {
137
- var e = t || location.href;
138
- e = LocationParam.changeParam(e, n), location.replace(e);
146
+ replaceUrl: function(t, n) {
147
+ var i = n || location.href;
148
+ i = LocationParam.changeParam(i, t), location.replace(i);
139
149
  },
140
150
  LocationSearch: _LocationSearch,
141
151
  LSFN: _LSFN
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amos-tool",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "amos ui tool",
5
5
  "main": "index.js",
6
6
  "directories": {