@ray-js/library 1.4.0-alpha.3 → 1.4.0-alpha.4
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/lib/regexp/NamedRegexp.js +20 -34
- package/lib/url/format.js +8 -14
- package/lib/url/index.js +7 -7
- package/lib/url/params.js +9 -9
- package/lib/url/parse.js +20 -28
- package/lib/url/queryStringify.js +8 -13
- package/lib/url/searchParse.js +7 -22
- package/package.json +3 -3
|
@@ -1,49 +1,35 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
4
|
-
import "core-js/modules/es.array.reduce.js";
|
|
5
|
-
import "core-js/modules/es.object.to-string.js";
|
|
6
|
-
|
|
7
1
|
/**
|
|
8
2
|
* 实现 Named Groups RegExp 的正则百表达式
|
|
9
3
|
* ECMA 2018 的实现
|
|
10
4
|
* 通过 new RegExp 运算符,无法被 babel 转义
|
|
11
5
|
*/
|
|
12
|
-
|
|
6
|
+
export default class NamedRegexp {
|
|
13
7
|
/**
|
|
14
8
|
* 创建 Named RegExp
|
|
15
9
|
* @param {object} options
|
|
16
10
|
* @param {RegExp} options.regex 正则
|
|
17
11
|
* @param {Array<String>} options.groups 分组
|
|
18
12
|
*/
|
|
19
|
-
function NamedRegexp(options) {
|
|
20
|
-
_classCallCheck(this, NamedRegexp);
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
constructor(options) {
|
|
15
|
+
const {
|
|
16
|
+
regex,
|
|
17
|
+
groups
|
|
18
|
+
} = options;
|
|
24
19
|
this.regex = regex;
|
|
25
20
|
this.groups = groups;
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
matches.groups = groups;
|
|
42
|
-
return matches;
|
|
43
|
-
}
|
|
44
|
-
}]);
|
|
45
|
-
|
|
46
|
-
return NamedRegexp;
|
|
47
|
-
}();
|
|
48
|
-
|
|
49
|
-
export { NamedRegexp as default };
|
|
22
|
+
exec(value) {
|
|
23
|
+
const matches = this.regex.exec(value);
|
|
24
|
+
if (!matches) return matches;
|
|
25
|
+
const groups = matches.reduce((result, match, index) => {
|
|
26
|
+
if (index > 0)
|
|
27
|
+
// This subtraction is required because we count
|
|
28
|
+
// match indexes from 1, because 0 is the entire matched string
|
|
29
|
+
result[this.groups[index - 1]] = match;
|
|
30
|
+
return result;
|
|
31
|
+
}, {});
|
|
32
|
+
matches.groups = groups;
|
|
33
|
+
return matches;
|
|
34
|
+
}
|
|
35
|
+
}
|
package/lib/url/format.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
3
|
-
import "core-js/modules/es.string.search.js";
|
|
4
|
-
import "core-js/modules/es.array.concat.js";
|
|
5
2
|
import queryStringify from './queryStringify';
|
|
6
3
|
import searchParse from './searchParse';
|
|
7
4
|
export default function format(attrs) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_attrs$search = attrs.search,
|
|
17
|
-
search = _attrs$search === void 0 ? '' : _attrs$search;
|
|
18
|
-
var searchQuery = searchParse(search);
|
|
5
|
+
const {
|
|
6
|
+
hash = '',
|
|
7
|
+
pathname = '',
|
|
8
|
+
origin = '',
|
|
9
|
+
query = {},
|
|
10
|
+
search = ''
|
|
11
|
+
} = attrs;
|
|
12
|
+
const searchQuery = searchParse(search);
|
|
19
13
|
return "".concat(origin).concat(pathname).concat(queryStringify(_objectSpread(_objectSpread({}, query), searchQuery))).concat(hash);
|
|
20
14
|
}
|
package/lib/url/index.js
CHANGED
|
@@ -3,13 +3,13 @@ import params from './params';
|
|
|
3
3
|
import parse from './parse';
|
|
4
4
|
import queryStringify from './queryStringify';
|
|
5
5
|
import searchParse from './searchParse';
|
|
6
|
-
|
|
6
|
+
const queryParse = searchParse;
|
|
7
7
|
export { parse, format, queryStringify, params, searchParse, queryParse };
|
|
8
8
|
export default {
|
|
9
|
-
parse
|
|
10
|
-
format
|
|
11
|
-
queryStringify
|
|
12
|
-
queryParse
|
|
13
|
-
params
|
|
14
|
-
searchParse
|
|
9
|
+
parse,
|
|
10
|
+
format,
|
|
11
|
+
queryStringify,
|
|
12
|
+
queryParse,
|
|
13
|
+
params,
|
|
14
|
+
searchParse
|
|
15
15
|
};
|
package/lib/url/params.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
-
|
|
4
|
-
import "core-js/modules/
|
|
3
|
+
const _excluded = ["query"];
|
|
4
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
5
5
|
import merge from 'merge';
|
|
6
6
|
import parse from './parse';
|
|
7
7
|
import format from './format';
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* 调整页面地址的 query
|
|
10
11
|
* @param url - url 地址
|
|
11
12
|
* @param args - 附加到 query 上的参数
|
|
12
13
|
* @returns
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
15
|
export default function params(url) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const _parse = parse(url),
|
|
17
|
+
{
|
|
18
|
+
query
|
|
19
|
+
} = _parse,
|
|
20
|
+
rest = _objectWithoutProperties(_parse, _excluded);
|
|
20
21
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
21
22
|
args[_key - 1] = arguments[_key];
|
|
22
23
|
}
|
|
23
|
-
|
|
24
24
|
return format(_objectSpread({
|
|
25
|
-
query: merge
|
|
25
|
+
query: merge(query, ...args)
|
|
26
26
|
}, rest));
|
|
27
27
|
}
|
package/lib/url/parse.js
CHANGED
|
@@ -1,61 +1,53 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
6
|
-
import "core-js/modules/es.object.to-string.js";
|
|
7
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
8
|
-
import "core-js/modules/es.object.keys.js";
|
|
9
|
-
import "core-js/modules/es.string.search.js";
|
|
3
|
+
const _excluded = ["pathname"],
|
|
4
|
+
_excluded2 = ["____h_a_s_h____"];
|
|
10
5
|
import { NamedRegexp } from '../regexp';
|
|
11
6
|
import searchParse from './searchParse';
|
|
12
7
|
import format from './format';
|
|
13
|
-
|
|
8
|
+
const URL_REGEX = new NamedRegexp({
|
|
14
9
|
regex: /(((?:http|https):)?(?:\/\/)?([^./]([^:/?#]*)(?::(\d+))?))?([^?#]+)?(\?[^#]*)?(#.*)?/,
|
|
15
10
|
groups: ['origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash']
|
|
16
11
|
});
|
|
17
12
|
export default function parse(href) {
|
|
18
13
|
/* istanbul ignore next */
|
|
19
|
-
|
|
14
|
+
const {
|
|
15
|
+
groups = {}
|
|
16
|
+
} = URL_REGEX.exec(href) || {
|
|
20
17
|
groups: {}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
groups = _ref$groups === void 0 ? {} : _ref$groups;
|
|
24
|
-
|
|
25
|
-
Object.keys(groups).forEach(function (key) {
|
|
18
|
+
};
|
|
19
|
+
Object.keys(groups).forEach(key => {
|
|
26
20
|
if (!groups[key]) {
|
|
27
21
|
groups[key] = '';
|
|
28
22
|
}
|
|
29
23
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
const {
|
|
25
|
+
pathname
|
|
26
|
+
} = groups,
|
|
27
|
+
restGroups = _objectWithoutProperties(groups, _excluded);
|
|
28
|
+
const res = _objectSpread({
|
|
35
29
|
query: {},
|
|
36
|
-
href
|
|
30
|
+
href,
|
|
37
31
|
pathname: pathname ? pathname : '/'
|
|
38
32
|
}, restGroups);
|
|
39
|
-
|
|
40
33
|
if (groups.search) {
|
|
41
34
|
// 小程序不能传递hash,用query.____h_a_s_h____传递
|
|
42
35
|
// 回显恢复____h_a_s_h____ ====> hash
|
|
43
36
|
// 从query中接出hash值
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
const _searchParse = searchParse(groups.search),
|
|
38
|
+
{
|
|
39
|
+
____h_a_s_h____
|
|
40
|
+
} = _searchParse,
|
|
41
|
+
query = _objectWithoutProperties(_searchParse, _excluded2);
|
|
48
42
|
res.query = query;
|
|
49
|
-
|
|
50
43
|
if (____h_a_s_h____) {
|
|
51
44
|
// 剔除 ____h_a_s_h____
|
|
52
45
|
res.hash = res.hash || "#".concat(____h_a_s_h____);
|
|
53
46
|
res.search = format({
|
|
54
|
-
query
|
|
47
|
+
query
|
|
55
48
|
});
|
|
56
49
|
res.href = format(res);
|
|
57
50
|
}
|
|
58
51
|
}
|
|
59
|
-
|
|
60
52
|
return res;
|
|
61
53
|
}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import "core-js/modules/es.object.keys.js";
|
|
2
|
-
import "core-js/modules/es.object.to-string.js";
|
|
3
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
4
|
-
import "core-js/modules/es.array.concat.js";
|
|
5
1
|
export default function queryStringify(query) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3
|
+
const {
|
|
4
|
+
prefix = true
|
|
5
|
+
} = options;
|
|
6
|
+
const search = [];
|
|
7
|
+
const keys = Object.keys(query);
|
|
12
8
|
if (keys.length === 0) {
|
|
13
9
|
return '';
|
|
14
10
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var value = query[key];
|
|
11
|
+
keys.forEach(key => {
|
|
12
|
+
const value = query[key];
|
|
18
13
|
search.push([key, value].join('='));
|
|
19
14
|
});
|
|
20
15
|
return "".concat(prefix ? '?' : '').concat(search.join('&'));
|
package/lib/url/searchParse.js
CHANGED
|
@@ -1,40 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _toArray from "@babel/runtime/helpers/esm/toArray";
|
|
3
|
-
import "core-js/modules/es.array.slice.js";
|
|
4
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
1
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
5
2
|
import "core-js/modules/es.string.replace.js";
|
|
6
|
-
import "core-js/modules/es.object.to-string.js";
|
|
7
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
8
|
-
|
|
9
3
|
/**
|
|
10
4
|
* 分割url search key value,返回 [key, value]
|
|
11
5
|
*/
|
|
12
6
|
function splitSearchKeyValue(str) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
key = _str$split2[0],
|
|
16
|
-
valueArr = _str$split2.slice(1);
|
|
17
|
-
|
|
18
|
-
var value = valueArr.length ? valueArr.join('=') : '';
|
|
7
|
+
const [key, ...valueArr] = str.split('=');
|
|
8
|
+
const value = valueArr.length ? valueArr.join('=') : '';
|
|
19
9
|
return [key, value];
|
|
20
10
|
}
|
|
11
|
+
|
|
21
12
|
/**
|
|
22
13
|
* 解析 url.search 返回对象类型
|
|
23
14
|
* @param search URL search 信息
|
|
24
15
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
16
|
export default function searchParse(search) {
|
|
28
|
-
|
|
17
|
+
const query = {};
|
|
29
18
|
if (!search) return query;
|
|
30
19
|
search = search.replace(/^\?/, ''); // 移除首字符 问号
|
|
31
20
|
|
|
32
|
-
search.split('&').forEach(
|
|
33
|
-
|
|
34
|
-
_splitSearchKeyValue2 = _slicedToArray(_splitSearchKeyValue, 2),
|
|
35
|
-
key = _splitSearchKeyValue2[0],
|
|
36
|
-
value = _splitSearchKeyValue2[1];
|
|
37
|
-
|
|
21
|
+
search.split('&').forEach(i => {
|
|
22
|
+
const [key, value] = splitSearchKeyValue(i);
|
|
38
23
|
query[key] = value;
|
|
39
24
|
});
|
|
40
25
|
return query;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/library",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.4",
|
|
4
4
|
"description": "Ray library for browser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ray"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"merge": "^2.1.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@ray-js/cli": "^1.4.0-alpha.
|
|
26
|
+
"@ray-js/cli": "^1.4.0-alpha.4"
|
|
27
27
|
},
|
|
28
28
|
"maintainers": [
|
|
29
29
|
{
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"email": "tuyafe@tuya.com"
|
|
32
32
|
}
|
|
33
33
|
],
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "ae3621a47944287771e18e926c76ea92d0516097",
|
|
35
35
|
"repository": {}
|
|
36
36
|
}
|