@ray-js/library 0.3.0-beta.1c347991
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/README.md +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/regexp/NamedRegexp.d.ts +24 -0
- package/lib/regexp/NamedRegexp.js +49 -0
- package/lib/regexp/index.d.ts +1 -0
- package/lib/regexp/index.js +1 -0
- package/lib/url/format.d.ts +2 -0
- package/lib/url/format.js +26 -0
- package/lib/url/index.d.ts +16 -0
- package/lib/url/index.js +15 -0
- package/lib/url/interface.d.ts +12 -0
- package/lib/url/interface.js +1 -0
- package/lib/url/params.d.ts +7 -0
- package/lib/url/params.js +26 -0
- package/lib/url/parse.d.ts +2 -0
- package/lib/url/parse.js +42 -0
- package/lib/url/queryStringify.d.ts +3 -0
- package/lib/url/queryStringify.js +22 -0
- package/lib/url/searchParse.d.ts +5 -0
- package/lib/url/searchParse.js +43 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @ray-js/library
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface ExecArray extends RegExpExecArray {
|
|
2
|
+
groups?: Record<string, string> | undefined;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* 实现 Named Groups RegExp 的正则百表达式
|
|
6
|
+
* ECMA 2018 的实现
|
|
7
|
+
* 通过 new RegExp 运算符,无法被 babel 转义
|
|
8
|
+
*/
|
|
9
|
+
export default class NamedRegexp {
|
|
10
|
+
regex: RegExp;
|
|
11
|
+
groups: string[];
|
|
12
|
+
/**
|
|
13
|
+
* 创建 Named RegExp
|
|
14
|
+
* @param {object} options
|
|
15
|
+
* @param {RegExp} options.regex 正则
|
|
16
|
+
* @param {Array<String>} options.groups 分组
|
|
17
|
+
*/
|
|
18
|
+
constructor(options: {
|
|
19
|
+
regex: RegExp;
|
|
20
|
+
groups: string[];
|
|
21
|
+
});
|
|
22
|
+
exec(value: string): ExecArray | null;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +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
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 实现 Named Groups RegExp 的正则百表达式
|
|
9
|
+
* ECMA 2018 的实现
|
|
10
|
+
* 通过 new RegExp 运算符,无法被 babel 转义
|
|
11
|
+
*/
|
|
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;
|
|
43
|
+
}
|
|
44
|
+
}]);
|
|
45
|
+
|
|
46
|
+
return NamedRegexp;
|
|
47
|
+
}();
|
|
48
|
+
|
|
49
|
+
export { NamedRegexp as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as NamedRegexp } from './NamedRegexp';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as NamedRegexp } from './NamedRegexp';
|
|
@@ -0,0 +1,26 @@
|
|
|
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.slice.js";
|
|
5
|
+
import "core-js/modules/es.array.concat.js";
|
|
6
|
+
import queryStringify from './queryStringify';
|
|
7
|
+
import searchParse from './searchParse';
|
|
8
|
+
export default function format(attrs) {
|
|
9
|
+
var _attrs$hash = attrs.hash,
|
|
10
|
+
hash = _attrs$hash === void 0 ? '' : _attrs$hash,
|
|
11
|
+
_attrs$pathname = attrs.pathname,
|
|
12
|
+
pathname = _attrs$pathname === void 0 ? '' : _attrs$pathname,
|
|
13
|
+
_attrs$origin = attrs.origin,
|
|
14
|
+
origin = _attrs$origin === void 0 ? '' : _attrs$origin,
|
|
15
|
+
_attrs$query = attrs.query,
|
|
16
|
+
query = _attrs$query === void 0 ? {} : _attrs$query,
|
|
17
|
+
_attrs$search = attrs.search,
|
|
18
|
+
search = _attrs$search === void 0 ? '' : _attrs$search;
|
|
19
|
+
var searchQuery = searchParse(search);
|
|
20
|
+
|
|
21
|
+
if (hash) {
|
|
22
|
+
query.____h_a_s_h____ = hash.slice(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return "".concat(origin).concat(pathname).concat(queryStringify(_objectSpread(_objectSpread({}, query), searchQuery))).concat(hash);
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import format from './format';
|
|
2
|
+
import params from './params';
|
|
3
|
+
import parse from './parse';
|
|
4
|
+
import queryStringify from './queryStringify';
|
|
5
|
+
import searchParse from './searchParse';
|
|
6
|
+
declare const queryParse: typeof searchParse;
|
|
7
|
+
export { parse, format, queryStringify, params, searchParse, queryParse };
|
|
8
|
+
declare const _default: {
|
|
9
|
+
parse: typeof parse;
|
|
10
|
+
format: typeof format;
|
|
11
|
+
queryStringify: typeof queryStringify;
|
|
12
|
+
queryParse: typeof searchParse;
|
|
13
|
+
params: typeof params;
|
|
14
|
+
searchParse: typeof searchParse;
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
package/lib/url/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import format from './format';
|
|
2
|
+
import params from './params';
|
|
3
|
+
import parse from './parse';
|
|
4
|
+
import queryStringify from './queryStringify';
|
|
5
|
+
import searchParse from './searchParse';
|
|
6
|
+
var queryParse = searchParse;
|
|
7
|
+
export { parse, format, queryStringify, params, searchParse, queryParse };
|
|
8
|
+
export default {
|
|
9
|
+
parse: parse,
|
|
10
|
+
format: format,
|
|
11
|
+
queryStringify: queryStringify,
|
|
12
|
+
queryParse: queryParse,
|
|
13
|
+
params: params,
|
|
14
|
+
searchParse: searchParse
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "core-js/modules/es.array.concat.js";
|
|
2
|
+
import merge from 'merge';
|
|
3
|
+
import parse from './parse';
|
|
4
|
+
import queryStringify from './queryStringify';
|
|
5
|
+
/**
|
|
6
|
+
* 调整页面地址的 query
|
|
7
|
+
* @param url - url 地址
|
|
8
|
+
* @param args - 附加到 query 上的参数
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export default function params(url) {
|
|
13
|
+
var _parse = parse(url),
|
|
14
|
+
query = _parse.query,
|
|
15
|
+
pathname = _parse.pathname,
|
|
16
|
+
origin = _parse.origin,
|
|
17
|
+
hash = _parse.hash;
|
|
18
|
+
|
|
19
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
20
|
+
args[_key - 1] = arguments[_key];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var params = merge.apply(void 0, [query].concat(args)); // 合并多个对象,覆盖前一个
|
|
24
|
+
|
|
25
|
+
return "".concat(origin).concat(pathname).concat(queryStringify(params)).concat(hash);
|
|
26
|
+
}
|
package/lib/url/parse.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["pathname"];
|
|
4
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
5
|
+
import "core-js/modules/es.object.to-string.js";
|
|
6
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
7
|
+
import "core-js/modules/es.object.keys.js";
|
|
8
|
+
import "core-js/modules/es.string.search.js";
|
|
9
|
+
import { NamedRegexp } from '../regexp';
|
|
10
|
+
import searchParse from './searchParse';
|
|
11
|
+
var URL_REGEX = new NamedRegexp({
|
|
12
|
+
regex: /(((?:http|https):)?(?:\/\/)?(([^:/?#]*)(?::(\d+))?))?([^?#]+)?(\?[^#]*)?(#.*)?/,
|
|
13
|
+
groups: ['origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash']
|
|
14
|
+
});
|
|
15
|
+
export default function parse(href) {
|
|
16
|
+
/* istanbul ignore next */
|
|
17
|
+
var _ref = URL_REGEX.exec(href) || {
|
|
18
|
+
groups: {}
|
|
19
|
+
},
|
|
20
|
+
_ref$groups = _ref.groups,
|
|
21
|
+
groups = _ref$groups === void 0 ? {} : _ref$groups;
|
|
22
|
+
|
|
23
|
+
Object.keys(groups).forEach(function (key) {
|
|
24
|
+
if (!groups[key]) {
|
|
25
|
+
groups[key] = '';
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
var query = {};
|
|
29
|
+
|
|
30
|
+
if (groups.search) {
|
|
31
|
+
query = searchParse(groups.search);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var pathname = groups.pathname,
|
|
35
|
+
restGroups = _objectWithoutProperties(groups, _excluded);
|
|
36
|
+
|
|
37
|
+
return _objectSpread({
|
|
38
|
+
query: query,
|
|
39
|
+
href: href,
|
|
40
|
+
pathname: pathname ? pathname : '/'
|
|
41
|
+
}, restGroups);
|
|
42
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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.join.js";
|
|
5
|
+
import "core-js/modules/es.array.concat.js";
|
|
6
|
+
export default function queryStringify(query) {
|
|
7
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8
|
+
var _options$prefix = options.prefix,
|
|
9
|
+
prefix = _options$prefix === void 0 ? true : _options$prefix;
|
|
10
|
+
var search = [];
|
|
11
|
+
var keys = Object.keys(query);
|
|
12
|
+
|
|
13
|
+
if (keys.length === 0) {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
keys.forEach(function (key) {
|
|
18
|
+
var value = query[key];
|
|
19
|
+
search.push([key, value].join('='));
|
|
20
|
+
});
|
|
21
|
+
return "".concat(prefix ? '?' : '').concat(search.join('&'));
|
|
22
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _toArray from "@babel/runtime/helpers/esm/toArray";
|
|
3
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
4
|
+
import "core-js/modules/es.string.split.js";
|
|
5
|
+
import "core-js/modules/es.array.slice.js";
|
|
6
|
+
import "core-js/modules/es.array.join.js";
|
|
7
|
+
import "core-js/modules/es.string.replace.js";
|
|
8
|
+
import "core-js/modules/es.object.to-string.js";
|
|
9
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 分割url search key value,返回 [key, value]
|
|
13
|
+
*/
|
|
14
|
+
function splitSearchKeyValue(str) {
|
|
15
|
+
var _str$split = str.split('='),
|
|
16
|
+
_str$split2 = _toArray(_str$split),
|
|
17
|
+
key = _str$split2[0],
|
|
18
|
+
valueArr = _str$split2.slice(1);
|
|
19
|
+
|
|
20
|
+
var value = valueArr.length ? valueArr.join('=') : '';
|
|
21
|
+
return [key, value];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 解析 url.search 返回对象类型
|
|
25
|
+
* @param search URL search 信息
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export default function searchParse(search) {
|
|
30
|
+
var query = {};
|
|
31
|
+
if (!search) return query;
|
|
32
|
+
search = search.replace(/^\?/, ''); // 移除首字符 问号
|
|
33
|
+
|
|
34
|
+
search.split('&').forEach(function (i) {
|
|
35
|
+
var _splitSearchKeyValue = splitSearchKeyValue(i),
|
|
36
|
+
_splitSearchKeyValue2 = _slicedToArray(_splitSearchKeyValue, 2),
|
|
37
|
+
key = _splitSearchKeyValue2[0],
|
|
38
|
+
value = _splitSearchKeyValue2[1];
|
|
39
|
+
|
|
40
|
+
query[key] = value;
|
|
41
|
+
});
|
|
42
|
+
return query;
|
|
43
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ray-js/library",
|
|
3
|
+
"version": "0.3.0-beta.1c347991",
|
|
4
|
+
"description": "Ray library for browser",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ray"
|
|
7
|
+
],
|
|
8
|
+
"author": "子长 <zichang.nong@tuya.com>",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"main": "lib/index.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"lib"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rm -rf lib",
|
|
20
|
+
"build": "ray build --type=component --transform-mode=pure",
|
|
21
|
+
"watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"merge": "^2.1.1",
|
|
25
|
+
"slash": "3.x"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@ray-js/cli": "^0.3.0-beta.1c347991"
|
|
29
|
+
},
|
|
30
|
+
"maintainers": [
|
|
31
|
+
{
|
|
32
|
+
"name": "tuyafe",
|
|
33
|
+
"email": "tuyafe@tuya.com"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"gitHead": "e0bd013022ddda63380d3c9e20fd8cadb46cd61f",
|
|
37
|
+
"repository": {}
|
|
38
|
+
}
|