@ray-js/library 1.4.0-alpha.1 → 1.4.0-alpha.10

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.
@@ -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
- var NamedRegexp = /*#__PURE__*/function () {
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
- var regex = options.regex,
23
- groups = options.groups;
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
- _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;
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
- 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);
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
- var queryParse = searchParse;
6
+ const queryParse = searchParse;
7
7
  export { parse, format, queryStringify, params, searchParse, queryParse };
8
8
  export default {
9
- parse: parse,
10
- format: format,
11
- queryStringify: queryStringify,
12
- queryParse: queryParse,
13
- params: params,
14
- searchParse: 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
- var _excluded = ["query"];
4
- import "core-js/modules/es.array.concat.js";
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
- var _parse = parse(url),
17
- query = _parse.query,
18
- rest = _objectWithoutProperties(_parse, _excluded);
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.apply(void 0, [query].concat(args))
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
- 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";
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
- var URL_REGEX = new NamedRegexp({
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
- var _ref = URL_REGEX.exec(href) || {
14
+ const {
15
+ groups = {}
16
+ } = URL_REGEX.exec(href) || {
20
17
  groups: {}
21
- },
22
- _ref$groups = _ref.groups,
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
- var pathname = groups.pathname,
32
- restGroups = _objectWithoutProperties(groups, _excluded);
33
-
34
- var res = _objectSpread({
24
+ const {
25
+ pathname
26
+ } = groups,
27
+ restGroups = _objectWithoutProperties(groups, _excluded);
28
+ const res = _objectSpread({
35
29
  query: {},
36
- href: 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
- var _searchParse = searchParse(groups.search),
45
- ____h_a_s_h____ = _searchParse.____h_a_s_h____,
46
- query = _objectWithoutProperties(_searchParse, _excluded2);
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: 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
- 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
-
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
- keys.forEach(function (key) {
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('&'));
@@ -1,40 +1,25 @@
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";
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
- 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('=') : '';
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
- var query = {};
17
+ const query = {};
29
18
  if (!search) return query;
30
19
  search = search.replace(/^\?/, ''); // 移除首字符 问号
31
20
 
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
-
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,36 +1,36 @@
1
1
  {
2
2
  "name": "@ray-js/library",
3
- "version": "1.4.0-alpha.1",
3
+ "version": "1.4.0-alpha.10",
4
4
  "description": "Ray library for browser",
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
26
  "merge": "^2.1.1"
24
27
  },
25
28
  "devDependencies": {
26
- "@ray-js/cli": "^1.4.0-alpha.1"
29
+ "@ray-js/cli": "^1.4.0-alpha.10"
27
30
  },
28
- "maintainers": [
29
- {
30
- "name": "tuyafe",
31
- "email": "tuyafe@tuya.com"
32
- }
33
- ],
34
- "gitHead": "4340240aafe16c03853241e2356134610e65443e",
35
- "repository": {}
31
+ "publishConfig": {
32
+ "access": "public",
33
+ "registry": "https://registry.npmjs.org"
34
+ },
35
+ "gitHead": "14cb935df10f020e714b44bb41d4899646db751c"
36
36
  }
package/LICENSE.md DELETED
@@ -1,9 +0,0 @@
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.