util-helpers 4.12.10 → 4.13.1

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/esm/isUrl.js CHANGED
@@ -1,6 +1,19 @@
1
- import normalizeString from './normalizeString'; // url正则
1
+ import normalizeString from './normalizeString'; // 标准格式如下:
2
+ // [协议类型]://[服务器地址]:[端口号]/[资源层级UNIX文件路径][文件名]?[查询]#[片段ID]
3
+ // 完整格式如下:
4
+ // [协议类型]://[访问资源需要的凭证信息]@[服务器地址]:[端口号]/[资源层级UNIX文件路径][文件名]?[查询]#[片段ID]
5
+ //
6
+ // 其中[访问凭证信息]、[端口号]、[查询]、[片段ID]都属于选填项。
2
7
 
3
- var reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\*\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
8
+ var protocalReg = '[\\w-.]+:\\/\\/';
9
+ var credentialsReg = '[-;:&=\\+\\$,\\w]+@';
10
+ var serverReg = 'localhost|(([^\\s:\\/]+?\\.)+?[^\\s:\\/]+)';
11
+ var portReg = ':\\d+';
12
+ var pathReg = '\\/.*';
13
+ var searchReg = '\\?.*';
14
+ var hashReg = '#.*';
15
+ var regWithProtocal = new RegExp("^".concat(protocalReg, "(?:").concat(credentialsReg, ")?(?:").concat(serverReg, ")(?:").concat(portReg, ")?(?:").concat(pathReg, ")*(?:").concat(searchReg, ")?(?:").concat(hashReg, ")?$"));
16
+ var regNonProtocal = new RegExp("^(?:".concat(serverReg, ")(?:").concat(portReg, ")?(?:").concat(pathReg, ")*(?:").concat(searchReg, ")?(?:").concat(hashReg, ")?$"));
4
17
  /**
5
18
  * 检测值是否为url
6
19
  *
@@ -13,18 +26,27 @@ var reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:
13
26
  * @example
14
27
  *
15
28
  * isUrl(''); // false
16
- * isUrl('8.8.8.8'); // false
29
+ * isUrl('/foo/bar'); // false
30
+ *
31
+ * isUrl('8.8.8.8'); // true
17
32
  * isUrl('example.com'); // true
18
33
  * isUrl('http://example.com'); // true
19
34
  * isUrl('https://example.com:8080'); // true
20
- * isUrl('http://www.example.com/test/123'); // true
21
- * isUrl('http://www.example.com/test/123?foo=bar'); // true
35
+ * isUrl('https://www.example.com/test/123'); // true
36
+ * isUrl('https://www.example.com/test/123?foo=bar'); // true
37
+ * isUrl('https://www.example.com/test/123?foo=中文#id'); // true
38
+ * isUrl('https://www.example.com/test/123?foo=中文#测试'); // true
39
+ * isUrl('ftp://127.0.0.1:8080/测试.tar'); // true
40
+ * isUrl('a.b'); // true
41
+ * isUrl('a.b:8080'); // true
42
+ * isUrl('p://a.b'); // true
43
+ * isUrl('p://a.b:8888'); // true
22
44
  *
23
45
  */
24
46
 
25
47
  function isUrl(value) {
26
48
  var valueStr = normalizeString(value);
27
- return reg.test(valueStr);
49
+ return regWithProtocal.test(valueStr) || regNonProtocal.test(valueStr);
28
50
  }
29
51
 
30
52
  export default isUrl;
