@deot/helper-route 1.1.3 → 1.1.5

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
@@ -3,10 +3,12 @@
3
3
  ### `Route`
4
4
 
5
5
  ```js
6
- import * as Route from "@deot/helper-route";
6
+ import * as Route from '@deot/helper-route';
7
+ ```
7
8
 
9
+ ```js
8
10
  // or
9
- import { Route } from "@deot/helper";
11
+ import { Route } from '@deot/helper';
10
12
  ```
11
13
 
12
14
  ---
package/dist/index.cjs CHANGED
@@ -28,9 +28,9 @@ const merge = (route) => {
28
28
  let result = origin;
29
29
  result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
30
30
  let queryArr = [];
31
- for (let key in query) {
31
+ for (const key in query) {
32
32
  if (query[key] || query[key] === false || query[key] === 0) {
33
- let v = helperUtils.flatten(query[key]);
33
+ const v = helperUtils.flatten(query[key]);
34
34
  queryArr = [
35
35
  ...queryArr,
36
36
  `${key}=${encodeURIComponent(v)}`
@@ -54,15 +54,16 @@ const parse = (url, options) => {
54
54
  const query = {};
55
55
  if (search) {
56
56
  Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
57
- let [key, value] = v.split("=");
58
- value = helperUtils.flatten(value);
59
- query[key] = typeof options$.parse === "function" ? options$.parse(value) : value;
57
+ const [key, value] = v.split("=");
58
+ const value$ = helperUtils.flatten(value);
59
+ query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
60
60
  });
61
61
  }
62
- const sIndex = prefix.indexOf("/");
62
+ const pIndex = prefix.indexOf("://");
63
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
63
64
  return {
64
65
  origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
65
- path: prefix.slice(sIndex),
66
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
66
67
  query
67
68
  };
68
69
  };
@@ -10,12 +10,12 @@ var HelperRoute = (function (exports) {
10
10
  throw new Error(value);
11
11
  }
12
12
  try {
13
- let next = (parser || decodeURIComponent)(parseValue);
13
+ const next = (parser || decodeURIComponent)(parseValue);
14
14
  if (parseValue === next) {
15
15
  need = false;
16
16
  }
17
17
  parseValue = next;
18
- } catch {
18
+ } catch (_) {
19
19
  need = false;
20
20
  }
21
21
  safeCount++;
@@ -26,7 +26,7 @@ var HelperRoute = (function (exports) {
26
26
  const flattenJSONParse = (value) => {
27
27
  if (value === null)
28
28
  return null;
29
- let regex = /^\d+$/;
29
+ const regex = /^\d+$/;
30
30
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
31
31
  return value;
32
32
  }
@@ -57,9 +57,9 @@ var HelperRoute = (function (exports) {
57
57
  let result = origin;
58
58
  result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
59
59
  let queryArr = [];
60
- for (let key in query) {
60
+ for (const key in query) {
61
61
  if (query[key] || query[key] === false || query[key] === 0) {
62
- let v = flatten(query[key]);
62
+ const v = flatten(query[key]);
63
63
  queryArr = [
64
64
  ...queryArr,
65
65
  `${key}=${encodeURIComponent(v)}`
@@ -83,15 +83,16 @@ var HelperRoute = (function (exports) {
83
83
  const query = {};
84
84
  if (search) {
85
85
  Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
86
- let [key, value] = v.split("=");
87
- value = flatten(value);
88
- query[key] = typeof options$.parse === "function" ? options$.parse(value) : value;
86
+ const [key, value] = v.split("=");
87
+ const value$ = flatten(value);
88
+ query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
89
89
  });
90
90
  }
91
- const sIndex = prefix.indexOf("/");
91
+ const pIndex = prefix.indexOf("://");
92
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
92
93
  return {
93
94
  origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
94
- path: prefix.slice(sIndex),
95
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
95
96
  query
96
97
  };
97
98
  };
package/dist/index.js CHANGED
@@ -24,9 +24,9 @@ const merge = (route) => {
24
24
  let result = origin;
25
25
  result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
26
26
  let queryArr = [];
27
- for (let key in query) {
27
+ for (const key in query) {
28
28
  if (query[key] || query[key] === false || query[key] === 0) {
29
- let v = flatten(query[key]);
29
+ const v = flatten(query[key]);
30
30
  queryArr = [
31
31
  ...queryArr,
32
32
  `${key}=${encodeURIComponent(v)}`
@@ -50,15 +50,16 @@ const parse = (url, options) => {
50
50
  const query = {};
51
51
  if (search) {
52
52
  Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
53
- let [key, value] = v.split("=");
54
- value = flatten(value);
55
- query[key] = typeof options$.parse === "function" ? options$.parse(value) : value;
53
+ const [key, value] = v.split("=");
54
+ const value$ = flatten(value);
55
+ query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
56
56
  });
57
57
  }
58
- const sIndex = prefix.indexOf("/");
58
+ const pIndex = prefix.indexOf("://");
59
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
59
60
  return {
60
61
  origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
61
- path: prefix.slice(sIndex),
62
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
62
63
  query
63
64
  };
64
65
  };
@@ -13,12 +13,12 @@
13
13
  throw new Error(value);
14
14
  }
15
15
  try {
16
- let next = (parser || decodeURIComponent)(parseValue);
16
+ const next = (parser || decodeURIComponent)(parseValue);
17
17
  if (parseValue === next) {
18
18
  need = false;
19
19
  }
20
20
  parseValue = next;
21
- } catch {
21
+ } catch (_) {
22
22
  need = false;
23
23
  }
24
24
  safeCount++;
@@ -29,7 +29,7 @@
29
29
  const flattenJSONParse = (value) => {
30
30
  if (value === null)
31
31
  return null;
32
- let regex = /^\d+$/;
32
+ const regex = /^\d+$/;
33
33
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
34
34
  return value;
35
35
  }
@@ -60,9 +60,9 @@
60
60
  let result = origin;
61
61
  result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
62
62
  let queryArr = [];
63
- for (let key in query) {
63
+ for (const key in query) {
64
64
  if (query[key] || query[key] === false || query[key] === 0) {
65
- let v = flatten(query[key]);
65
+ const v = flatten(query[key]);
66
66
  queryArr = [
67
67
  ...queryArr,
68
68
  `${key}=${encodeURIComponent(v)}`
@@ -86,15 +86,16 @@
86
86
  const query = {};
87
87
  if (search) {
88
88
  Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
89
- let [key, value] = v.split("=");
90
- value = flatten(value);
91
- query[key] = typeof options$.parse === "function" ? options$.parse(value) : value;
89
+ const [key, value] = v.split("=");
90
+ const value$ = flatten(value);
91
+ query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
92
92
  });
93
93
  }
94
- const sIndex = prefix.indexOf("/");
94
+ const pIndex = prefix.indexOf("://");
95
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
95
96
  return {
96
97
  origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
97
- path: prefix.slice(sIndex),
98
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
98
99
  query
99
100
  };
100
101
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/helper-route",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,6 +19,6 @@
19
19
  "access": "public"
20
20
  },
21
21
  "dependencies": {
22
- "@deot/helper-utils": "^1.1.3"
22
+ "@deot/helper-utils": "^1.1.4"
23
23
  }
24
24
  }