@deot/helper-route 1.1.8 → 1.1.9

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/dist/index.cjs CHANGED
@@ -1,72 +1,61 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const helperUtils = require('@deot/helper-utils');
6
-
7
- const get = (key, url, options) => {
8
- const options$ = {
9
- parse: helperUtils.flattenJSONParse,
10
- ...typeof url === "object" ? url : { url },
11
- ...options
12
- };
13
- const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
14
- const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
15
- let value = match != null ? match[2] : null;
16
- if (value === null) return null;
17
- value = helperUtils.flatten(value);
18
- return typeof options$.parse === "function" ? options$.parse(value) : value;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _deot_helper_utils = require("@deot/helper-utils");
3
+ //#region packages/route/src/get.ts
4
+ var get = (key, url, options) => {
5
+ const options$ = {
6
+ parse: _deot_helper_utils.flattenJSONParse,
7
+ ...typeof url === "object" ? url : { url },
8
+ ...options
9
+ };
10
+ const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
11
+ const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
12
+ let value = match != null ? match[2] : null;
13
+ if (value === null) return null;
14
+ value = (0, _deot_helper_utils.flatten)(value);
15
+ return typeof options$.parse === "function" ? options$.parse(value) : value;
19
16
  };
20
-
21
- const merge = (route) => {
22
- const {
23
- origin = "",
24
- path = "",
25
- query
26
- } = route;
27
- let result = origin;
28
- result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
29
- let queryArr = [];
30
- for (const key in query) {
31
- if (query[key] || query[key] === false || query[key] === 0) {
32
- const v = helperUtils.flatten(query[key]);
33
- queryArr = [
34
- ...queryArr,
35
- `${key}=${encodeURIComponent(v)}`
36
- ];
37
- }
38
- }
39
- if (queryArr.length > 0) {
40
- result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
41
- }
42
- return result;
17
+ //#endregion
18
+ //#region packages/route/src/merge.ts
19
+ var merge = (route) => {
20
+ const { origin = "", path = "", query } = route;
21
+ let result = origin;
22
+ result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
23
+ let queryArr = [];
24
+ for (const key in query) if (query[key] || query[key] === false || query[key] === 0) {
25
+ const v = (0, _deot_helper_utils.flatten)(query[key]);
26
+ queryArr = [...queryArr, `${key}=${encodeURIComponent(v)}`];
27
+ }
28
+ if (queryArr.length > 0) result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
29
+ return result;
43
30
  };
44
-
45
- const parse = (url, options) => {
46
- const options$ = {
47
- parse: helperUtils.flattenJSONParse,
48
- ...typeof url === "object" ? url : { url },
49
- ...options
50
- };
51
- const url$ = options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`);
52
- const [prefix, search] = url$.split("?");
53
- const query = {};
54
- if (search) {
55
- Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
56
- const [key, value] = v.split("=");
57
- const value$ = helperUtils.flatten(value);
58
- query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
59
- });
60
- }
61
- const pIndex = prefix.indexOf("://");
62
- const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
63
- return {
64
- origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
65
- path: sIndex !== -1 ? prefix.slice(sIndex) : "",
66
- query
67
- };
31
+ //#endregion
32
+ //#region packages/route/src/parse.ts
33
+ /**
34
+ * https://www.30secondsofcode.org/js/s/get-url-parameters/
35
+ * https://www.30secondsofcode.org/js/s/query-string-to-object/
36
+ */
37
+ var parse = (url, options) => {
38
+ const options$ = {
39
+ parse: _deot_helper_utils.flattenJSONParse,
40
+ ...typeof url === "object" ? url : { url },
41
+ ...options
42
+ };
43
+ const [prefix, search] = (options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`)).split("?");
44
+ const query = {};
45
+ if (search) Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
46
+ const [key, value] = v.split("=");
47
+ const value$ = (0, _deot_helper_utils.flatten)(value);
48
+ query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
49
+ });
50
+ const pIndex = prefix.indexOf("://");
51
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
52
+ return {
53
+ origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
54
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
55
+ query
56
+ };
68
57
  };
69
-
58
+ //#endregion
70
59
  exports.get = get;
71
60
  exports.merge = merge;
72
61
  exports.parse = parse;
