@deot/helper-route 1.0.1
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 +92 -0
- package/dist/index.cjs.js +72 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.es.js +66 -0
- package/dist/index.iife.js +125 -0
- package/dist/index.umd.js +126 -0
- package/package.json +24 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @deot/helper-route
|
|
2
|
+
|
|
3
|
+
### `Route`
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import * as Route from "@deot/helper-route";
|
|
7
|
+
|
|
8
|
+
// or
|
|
9
|
+
import { Route } from "@deot/helper";
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
#### `merge`
|
|
15
|
+
|
|
16
|
+
`Route.merge(route: object, options: object)`
|
|
17
|
+
|
|
18
|
+
基于规则构建新的url
|
|
19
|
+
|
|
20
|
+
+ **route**: 路由规则
|
|
21
|
+
+ **options**: 可配置参数
|
|
22
|
+
|
|
23
|
+
*rule:* 规则:
|
|
24
|
+
+ **path**: *string, string[]* 路径
|
|
25
|
+
+ **query**: *object* 参数
|
|
26
|
+
|
|
27
|
+
**示例**
|
|
28
|
+
```js
|
|
29
|
+
Route.merge({
|
|
30
|
+
// path: '/home',
|
|
31
|
+
path: ['/', 'home'],
|
|
32
|
+
query: { name: 'wya-team' }
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
#### `parse`
|
|
39
|
+
|
|
40
|
+
`Route.parse(url: string, options: object)`
|
|
41
|
+
|
|
42
|
+
解析当前路由 -> `{ query: {}, path: [] }`
|
|
43
|
+
|
|
44
|
+
+ **url**: 路径,默认值:当前路由
|
|
45
|
+
+ **options**: 可配置参数
|
|
46
|
+
|
|
47
|
+
**示例**
|
|
48
|
+
```js
|
|
49
|
+
Route.parse();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
#### `get`
|
|
55
|
+
|
|
56
|
+
`Route.get(key: string, url: string, options: object)`
|
|
57
|
+
|
|
58
|
+
设置版本号
|
|
59
|
+
|
|
60
|
+
+ **key**: 参数键值
|
|
61
|
+
+ **url**: 路径,默认值:当前路由
|
|
62
|
+
+ **options**: 可配置参数
|
|
63
|
+
|
|
64
|
+
**示例**
|
|
65
|
+
```javascript
|
|
66
|
+
Route.get('name');
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 约定
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
let url = `?a=${encodeURIComponent('&')}`; // '?a=%26'
|
|
73
|
+
|
|
74
|
+
decodeURIComponent(url); // a=&
|
|
75
|
+
|
|
76
|
+
encodeURIComponent(url); // '%3Fa%3D%2526'
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- 期望: `{ a: '&' }`
|
|
80
|
+
- 实际: `{ a: '' }`
|
|
81
|
+
|
|
82
|
+
为了避免该情况,内部对`url`不直接`decodeURIComponent`, 仅当对值进行`decodeURIComponent`. 所以`%3Fa%3D%2526`是无效的;
|
|
83
|
+
|
|
84
|
+
`merge`调用时,`value`的值会被`decodeURIComponent`
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
get('a', '?a=%26'); // &
|
|
88
|
+
|
|
89
|
+
merge({ query: { a: '&' } }); // ?a=%26
|
|
90
|
+
|
|
91
|
+
parse('?a=%26'); // query.a === '&' (true)
|
|
92
|
+
```
|
|
@@ -0,0 +1,72 @@
|
|
|
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)
|
|
17
|
+
return null;
|
|
18
|
+
value = helperUtils.flattenDecodeURIComponent(value);
|
|
19
|
+
return typeof options$.parse === "function" ? options$.parse(value) : value;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const merge = (route) => {
|
|
23
|
+
const {
|
|
24
|
+
origin = "",
|
|
25
|
+
path = "",
|
|
26
|
+
query
|
|
27
|
+
} = route;
|
|
28
|
+
let result = origin;
|
|
29
|
+
result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
|
|
30
|
+
let queryArr = [];
|
|
31
|
+
for (let key in query) {
|
|
32
|
+
if (query[key] || query[key] === false || query[key] === 0) {
|
|
33
|
+
let v = helperUtils.flattenDecodeURIComponent(query[key]);
|
|
34
|
+
queryArr = [
|
|
35
|
+
...queryArr,
|
|
36
|
+
`${key}=${encodeURIComponent(v)}`
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (queryArr.length > 0) {
|
|
41
|
+
result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const parse = (url, options) => {
|
|
47
|
+
const options$ = {
|
|
48
|
+
parse: helperUtils.flattenJSONParse,
|
|
49
|
+
...typeof url === "object" ? url : { url },
|
|
50
|
+
...options
|
|
51
|
+
};
|
|
52
|
+
const url$ = options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`);
|
|
53
|
+
const [prefix, search] = url$.split("?");
|
|
54
|
+
const query = {};
|
|
55
|
+
if (search) {
|
|
56
|
+
Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
|
|
57
|
+
let [key, value] = v.split("=");
|
|
58
|
+
value = helperUtils.flattenDecodeURIComponent(value);
|
|
59
|
+
query[key] = typeof options$.parse === "function" ? options$.parse(value) : value;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const sIndex = prefix.indexOf("/");
|
|
63
|
+
return {
|
|
64
|
+
origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
|
|
65
|
+
path: prefix.slice(sIndex),
|
|
66
|
+
query
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.get = get;
|
|
71
|
+
exports.merge = merge;
|
|
72
|
+
exports.parse = parse;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const get: (key: string, url?: string | GetOptions, options?: GetOptions) => any;
|
|
2
|
+
|
|
3
|
+
declare interface GetOptions {
|
|
4
|
+
url?: string;
|
|
5
|
+
parse?: boolean | ((v: string) => any);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare const merge: (route: Route) => string;
|
|
9
|
+
|
|
10
|
+
export declare const parse: (url?: string | ParseOptions, options?: ParseOptions) => {
|
|
11
|
+
origin: string;
|
|
12
|
+
path: string;
|
|
13
|
+
query: {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
declare interface ParseOptions {
|
|
19
|
+
url?: string;
|
|
20
|
+
parse?: boolean | ((v: string) => any);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare interface Route {
|
|
24
|
+
origin?: string;
|
|
25
|
+
path?: string | string[];
|
|
26
|
+
query?: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { }
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { flattenJSONParse, flattenDecodeURIComponent } 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)
|
|
13
|
+
return null;
|
|
14
|
+
value = flattenDecodeURIComponent(value);
|
|
15
|
+
return typeof options$.parse === "function" ? options$.parse(value) : value;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const merge = (route) => {
|
|
19
|
+
const {
|
|
20
|
+
origin = "",
|
|
21
|
+
path = "",
|
|
22
|
+
query
|
|
23
|
+
} = route;
|
|
24
|
+
let result = origin;
|
|
25
|
+
result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
|
|
26
|
+
let queryArr = [];
|
|
27
|
+
for (let key in query) {
|
|
28
|
+
if (query[key] || query[key] === false || query[key] === 0) {
|
|
29
|
+
let v = flattenDecodeURIComponent(query[key]);
|
|
30
|
+
queryArr = [
|
|
31
|
+
...queryArr,
|
|
32
|
+
`${key}=${encodeURIComponent(v)}`
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (queryArr.length > 0) {
|
|
37
|
+
result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const parse = (url, options) => {
|
|
43
|
+
const options$ = {
|
|
44
|
+
parse: flattenJSONParse,
|
|
45
|
+
...typeof url === "object" ? url : { url },
|
|
46
|
+
...options
|
|
47
|
+
};
|
|
48
|
+
const url$ = options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`);
|
|
49
|
+
const [prefix, search] = url$.split("?");
|
|
50
|
+
const query = {};
|
|
51
|
+
if (search) {
|
|
52
|
+
Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
|
|
53
|
+
let [key, value] = v.split("=");
|
|
54
|
+
value = flattenDecodeURIComponent(value);
|
|
55
|
+
query[key] = typeof options$.parse === "function" ? options$.parse(value) : value;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const sIndex = prefix.indexOf("/");
|
|
59
|
+
return {
|
|
60
|
+
origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
|
|
61
|
+
path: prefix.slice(sIndex),
|
|
62
|
+
query
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { get, merge, parse };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var HelperRoute = (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const flattenDecodeURIComponent = (value) => {
|
|
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
|
+
let next = decodeURIComponent(parseValue);
|
|
14
|
+
if (parseValue === 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)
|
|
28
|
+
return null;
|
|
29
|
+
let regex = /^\d+$/;
|
|
30
|
+
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
let need = true;
|
|
34
|
+
let safeCount = 1;
|
|
35
|
+
let parseValue = value;
|
|
36
|
+
while (need) {
|
|
37
|
+
if (safeCount > 10) {
|
|
38
|
+
throw new Error(value);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
let next = JSON.parse(parseValue);
|
|
42
|
+
if (parseValue === next) {
|
|
43
|
+
need = false;
|
|
44
|
+
}
|
|
45
|
+
parseValue = next;
|
|
46
|
+
} catch {
|
|
47
|
+
need = false;
|
|
48
|
+
}
|
|
49
|
+
safeCount++;
|
|
50
|
+
}
|
|
51
|
+
return parseValue;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const get = (key, url, options) => {
|
|
55
|
+
const options$ = {
|
|
56
|
+
parse: flattenJSONParse,
|
|
57
|
+
...typeof url === "object" ? url : { url },
|
|
58
|
+
...options
|
|
59
|
+
};
|
|
60
|
+
const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
|
|
61
|
+
const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
|
|
62
|
+
let value = match != null ? match[2] : null;
|
|
63
|
+
if (value === null)
|
|
64
|
+
return null;
|
|
65
|
+
value = flattenDecodeURIComponent(value);
|
|
66
|
+
return typeof options$.parse === "function" ? options$.parse(value) : value;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const merge = (route) => {
|
|
70
|
+
const {
|
|
71
|
+
origin = "",
|
|
72
|
+
path = "",
|
|
73
|
+
query
|
|
74
|
+
} = route;
|
|
75
|
+
let result = origin;
|
|
76
|
+
result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
|
|
77
|
+
let queryArr = [];
|
|
78
|
+
for (let key in query) {
|
|
79
|
+
if (query[key] || query[key] === false || query[key] === 0) {
|
|
80
|
+
let v = flattenDecodeURIComponent(query[key]);
|
|
81
|
+
queryArr = [
|
|
82
|
+
...queryArr,
|
|
83
|
+
`${key}=${encodeURIComponent(v)}`
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (queryArr.length > 0) {
|
|
88
|
+
result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const parse = (url, options) => {
|
|
94
|
+
const options$ = {
|
|
95
|
+
parse: flattenJSONParse,
|
|
96
|
+
...typeof url === "object" ? url : { url },
|
|
97
|
+
...options
|
|
98
|
+
};
|
|
99
|
+
const url$ = options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`);
|
|
100
|
+
const [prefix, search] = url$.split("?");
|
|
101
|
+
const query = {};
|
|
102
|
+
if (search) {
|
|
103
|
+
Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
|
|
104
|
+
let [key, value] = v.split("=");
|
|
105
|
+
value = flattenDecodeURIComponent(value);
|
|
106
|
+
query[key] = typeof options$.parse === "function" ? options$.parse(value) : value;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const sIndex = prefix.indexOf("/");
|
|
110
|
+
return {
|
|
111
|
+
origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
|
|
112
|
+
path: prefix.slice(sIndex),
|
|
113
|
+
query
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
exports.get = get;
|
|
118
|
+
exports.merge = merge;
|
|
119
|
+
exports.parse = parse;
|
|
120
|
+
|
|
121
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
122
|
+
|
|
123
|
+
return exports;
|
|
124
|
+
|
|
125
|
+
})({});
|
|
@@ -0,0 +1,126 @@
|
|
|
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 flattenDecodeURIComponent = (value) => {
|
|
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
|
+
let next = decodeURIComponent(parseValue);
|
|
17
|
+
if (parseValue === 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)
|
|
31
|
+
return null;
|
|
32
|
+
let regex = /^\d+$/;
|
|
33
|
+
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
let need = true;
|
|
37
|
+
let safeCount = 1;
|
|
38
|
+
let parseValue = value;
|
|
39
|
+
while (need) {
|
|
40
|
+
if (safeCount > 10) {
|
|
41
|
+
throw new Error(value);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
let next = JSON.parse(parseValue);
|
|
45
|
+
if (parseValue === next) {
|
|
46
|
+
need = false;
|
|
47
|
+
}
|
|
48
|
+
parseValue = next;
|
|
49
|
+
} catch {
|
|
50
|
+
need = false;
|
|
51
|
+
}
|
|
52
|
+
safeCount++;
|
|
53
|
+
}
|
|
54
|
+
return parseValue;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const get = (key, url, options) => {
|
|
58
|
+
const options$ = {
|
|
59
|
+
parse: flattenJSONParse,
|
|
60
|
+
...typeof url === "object" ? url : { url },
|
|
61
|
+
...options
|
|
62
|
+
};
|
|
63
|
+
const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
|
|
64
|
+
const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
|
|
65
|
+
let value = match != null ? match[2] : null;
|
|
66
|
+
if (value === null)
|
|
67
|
+
return null;
|
|
68
|
+
value = flattenDecodeURIComponent(value);
|
|
69
|
+
return typeof options$.parse === "function" ? options$.parse(value) : value;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const merge = (route) => {
|
|
73
|
+
const {
|
|
74
|
+
origin = "",
|
|
75
|
+
path = "",
|
|
76
|
+
query
|
|
77
|
+
} = route;
|
|
78
|
+
let result = origin;
|
|
79
|
+
result += path instanceof Array ? path.length ? `/${path.join("/")}` : "" : path;
|
|
80
|
+
let queryArr = [];
|
|
81
|
+
for (let key in query) {
|
|
82
|
+
if (query[key] || query[key] === false || query[key] === 0) {
|
|
83
|
+
let v = flattenDecodeURIComponent(query[key]);
|
|
84
|
+
queryArr = [
|
|
85
|
+
...queryArr,
|
|
86
|
+
`${key}=${encodeURIComponent(v)}`
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (queryArr.length > 0) {
|
|
91
|
+
result += (result.indexOf("?") > -1 ? "&" : "?") + queryArr.join("&");
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const parse = (url, options) => {
|
|
97
|
+
const options$ = {
|
|
98
|
+
parse: flattenJSONParse,
|
|
99
|
+
...typeof url === "object" ? url : { url },
|
|
100
|
+
...options
|
|
101
|
+
};
|
|
102
|
+
const url$ = options$.url || (typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`);
|
|
103
|
+
const [prefix, search] = url$.split("?");
|
|
104
|
+
const query = {};
|
|
105
|
+
if (search) {
|
|
106
|
+
Array.from(search.match(/[^?=&]+=[^&]*/g) || []).forEach((v) => {
|
|
107
|
+
let [key, value] = v.split("=");
|
|
108
|
+
value = flattenDecodeURIComponent(value);
|
|
109
|
+
query[key] = typeof options$.parse === "function" ? options$.parse(value) : value;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const sIndex = prefix.indexOf("/");
|
|
113
|
+
return {
|
|
114
|
+
origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
|
|
115
|
+
path: prefix.slice(sIndex),
|
|
116
|
+
query
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
exports.get = get;
|
|
121
|
+
exports.merge = merge;
|
|
122
|
+
exports.parse = parse;
|
|
123
|
+
|
|
124
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
125
|
+
|
|
126
|
+
}));
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deot/helper-route",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "dist/index.cjs.js",
|
|
5
|
+
"module": "dist/index.es.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.es.js",
|
|
10
|
+
"require": "./dist/index.cjs.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@deot/helper-utils": "^1.0.1"
|
|
23
|
+
}
|
|
24
|
+
}
|