@ray-js/location 1.3.21 → 1.3.23
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/LICENSE.md +9 -0
- package/lib/location.js +18 -24
- package/package.json +7 -7
package/LICENSE.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Copyright © 2014-2022 Tuya.inc
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/lib/location.js
CHANGED
@@ -1,15 +1,12 @@
|
|
1
|
-
import "core-js/modules/es.object.define-properties.js";
|
2
|
-
import "core-js/modules/es.regexp.exec.js";
|
3
|
-
import "core-js/modules/es.string.replace.js";
|
4
|
-
import "core-js/modules/es.string.search.js";
|
5
1
|
import { url } from '@ray-js/library';
|
6
2
|
import router from '@ray-js/router';
|
3
|
+
|
7
4
|
/**
|
8
5
|
* 跨平台全局 location 对象,惰性获取,读取时再进行页面路径计算,性能较低
|
9
6
|
* 小程序原生 NavBar 跳转的页面无法预先进行设置,所以仅支持在读取可用
|
10
7
|
*/
|
11
8
|
|
12
|
-
|
9
|
+
const location = {
|
13
10
|
href: '',
|
14
11
|
hash: '',
|
15
12
|
host: '',
|
@@ -21,95 +18,92 @@ var location = {
|
|
21
18
|
query: {},
|
22
19
|
search: '',
|
23
20
|
basename: '/' // 只用于web端
|
24
|
-
|
25
21
|
};
|
22
|
+
|
26
23
|
Object.defineProperties(location, {
|
27
24
|
href: {
|
28
25
|
enumerable: true,
|
29
26
|
configurable: false,
|
30
|
-
get
|
27
|
+
get() {
|
31
28
|
return router.href;
|
32
29
|
}
|
33
30
|
},
|
34
31
|
hash: {
|
35
32
|
enumerable: true,
|
36
33
|
configurable: false,
|
37
|
-
get
|
38
|
-
|
34
|
+
get() {
|
35
|
+
const q = url.parse(router.href);
|
39
36
|
return q.hash;
|
40
37
|
}
|
41
38
|
},
|
42
39
|
host: {
|
43
40
|
enumerable: true,
|
44
41
|
configurable: false,
|
45
|
-
get
|
42
|
+
get() {
|
46
43
|
return url.parse(this.href).host;
|
47
44
|
}
|
48
45
|
},
|
49
46
|
hostname: {
|
50
47
|
enumerable: true,
|
51
48
|
configurable: false,
|
52
|
-
get
|
49
|
+
get() {
|
53
50
|
return url.parse(this.href).hostname;
|
54
51
|
}
|
55
52
|
},
|
56
53
|
pathname: {
|
57
54
|
enumerable: true,
|
58
55
|
configurable: false,
|
59
|
-
get
|
56
|
+
get() {
|
60
57
|
// pathname 不需要basename前缀
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
const basename = this.basename;
|
59
|
+
const pathname = url.parse(this.href).pathname;
|
64
60
|
if (basename !== '/') {
|
65
61
|
return pathname.replace(basename, '');
|
66
62
|
}
|
67
|
-
|
68
63
|
return pathname;
|
69
64
|
}
|
70
65
|
},
|
71
66
|
port: {
|
72
67
|
enumerable: true,
|
73
68
|
configurable: false,
|
74
|
-
get
|
69
|
+
get() {
|
75
70
|
return url.parse(this.href).port;
|
76
71
|
}
|
77
72
|
},
|
78
73
|
protocol: {
|
79
74
|
enumerable: true,
|
80
75
|
configurable: false,
|
81
|
-
get
|
76
|
+
get() {
|
82
77
|
return url.parse(this.href).protocol;
|
83
78
|
}
|
84
79
|
},
|
85
80
|
search: {
|
86
81
|
enumerable: true,
|
87
82
|
configurable: false,
|
88
|
-
get
|
83
|
+
get() {
|
89
84
|
return url.parse(this.href).search;
|
90
85
|
}
|
91
86
|
},
|
92
87
|
query: {
|
93
88
|
enumerable: true,
|
94
89
|
configurable: false,
|
95
|
-
get
|
90
|
+
get() {
|
96
91
|
return url.parse(this.href).query;
|
97
92
|
}
|
98
93
|
},
|
99
94
|
params: {
|
100
95
|
enumerable: true,
|
101
96
|
configurable: false,
|
102
|
-
get
|
103
|
-
|
97
|
+
get() {
|
98
|
+
const page = router.scheduler.getMatchedPage(this.pathname);
|
104
99
|
return (page === null || page === void 0 ? void 0 : page.params) || {};
|
105
100
|
}
|
106
101
|
},
|
107
102
|
basename: {
|
108
103
|
enumerable: true,
|
109
104
|
configurable: false,
|
110
|
-
get
|
105
|
+
get() {
|
111
106
|
var _router$scheduler$bas;
|
112
|
-
|
113
107
|
// 小程序中没有basename
|
114
108
|
return ((_router$scheduler$bas = router.scheduler.basename) !== null && _router$scheduler$bas !== void 0 ? _router$scheduler$bas : '/') || '/';
|
115
109
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ray-js/location",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.23",
|
4
4
|
"description": "Ray Core",
|
5
5
|
"keywords": [
|
6
6
|
"ray"
|
@@ -20,13 +20,13 @@
|
|
20
20
|
"watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
|
21
21
|
},
|
22
22
|
"dependencies": {
|
23
|
-
"@ray-js/library": "1.3.
|
24
|
-
"@ray-js/router": "1.3.
|
25
|
-
"@ray-js/router-mp": "1.3.
|
23
|
+
"@ray-js/library": "1.3.23",
|
24
|
+
"@ray-js/router": "1.3.23",
|
25
|
+
"@ray-js/router-mp": "1.3.23"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
|
-
"@ray-js/cli": "1.3.
|
29
|
-
"@ray-js/types": "1.3.
|
28
|
+
"@ray-js/cli": "1.3.23",
|
29
|
+
"@ray-js/types": "1.3.23"
|
30
30
|
},
|
31
31
|
"maintainers": [
|
32
32
|
{
|
@@ -34,6 +34,6 @@
|
|
34
34
|
"email": "tuyafe@tuya.com"
|
35
35
|
}
|
36
36
|
],
|
37
|
-
"gitHead": "
|
37
|
+
"gitHead": "04708bb394d817a7a522fcde178f19f170d5d364",
|
38
38
|
"repository": {}
|
39
39
|
}
|