@@ -1,106 +1,102 @@
1
- var HelperRoute = (function (exports) {
2
- 'use strict';
3
-
4
- const flatten = (value, parser, exit) => {
5
- let need = true;
6
- let safeCount = 1;
7
- let parseValue = value;
8
- while (need) {
9
- if (safeCount > 1e3) {
10
- throw new Error(value);
11
- }
12
- try {
13
- const next = (parser || decodeURIComponent)(parseValue);
14
- if (parseValue === next || typeof exit === "function" && exit(next)) {
15
- need = false;
16
- }
17
- parseValue = next;
18
- } catch (_) {
19
- need = false;
20
- }
21
- safeCount++;
22
- }
23
- return parseValue;
24
- };
25
-
26
- const flattenJSONParse = (value) => {
27
- if (value === null) return null;
28
- const regex = /^\d+$/;
29
- if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
30
- return value;
31
- }
32
- return flatten(value, JSON.parse);
33
- };
34
-
35
- const get = (key, url, options) => {
36
- const options$ = {
37
- parse: flattenJSONParse,
38
- ...typeof url === "object" ? url : { url },
39
- ...options
40
- };
41
- const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
42
- const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
43
- let value = match != null ? match[2] : null;
44
- if (value === null) return null;
45
- value = flatten(value);
46
- return typeof options$.parse === "function" ? options$.parse(value) : value;
47
- };
48
-
49
- const merge = (route) => {
50
- const {
51
- origin = "",
52
- path = "",
53
- query
54
- } = route;
55
- let result = origin;
56
- result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
57
- let queryArr = [];
58
- for (const key in query) {
59
- if (query[key] || query[key] === false || query[key] === 0) {
60
- const v = flatten(query[key]);
61
- queryArr = [
62
- ...queryArr,
63
- `${key}=${encodeURIComponent(v)}`
64
- ];
65
- }
66
- }
67
- if (queryArr.length > 0) {
68
- result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
69
- }
70
- return result;
71
- };
72
-
73
- const parse = (url, options) => {
74
- const options$ = {
75
- parse: flattenJSONParse,
76
- ...typeof url === "object" ? url : { url },
77
- ...options
78
- };
79
- const url$ = options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`);
80
- const [prefix, search] = url$.split("?");
81
- const query = {};
82
- if (search) {
83
- Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
84
- const [key, value] = v.split("=");
85
- const value$ = flatten(value);
86
- query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
87
- });
88
- }
89
- const pIndex = prefix.indexOf("://");
90
- const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
91
- return {
92
- origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
93
- path: sIndex !== -1 ? prefix.slice(sIndex) : "",
94
- query
95
- };
96
- };
97
-
98
- exports.get = get;
99
- exports.merge = merge;
100
- exports.parse = parse;
101
-
102
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
103
-
104
- return exports;
105
-
1
+ var HelperRoute = (function(exports) {
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ +/* @__PURE__ */ new Date();
4
+ typeof window !== "undefined" && window.requestAnimationFrame;
5
+ typeof window !== "undefined" && window.cancelAnimationFrame;
6
+ typeof window !== "undefined" && window.requestIdleCallback;
7
+ typeof window !== "undefined" && window.cancelIdleCallback;
8
+ var flatten = (value, parser, exit) => {
9
+ let need = true;
10
+ let safeCount = 1;
11
+ let parseValue = value;
12
+ while (need) {
13
+ if (safeCount > 1e3) throw new Error(value);
14
+ try {
15
+ const next = (parser || decodeURIComponent)(parseValue);
16
+ if (parseValue === next || typeof exit === "function" && exit(next)) need = false;
17
+ parseValue = next;
18
+ } catch (_) {
19
+ need = false;
20
+ }
21
+ safeCount++;
22
+ }
23
+ return parseValue;
24
+ };
25
+ /**
26
+ * 格式转换
27
+ * '1' -> 1
28
+ * '{}' -> {}
29
+ * '9007199254740992' -> '9007199254740992'
30
+ * '9007199254740991' -> 9007199254740991
31
+ * @param value 输入
32
+ * @returns ~
33
+ */
34
+ var flattenJSONParse = (value) => {
35
+ if (value === null) return null;
36
+ if (/^\d+$/.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) return value;
37
+ return flatten(value, JSON.parse, (v) => typeof v === "object");
38
+ };
39
+ var ALPHA = "abcdefghijklmnopqrstuvwxyz";
40
+ ALPHA + ALPHA.toUpperCase() + "";
41
+ //#endregion
42
+ //#region packages/route/src/get.ts
43
+ var get = (key, url, options) => {
44
+ const options$ = {
45
+ parse: flattenJSONParse,
46
+ ...typeof url === "object" ? url : { url },
47
+ ...options
48
+ };
49
+ const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
50
+ const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
51
+ let value = match != null ? match[2] : null;
52
+ if (value === null) return null;
53
+ value = flatten(value);
54
+ return typeof options$.parse === "function" ? options$.parse(value) : value;
55
+ };
56
+ //#endregion
57
+ //#region packages/route/src/merge.ts
58
+ var merge = (route) => {
59
+ const { origin = "", path = "", query } = route;
60
+ let result = origin;
61
+ result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
62
+ let queryArr = [];
63
+ for (const key in query) if (query[key] || query[key] === false || query[key] === 0) {
64
+ const v = flatten(query[key]);
65
+ queryArr = [...queryArr, `${key}=${encodeURIComponent(v)}`];
66
+ }
67
+ if (queryArr.length > 0) result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
68
+ return result;
69
+ };
70
+ //#endregion
71
+ //#region packages/route/src/parse.ts
72
+ /**
73
+ * https://www.30secondsofcode.org/js/s/get-url-parameters/
74
+ * https://www.30secondsofcode.org/js/s/query-string-to-object/
75
+ */
76
+ var parse = (url, options) => {
77
+ const options$ = {
78
+ parse: flattenJSONParse,
79
+ ...typeof url === "object" ? url : { url },
80
+ ...options
81
+ };
82
+ const [prefix, search] = (options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`)).split("?");
83
+ const query = {};
84
+ if (search) Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
85
+ const [key, value] = v.split("=");
86
+ const value$ = flatten(value);
87
+ query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
88
+ });
89
+ const pIndex = prefix.indexOf("://");
90
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
91
+ return {
92
+ origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
93
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
94
+ query
95
+ };
96
+ };
97
+ //#endregion
98
+ exports.get = get;
99
+ exports.merge = merge;
100
+ exports.parse = parse;
101
+ return exports;
106
102
  })({});