@@ -1,5 +1,3 @@
1
- // @ts-ignore
2
- var version = "4.12.10";
3
1
  var config = {
4
2
  // 禁用warning提示
5
3
  disableWarning: true
@@ -14,6 +12,8 @@ var config = {
14
12
 
15
13
  function setDisableWarning(bool) {
16
14
  config.disableWarning = !!bool;
17
- }
15
+ } // eslint-disable-next-line no-undef
18
16
 
17
+
18
+ var version = "4.13.1";
19
19
  export { config, setDisableWarning, version };
package/lib/isChinese.js CHANGED
@@ -41,6 +41,8 @@ var supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
41
41
  * @alias module:Validator.isChinese
42
42
  * @since 1.1.0
43
43
  * @see 参考 {@link http://www.unicode.org/reports/tr38/#BlockListing|4.4 Listing of Characters Covered by the Unihan Database}
44
+ * @see 参考 {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射|Unicode字符平面映射}
45
+ * @see 参考 {@link https://zh.wikipedia.org/wiki/Unicode區段|Unicode区段}
44
46
  * @param {*} value 要检测的值
45
47
  * @param {Object} [options] 配置项
46
48
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
package/lib/isUrl.js CHANGED
@@ -9,8 +9,21 @@ var _normalizeString = _interopRequireDefault(require("./normalizeString"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
11
 
12
- // url正则
13
- var reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\*\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
12
+ // 标准格式如下:
13
+ // [协议类型]://[服务器地址]:[端口号]/[资源层级UNIX文件路径][文件名]?[查询]#[片段ID]
14
+ // 完整格式如下:
15
+ // [协议类型]://[访问资源需要的凭证信息]@[服务器地址]:[端口号]/[资源层级UNIX文件路径][文件名]?[查询]#[片段ID]
16
+ //
17
+ // 其中[访问凭证信息]、[端口号]、[查询]、[片段ID]都属于选填项。
18
+ var protocalReg = '[\\w-.]+:\\/\\/';
19
+ var credentialsReg = '[-;:&=\\+\\$,\\w]+@';
20
+ var serverReg = 'localhost|(([^\\s:\\/]+?\\.)+?[^\\s:\\/]+)';
21
+ var portReg = ':\\d+';
22
+ var pathReg = '\\/.*';
23
+ var searchReg = '\\?.*';
24
+ var hashReg = '#.*';
25
+ var regWithProtocal = new RegExp("^".concat(protocalReg, "(?:").concat(credentialsReg, ")?(?:").concat(serverReg, ")(?:").concat(portReg, ")?(?:").concat(pathReg, ")*(?:").concat(searchReg, ")?(?:").concat(hashReg, ")?$"));
26
+ var regNonProtocal = new RegExp("^(?:".concat(serverReg, ")(?:").concat(portReg, ")?(?:").concat(pathReg, ")*(?:").concat(searchReg, ")?(?:").concat(hashReg, ")?$"));
14
27
  /**
15
28
  * 检测值是否为url
16
29
  *
@@ -23,18 +36,27 @@ var reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:
23
36
  * @example
24
37
  *
25
38
  * isUrl(''); // false
26
- * isUrl('8.8.8.8'); // false
39
+ * isUrl('/foo/bar'); // false
40
+ *
41
+ * isUrl('8.8.8.8'); // true
27
42
  * isUrl('example.com'); // true
28
43
  * isUrl('http://example.com'); // true
29
44
  * isUrl('https://example.com:8080'); // true
30
- * isUrl('http://www.example.com/test/123'); // true
31
- * isUrl('http://www.example.com/test/123?foo=bar'); // true
45
+ * isUrl('https://www.example.com/test/123'); // true
46
+ * isUrl('https://www.example.com/test/123?foo=bar'); // true
47
+ * isUrl('https://www.example.com/test/123?foo=中文#id'); // true
48
+ * isUrl('https://www.example.com/test/123?foo=中文#测试'); // true
49
+ * isUrl('ftp://127.0.0.1:8080/测试.tar'); // true
50
+ * isUrl('a.b'); // true
51
+ * isUrl('a.b:8080'); // true
52
+ * isUrl('p://a.b'); // true
53
+ * isUrl('p://a.b:8888'); // true
32
54
  *
33
55
  */
34
56
 
35
57
  function isUrl(value) {
36
58
  var valueStr = (0, _normalizeString["default"])(value);
37
- return reg.test(valueStr);
59
+ return regWithProtocal.test(valueStr) || regNonProtocal.test(valueStr);
38
60
  }
39
61
 
40
62
  var _default = isUrl;
@@ -5,9 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.setDisableWarning = setDisableWarning;
7
7
  exports.version = exports.config = void 0;
8
- // @ts-ignore
9
- var version = "4.12.10";
10
- exports.version = version;
11
8
  var config = {
12
9
  // 禁用warning提示
13
10
  disableWarning: true
@@ -24,4 +21,8 @@ exports.config = config;
24
21
 
25
22
  function setDisableWarning(bool) {
26
23
  config.disableWarning = !!bool;
27
- }
24
+ } // eslint-disable-next-line no-undef
25
+
26
+
27
+ var version = "4.13.1";
28
+ exports.version = version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "4.12.10",
3
+ "version": "4.13.1",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -65,11 +65,12 @@
65
65
  "@commitlint/config-conventional": "^11.0.0",
66
66
  "@rollup/plugin-babel": "^5.3.1",
67
67
  "@rollup/plugin-commonjs": "^19.0.0",
68
- "@rollup/plugin-json": "^4.1.0",
69
68
  "@rollup/plugin-node-resolve": "^13.0.0",
69
+ "@rollup/plugin-replace": "^5.0.1",
70
70
  "@types/jest": "^26.0.23",
71
71
  "babel-jest": "^27.0.2",
72
72
  "babel-plugin-inline-json": "^2.1.0",
73
+ "babel-plugin-minify-replace": "^0.5.0",
73
74
  "cross-env": "^7.0.3",
74
75
  "cz-conventional-changelog": "^3.3.0",
75
76
  "docdash": "^1.2.0",
@@ -81,7 +82,7 @@
81
82
  "prettier": "^2.3.2",
82
83
  "rollup": "^2.49.0",
83
84
  "rollup-plugin-terser": "^7.0.2",
84
- "typescript": "^4.2.4"
85
+ "typescript": "^4.9.3"
85
86
  },
86
87
  "lint-staged": {
87
88
  "**/*.js": "npm run lint-staged:js",
@@ -6,6 +6,8 @@ export default isChinese;
6
6
  * @alias module:Validator.isChinese
7
7
  * @since 1.1.0
8
8
  * @see 参考 {@link http://www.unicode.org/reports/tr38/#BlockListing|4.4 Listing of Characters Covered by the Unihan Database}
9
+ * @see 参考 {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射|Unicode字符平面映射}
10
+ * @see 参考 {@link https://zh.wikipedia.org/wiki/Unicode區段|Unicode区段}
9
11
  * @param {*} value 要检测的值
10
12
  * @param {Object} [options] 配置项
11
13
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
package/types/isUrl.d.ts CHANGED
@@ -11,12 +11,21 @@ export default isUrl;
11
11
  * @example
12
12
  *
13
13
  * isUrl(''); // false
14
- * isUrl('8.8.8.8'); // false
14
+ * isUrl('/foo/bar'); // false
15
+ *
16
+ * isUrl('8.8.8.8'); // true
15
17
  * isUrl('example.com'); // true
16
18
  * isUrl('http://example.com'); // true
17
19
  * isUrl('https://example.com:8080'); // true
18
- * isUrl('http://www.example.com/test/123'); // true
19
- * isUrl('http://www.example.com/test/123?foo=bar'); // true
20
+ * isUrl('https://www.example.com/test/123'); // true
21
+ * isUrl('https://www.example.com/test/123?foo=bar'); // true
22
+ * isUrl('https://www.example.com/test/123?foo=中文#id'); // true
23
+ * isUrl('https://www.example.com/test/123?foo=中文#测试'); // true
24
+ * isUrl('ftp://127.0.0.1:8080/测试.tar'); // true
25
+ * isUrl('a.b'); // true
26
+ * isUrl('a.b:8080'); // true
27
+ * isUrl('p://a.b'); // true
28
+ * isUrl('p://a.b:8888'); // true
20
29
  *
21
30
  */
22
31
  declare function isUrl(value: any): boolean;
@@ -9,5 +9,4 @@ export namespace config {
9
9
  * @param {boolean} bool 是否禁止warning提示
10
10
  */
11
11
  export function setDisableWarning(bool: boolean): void;
12
- import { version } from "../../package.json";
13
- export { version };
12
+ export const version: string;