@ray-js/library 1.2.0-beta.1 → 1.3.0-beta.0

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