package/dist/index.js CHANGED
@@ -1,66 +1,58 @@
1
- import { flatten, flattenJSONParse } from '@deot/helper-utils';
2
-
3
- const get = (key, url, options) => {
4
- const options$ = {
5
- parse: flattenJSONParse,
6
- ...typeof url === "object" ? url : { url },
7
- ...options
8
- };
9
- const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
10
- const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
11
- let value = match != null ? match[2] : null;
12
- if (value === null) return null;
13
- value = flatten(value);
14
- return typeof options$.parse === "function" ? options$.parse(value) : value;
1
+ import { flatten, flattenJSONParse } from "@deot/helper-utils";
2
+ //#region packages/route/src/get.ts
3
+ var get = (key, url, options) => {
4
+ const options$ = {
5
+ parse: flattenJSONParse,
6
+ ...typeof url === "object" ? url : { url },
7
+ ...options
8
+ };
9
+ const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
10
+ const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
11
+ let value = match != null ? match[2] : null;
12
+ if (value === null) return null;
13
+ value = flatten(value);
14
+ return typeof options$.parse === "function" ? options$.parse(value) : value;
15
15
  };
16
-
17
- const merge = (route) => {
18
- const {
19
- origin = "",
20
- path = "",
21
- query
22
- } = route;
23
- let result = origin;
24
- result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
25
- let queryArr = [];
26
- for (const key in query) {
27
- if (query[key] || query[key] === false || query[key] === 0) {
28
- const v = flatten(query[key]);
29
- queryArr = [
30
- ...queryArr,
31
- `${key}=${encodeURIComponent(v)}`
32
- ];
33
- }
34
- }
35
- if (queryArr.length > 0) {
36
- result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
37
- }
38
- return result;
16
+ //#endregion
17
+ //#region packages/route/src/merge.ts
18
+ var merge = (route) => {
19
+ const { origin = "", path = "", query } = route;
20
+ let result = origin;
21
+ result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
22
+ let queryArr = [];
23
+ for (const key in query) if (query[key] || query[key] === false || query[key] === 0) {
24
+ const v = flatten(query[key]);
25
+ queryArr = [...queryArr, `${key}=${encodeURIComponent(v)}`];
26
+ }
27
+ if (queryArr.length > 0) result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
28
+ return result;
39
29
  };
40
-
41
- const parse = (url, options) => {
42
- const options$ = {
43
- parse: flattenJSONParse,
44
- ...typeof url === "object" ? url : { url },
45
- ...options
46
- };
47
- const url$ = options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`);
48
- const [prefix, search] = url$.split("?");
49
- const query = {};
50
- if (search) {
51
- Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
52
- const [key, value] = v.split("=");
53
- const value$ = flatten(value);
54
- query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
55
- });
56
- }
57
- const pIndex = prefix.indexOf("://");
58
- const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
59
- return {
60
- origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
61
- path: sIndex !== -1 ? prefix.slice(sIndex) : "",
62
- query
63
- };
30
+ //#endregion
31
+ //#region packages/route/src/parse.ts
32
+ /**
33
+ * https://www.30secondsofcode.org/js/s/get-url-parameters/
34
+ * https://www.30secondsofcode.org/js/s/query-string-to-object/
35
+ */
36
+ var parse = (url, options) => {
37
+ const options$ = {
38
+ parse: flattenJSONParse,
39
+ ...typeof url === "object" ? url : { url },
40
+ ...options
41
+ };
42
+ const [prefix, search] = (options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`)).split("?");
43
+ const query = {};
44
+ if (search) Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
45
+ const [key, value] = v.split("=");
46
+ const value$ = flatten(value);
47
+ query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
48
+ });
49
+ const pIndex = prefix.indexOf("://");
50
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
51
+ return {
52
+ origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
53
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
54
+ query
55
+ };
64
56
  };
