@ray-js/location 1.4.0-alpha.1 → 1.4.0-alpha.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/lib/location.js +18 -23
  2. package/package.json +19 -19
package/lib/location.js CHANGED
@@ -1,15 +1,13 @@
1
- import "core-js/modules/es.object.define-properties.js";
2
- import "core-js/modules/es.regexp.exec.js";
3
1
  import "core-js/modules/es.string.replace.js";
4
- import "core-js/modules/es.string.search.js";
5
2
  import { url } from '@ray-js/library';
6
3
  import router from '@ray-js/router';
4
+
7
5
  /**
8
6
  * 跨平台全局 location 对象,惰性获取,读取时再进行页面路径计算,性能较低
9
7
  * 小程序原生 NavBar 跳转的页面无法预先进行设置,所以仅支持在读取可用
10
8
  */
11
9
 
12
- var location = {
10
+ const location = {
13
11
  href: '',
14
12
  hash: '',
15
13
  host: '',
@@ -21,95 +19,92 @@ var location = {
21
19
  query: {},
22
20
  search: '',
23
21
  basename: '/' // 只用于web端
24
-
25
22
  };
23
+
26
24
  Object.defineProperties(location, {
27
25
  href: {
28
26
  enumerable: true,
29
27
  configurable: false,
30
- get: function get() {
28
+ get() {
31
29
  return router.href;
32
30
  }
33
31
  },
34
32
  hash: {
35
33
  enumerable: true,
36
34
  configurable: false,
37
- get: function get() {
38
- var q = url.parse(router.href);
35
+ get() {
36
+ const q = url.parse(router.href);
39
37
  return q.hash;
40
38
  }
41
39
  },
42
40
  host: {
43
41
  enumerable: true,
44
42
  configurable: false,
45
- get: function get() {
43
+ get() {
46
44
  return url.parse(this.href).host;
47
45
  }
48
46
  },
49
47
  hostname: {
50
48
  enumerable: true,
51
49
  configurable: false,
52
- get: function get() {
50
+ get() {
53
51
  return url.parse(this.href).hostname;
54
52
  }
55
53
  },
56
54
  pathname: {
57
55
  enumerable: true,
58
56
  configurable: false,
59
- get: function get() {
57
+ get() {
60
58
  // pathname 不需要basename前缀
61
- var basename = this.basename;
62
- var pathname = url.parse(this.href).pathname;
63
-
59
+ const basename = this.basename;
60
+ const pathname = url.parse(this.href).pathname;
64
61
  if (basename !== '/') {
65
62
  return pathname.replace(basename, '');
66
63
  }
67
-
68
64
  return pathname;
69
65
  }
70
66
  },
71
67
  port: {
72
68
  enumerable: true,
73
69
  configurable: false,
74
- get: function get() {
70
+ get() {
75
71
  return url.parse(this.href).port;
76
72
  }
77
73
  },
78
74
  protocol: {
79
75
  enumerable: true,
80
76
  configurable: false,
81
- get: function get() {
77
+ get() {
82
78
  return url.parse(this.href).protocol;
83
79
  }
84
80
  },
85
81
  search: {
86
82
  enumerable: true,
87
83
  configurable: false,
88
- get: function get() {
84
+ get() {
89
85
  return url.parse(this.href).search;
90
86
  }
91
87
  },
92
88
  query: {
93
89
  enumerable: true,
94
90
  configurable: false,
95
- get: function get() {
91
+ get() {
96
92
  return url.parse(this.href).query;
97
93
  }
98
94
  },
99
95
  params: {
100
96
  enumerable: true,
101
97
  configurable: false,
102
- get: function get() {
103
- var page = router.scheduler.getMatchedPage(this.pathname);
98
+ get() {
99
+ const page = router.scheduler.getMatchedPage(this.pathname);
104
100
  return (page === null || page === void 0 ? void 0 : page.params) || {};
105
101
  }
106
102
  },
107
103
  basename: {
108
104
  enumerable: true,
109
105
  configurable: false,
110
- get: function get() {
106
+ get() {
111
107
  var _router$scheduler$bas;
112
-
113
108
  // 小程序中没有basename
114
109
  return ((_router$scheduler$bas = router.scheduler.basename) !== null && _router$scheduler$bas !== void 0 ? _router$scheduler$bas : '/') || '/';
115
110
  }
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
1
  {
2
2
  "name": "@ray-js/location",
3
- "version": "1.4.0-alpha.1",
3
+ "version": "1.4.0-alpha.11",
4
4
  "description": "Ray Core",
5
5
  "keywords": [
6
6
  "ray"
7
7
  ],
8
+ "repository": {},
8
9
  "license": "MIT",
10
+ "maintainers": [
11
+ {
12
+ "name": "tuyafe",
13
+ "email": "tuyafe@tuya.com"
14
+ }
15
+ ],
9
16
  "main": "lib/index.js",
10
17
  "files": [
11
18
  "lib"
12
19
  ],
13
- "publishConfig": {
14
- "access": "public",
15
- "registry": "https://registry.npmjs.org"
16
- },
17
20
  "scripts": {
18
- "clean": "rm -rf lib",
19
21
  "build": "ray build --type=component --transform-mode=pure",
22
+ "clean": "rm -rf lib",
20
23
  "watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
21
24
  },
22
25
  "dependencies": {
23
- "@ray-js/library": "^1.4.0-alpha.1",
24
- "@ray-js/router": "^1.4.0-alpha.1",
25
- "@ray-js/router-mp": "^1.4.0-alpha.1"
26
+ "@ray-js/library": "^1.4.0-alpha.11",
27
+ "@ray-js/router": "^1.4.0-alpha.11",
28
+ "@ray-js/router-mp": "^1.4.0-alpha.11"
26
29
  },
27
30
  "devDependencies": {
28
- "@ray-js/cli": "^1.4.0-alpha.1",
29
- "@ray-js/types": "^1.4.0-alpha.1"
31
+ "@ray-js/cli": "^1.4.0-alpha.11",
32
+ "@ray-js/types": "^1.4.0-alpha.11"
30
33
  },
31
- "maintainers": [
32
- {
33
- "name": "tuyafe",
34
- "email": "tuyafe@tuya.com"
35
- }
36
- ],
37
- "gitHead": "4340240aafe16c03853241e2356134610e65443e",
38
- "repository": {}
34
+ "publishConfig": {
35
+ "access": "public",
36
+ "registry": "https://registry.npmjs.org"
37
+ },
38
+ "gitHead": "5e9c8e1d288eeaf707d34515399784d98ec13a1e"
39
39
  }