lyb-js 1.6.1 → 1.6.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.
@@ -1,5 +1,5 @@
1
1
  /** @description 将对象转为地址栏参数
2
- * @param params 对象参数
2
+ * @param params 对象
3
3
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsObjToUrlParams-对象转Url参数
4
4
  */
5
5
  export declare const libJsObjToUrlParams: (params: Record<string, string | number | boolean>) => string;
@@ -1,5 +1,5 @@
1
1
  /** @description 将对象转为地址栏参数
2
- * @param params 对象参数
2
+ * @param params 对象
3
3
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsObjToUrlParams-对象转Url参数
4
4
  */
5
5
  export const libJsObjToUrlParams = (params) => {
@@ -7,7 +7,8 @@ export const libJsPathParams = (path) => {
7
7
  if (!url)
8
8
  return {};
9
9
  const params = url.split("&").reduce((pre, cur) => {
10
- const [k, v] = cur.split(/=(.+)/);
10
+ const [k, v] = cur.split(/=(.+)/).map(decodeURIComponent);
11
+ ;
11
12
  return (pre[k] = v), pre;
12
13
  }, {}) || {};
13
14
  return params;
@@ -0,0 +1,7 @@
1
+ /** @description URL参数转对象
2
+ * @param query URL参数
3
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsParseQueryString-URL参数转对象
4
+ */
5
+ export declare const libJsParseQueryString: (query: string) => {
6
+ [k: string]: string;
7
+ };
@@ -0,0 +1,5 @@
1
+ /** @description URL参数转对象
2
+ * @param query URL参数
3
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsParseQueryString-URL参数转对象
4
+ */
5
+ export const libJsParseQueryString = (query) => Object.fromEntries(new URLSearchParams(decodeURIComponent(query)));
package/README.md CHANGED
@@ -75,6 +75,8 @@ console.log(t); //"string"
75
75
 
76
76
  \- [LibJsPathParams-地址栏参数](#LibJsPathParams-地址栏参数)
77
77
 
78
+ \- [LibJsParseQueryString-URL参数转对象](#LibJsParseQueryString-URL参数转对象)
79
+
78
80
  \- [LibJsSetTitleIcon-网站标题图标](#LibJsSetTitleIcon-网站标题图标)
79
81
 
80
82
  \- [LibJsTagTitleTip-网站标题交互](#LibJsTagTitleTip-网站标题交互)
@@ -241,6 +243,14 @@ const params = libJsPathParams();
241
243
  console.log(params); //{ param1: "value1", param2: "value2" }
242
244
  ```
243
245
 
246
+ ### LibJsParseQueryString-URL参数转对象
247
+
248
+ > 将`URL`参数转为对象
249
+
250
+ ```ts
251
+ libJsParseQueryString("name=lengyibai&age=18"); //{name: "lengyibai", age: "18"}
252
+ ```
253
+
244
254
  ### LibJsSetTitleIcon-网站标题图标
245
255
 
246
256
  > 动态设置网站标题及图标,涉及到不同平台的打包,可以根据不同环境来设置网站标题和图标
package/lyb.js CHANGED
@@ -92,7 +92,7 @@ ${log3.label}:`, log3.value];
92
92
  if (!url)
93
93
  return {};
94
94
  const params = url.split("&").reduce((pre, cur) => {
95
- const [k, v2] = cur.split(/=(.+)/);
95
+ const [k, v2] = cur.split(/=(.+)/).map(decodeURIComponent);
96
96
  return pre[k] = v2, pre;
97
97
  }, {}) || {};
98
98
  return params;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-js",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "自用JS方法库",
5
5
  "license": "ISC",
6
6
  "type": "module",