@lijuhong1981/jsurl 1.0.9 → 1.0.10

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/index.js CHANGED
@@ -11,6 +11,7 @@ import isHttpProtocol from "./src/isHttpProtocol.js";
11
11
  import splitPath from "./src/splitPath.js";
12
12
  import splitUrl from "./src/splitUrl.js";
13
13
  import parsePath from "./src/parsePath.js";
14
+ import parseQuery from "./src/parseQuery.js";
14
15
  import parseUrl from "./src/parseUrl.js";
15
16
 
16
17
  export {
@@ -27,5 +28,6 @@ export {
27
28
  splitPath,
28
29
  splitUrl,
29
30
  parsePath,
31
+ parseQuery,
30
32
  parseUrl,
31
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lijuhong1981/jsurl",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "> TODO: description",
5
5
  "author": "lijuhong1981 <lijuhong@hotmail.com>",
6
6
  "homepage": "https://github.com/lijuhong1981/jslibs#readme",
@@ -18,5 +18,5 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/lijuhong1981/jslibs/issues"
20
20
  },
21
- "gitHead": "c3059dfc0779fbf34ba00163e9636cfc4dfb334a"
21
+ "gitHead": "75538582d4f88fbef4e366404a96264c40bb05d8"
22
22
  }
@@ -0,0 +1,16 @@
1
+ const queryPattern = /(?:^|&)([^&=]*)=?([^&]*)/g;
2
+
3
+ /**
4
+ * 解析urlQuery字符串中的参数
5
+ * @param {string} urlQuery
6
+ * @param {object} result
7
+ * @returns {object}
8
+ */
9
+ function parseQuery(urlQuery, result = {}) {
10
+ urlQuery.replace(queryPattern, function (match, key, value) {
11
+ if (key)
12
+ result[key] = value;
13
+ });
14
+ };
15
+
16
+ export default parseQuery;
package/src/parseUrl.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import splitUrl from "./splitUrl.js";
2
+ import parseQuery from "./parseQuery.js";
2
3
 
3
4
  const names = ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"];
4
- const parseQuery = /(?:^|&)([^&=]*)=?([^&]*)/g;
5
5
 
6
6
  /**
7
7
  * 解析url,输出结果如下:
@@ -37,10 +37,7 @@ function parseUrl(url, result = {}) {
37
37
  }
38
38
  result.queryParams = {};
39
39
  if (result.query)
40
- result.query.replace(parseQuery, function (match, key, value) {
41
- if (key)
42
- result.queryParams[key] = value;
43
- });
40
+ parseQuery(result.query, result.queryParams);
44
41
  return result;
45
42
  };
46
43
 
package/src/splitUrl.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // const strict = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/;
2
- const loose = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
2
+ const splitPattern = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
3
3
 
4
4
  /**
5
5
  * 使用正则表达式把一个url解析为["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"]数组
@@ -7,7 +7,7 @@ const loose = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::
7
7
  * @returns {Array} 解析结果数组
8
8
  */
9
9
  function splitUrl(url) {
10
- return loose.exec(url);
10
+ return splitPattern.exec(url);
11
11
  };
12
12
 
13
13
  export default splitUrl;