65
-
57
+ //#endregion
66
58
  export { get, merge, parse };
@@ -1,107 +1,103 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.HelperRoute = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- const flatten = (value, parser, exit) => {
8
- let need = true;
9
- let safeCount = 1;
10
- let parseValue = value;
11
- while (need) {
12
- if (safeCount > 1e3) {
13
- throw new Error(value);
14
- }
15
- try {
16
- const next = (parser || decodeURIComponent)(parseValue);
17
- if (parseValue === next || typeof exit === "function" && exit(next)) {
18
- need = false;
19
- }
20
- parseValue = next;
21
- } catch (_) {
22
- need = false;
23
- }
24
- safeCount++;
25
- }
26
- return parseValue;
27
- };
28
-
29
- const flattenJSONParse = (value) => {
30
- if (value === null) return null;
31
- const regex = /^\d+$/;
32
- if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
33
- return value;
34
- }
35
- return flatten(value, JSON.parse);
36
- };
37
-
38
- const get = (key, url, options) => {
39
- const options$ = {
40
- parse: flattenJSONParse,
41
- ...typeof url === "object" ? url : { url },
42
- ...options
43
- };
44
- const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
45
- const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
46
- let value = match != null ? match[2] : null;
47
- if (value === null) return null;
48
- value = flatten(value);
49
- return typeof options$.parse === "function" ? options$.parse(value) : value;
50
- };
51
-
52
- const merge = (route) => {
53
- const {
54
- origin = "",
55
- path = "",
56
- query
57
- } = route;
58
- let result = origin;
59
- result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
60
- let queryArr = [];
61
- for (const key in query) {
62
- if (query[key] || query[key] === false || query[key] === 0) {
63
- const v = flatten(query[key]);
64
- queryArr = [
65
- ...queryArr,
66
- `${key}=${encodeURIComponent(v)}`
67
- ];
68
- }
69
- }
70
- if (queryArr.length > 0) {
71
- result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
72
- }
73
- return result;
74
- };
75
-
76
- const parse = (url, options) => {
77
- const options$ = {
78
- parse: flattenJSONParse,
79
- ...typeof url === "object" ? url : { url },
80
- ...options
81
- };
82
- const url$ = options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`);
83
- const [prefix, search] = url$.split("?");
84
- const query = {};
85
- if (search) {
86
- Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
87
- const [key, value] = v.split("=");
88
- const value$ = flatten(value);
89
- query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
90
- });
91
- }
92
- const pIndex = prefix.indexOf("://");
93
- const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
94
- return {
95
- origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
96
- path: sIndex !== -1 ? prefix.slice(sIndex) : "",
97
- query
98
- };
99
- };
100
-
101
- exports.get = get;
102
- exports.merge = merge;
103
- exports.parse = parse;
104
-
105
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
106
-
107
- }));
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.HelperRoute = {}));
3
+ })(this, function(exports) {
4
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
5
+ +/* @__PURE__ */ new Date();
6
+ typeof window !== "undefined" && window.requestAnimationFrame;
7
+ typeof window !== "undefined" && window.cancelAnimationFrame;
8
+ typeof window !== "undefined" && window.requestIdleCallback;
9
+ typeof window !== "undefined" && window.cancelIdleCallback;
10
+ var flatten = (value, parser, exit) => {
11
+ let need = true;
12
+ let safeCount = 1;
13
+ let parseValue = value;
14
+ while (need) {
15
+ if (safeCount > 1e3) throw new Error(value);
16
+ try {
17
+ const next = (parser || decodeURIComponent)(parseValue);
18
+ if (parseValue === next || typeof exit === "function" && exit(next)) need = false;
19
+ parseValue = next;
20
+ } catch (_) {
21
+ need = false;
22
+ }
23
+ safeCount++;
24
+ }
25
+ return parseValue;
26
+ };
27
+ /**
28
+ * 格式转换
29
+ * '1' -> 1
30
+ * '{}' -> {}
31
+ * '9007199254740992' -> '9007199254740992'
32
+ * '9007199254740991' -> 9007199254740991
33
+ * @param value 输入
34
+ * @returns ~
35
+ */
36
+ var flattenJSONParse = (value) => {
37
+ if (value === null) return null;
38
+ if (/^\d+$/.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) return value;
39
+ return flatten(value, JSON.parse, (v) => typeof v === "object");
40
+ };
41
+ var ALPHA = "abcdefghijklmnopqrstuvwxyz";
42
+ ALPHA + ALPHA.toUpperCase() + "";
43
+ //#endregion
44
+ //#region packages/route/src/get.ts
45
+ var get = (key, url, options) => {
46
+ const options$ = {
47
+ parse: flattenJSONParse,
48
+ ...typeof url === "object" ? url : { url },
49
+ ...options
50
+ };
51
+ const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
52
+ const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
53
+ let value = match != null ? match[2] : null;
54
+ if (value === null) return null;
55
+ value = flatten(value);
56
+ return typeof options$.parse === "function" ? options$.parse(value) : value;
57
+ };
58
+ //#endregion
59
+ //#region packages/route/src/merge.ts
60
+ var merge = (route) => {
61
+ const { origin = "", path = "", query } = route;
62
+ let result = origin;
63
+ result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
64
+ let queryArr = [];
65
+ for (const key in query) if (query[key] || query[key] === false || query[key] === 0) {
66
+ const v = flatten(query[key]);
67
+ queryArr = [...queryArr, `${key}=${encodeURIComponent(v)}`];
68
+ }
69
+ if (queryArr.length > 0) result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
70
+ return result;
71
+ };
72
+ //#endregion
73
+ //#region packages/route/src/parse.ts
74
+ /**
75
+ * https://www.30secondsofcode.org/js/s/get-url-parameters/
76
+ * https://www.30secondsofcode.org/js/s/query-string-to-object/
77
+ */
78
+ var parse = (url, options) => {
79
+ const options$ = {
80
+ parse: flattenJSONParse,
81
+ ...typeof url === "object" ? url : { url },
82
+ ...options
83
+ };
84
+ const [prefix, search] = (options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`)).split("?");
85
+ const query = {};
86
+ if (search) Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
87
+ const [key, value] = v.split("=");
88
+ const value$ = flatten(value);
89
+ query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
90
+ });
91
+ const pIndex = prefix.indexOf("://");
92
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
93
+ return {
94
+ origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
95
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
96
+ query
97
+ };
98
+ };
99
+ //#endregion
100
+ exports.get = get;
101
+ exports.merge = merge;
102
+ exports.parse = parse;
103
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/helper-route",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
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.7"
22
+ "@deot/helper-utils": "^1.1.8"
23
23
  }
24
24
  }