util-helpers 4.10.0 → 4.10.3

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/isPassport.js CHANGED
@@ -1,9 +1,9 @@
1
- import normalizeString from './normalizeString'; // 护照号 9位,包括首字母和数字;支持 普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ)、澳门特区护照(MA)
1
+ import normalizeString from './normalizeString'; // 护照号 9位,包括首字母和数字;支持 普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ/H*)、澳门特区护照(MA/MB/M*)
2
2
 
3
- var reg = /^((e[\da-z])|(de)|(se)|(pe)|(k[\da-z])|(kj)|(ma))[\da-z]{7}$/i;
3
+ var reg = /^((e[\da-z])|(de)|(se)|(pe)|([khm][\da-z]))[\da-z]{7}$/i;
4
4
  /**
5
5
  * 检测值是否为护照号
6
- * 支持普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ)、澳门特区护照(MA)
6
+ * 支持普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ/H*)、澳门特区护照(MA/MB/M*),注意不区分大小写
7
7
  *
8
8
  * @static
9
9
  * @alias module:Validator.isPassport
@@ -45,7 +45,7 @@ function sumCheckCode(preCode) {
45
45
  * @since 1.1.0
46
46
  * @param {*} value 要检测的值
47
47
  * @param {Object} [options] 配置项
48
- * @param {boolean} [options.loose=false] 宽松模式。如果为true,不校验校验位。
48
+ * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
49
49
  * @returns {boolean} 值是否为统一社会信用代码
50
50
  * @example
51
51
  *
@@ -55,22 +55,29 @@ function sumCheckCode(preCode) {
55
55
  * isSocialCreditCode('91350100M000100Y4A');
56
56
  * // => false
57
57
  *
58
- * // 宽松模式,不校验校验位。所以也可以通过
59
- * isSocialCreditCode('91350100M000100Y4A', {loose: true});
58
+ * // 不校验校验位
59
+ * isSocialCreditCode('91350100M000100Y4A', { checkCode: false });
60
60
  * // => true
61
61
  *
62
+ * isSocialCreditCode('91350100M000100Y', { checkCode: false });
63
+ * // => false
64
+ *
62
65
  */
63
66
 
64
67
 
65
68
  function isSocialCreditCode(value) {
66
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
67
- _ref$loose = _ref.loose,
68
- loose = _ref$loose === void 0 ? false : _ref$loose;
69
-
70
- var valueStr = normalizeString(value);
69
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
70
+ var valueStr = normalizeString(value); // @ts-ignore
71
+ // TODO 下个版本废弃 loose
72
+
73
+ var _options$loose = options.loose,
74
+ loose = _options$loose === void 0 ? false : _options$loose,
75
+ _options$checkCode = options.checkCode,
76
+ cc = _options$checkCode === void 0 ? true : _options$checkCode;
77
+ var needCheckCode = !loose && cc;
71
78
  var passBaseRule = baseReg.test(valueStr); // 宽松模式 或 基础规则不通过直接返回
72
79
 
73
- if (loose || !passBaseRule) {
80
+ if (!needCheckCode || !passBaseRule) {
74
81
  return passBaseRule;
75
82
  } // 前17位
76
83
 
package/esm/isTWCard.js CHANGED
@@ -1,6 +1,8 @@
1
- import normalizeString from './normalizeString'; // 台湾居民来往大陆通行证正则,支持一次性短期台胞证
1
+ import normalizeString from './normalizeString'; // 台湾居民来往大陆通行证正则
2
2
 
3
- var regTWCard = /^(\d{8}|[\da-z]{10})$/i;
3
+ var regTWCard = /^\d{8}$/i; // 一次性短期台胞证
4
+
5
+ var singleRegTWCard = /^[\da-z]{10,12}$/i;
4
6
  /**
5
7
  * 检测值是否为台湾居民来往大陆通行证,俗称台胞证。
6
8
  *
@@ -9,18 +11,30 @@ var regTWCard = /^(\d{8}|[\da-z]{10})$/i;
9
11
  * @since 4.0.0
10
12
  * @see 参考 {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
11
13
  * @param {*} value 要检测的值
14
+ * @param {Object} [options] 配置项
15
+ * @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
12
16
  * @returns {boolean} 是否为台湾居民来往大陆通行证
13
17
  * @example
14
18
  * isTWCard('12345678') // true
15
19
  * isTWCard('07257456') // true
16
20
  *
17
21
  * // 一次性短期
18
- * isTWCard('F290299977') // true
22
+ * isTWCard('F290299977') // false
23
+ * isTWCard('F290299977', { loose: true }) // true
19
24
  */
20
25
 
21
26
  function isTWCard(value) {
27
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
28
+ _ref$loose = _ref.loose,
29
+ loose = _ref$loose === void 0 ? false : _ref$loose;
30
+
22
31
  var valueStr = normalizeString(value);
23
- return regTWCard.test(valueStr);
32
+
33
+ if (regTWCard.test(valueStr)) {
34
+ return true;
35
+ }
36
+
37
+ return loose ? singleRegTWCard.test(valueStr) : false;
24
38
  }
25
39
 
26
40
  export default isTWCard;
@@ -51,36 +51,37 @@ function sumCheckCode(preCode) {
51
51
  * @since 3.5.0
52
52
  * @param {*} value 要检测的值
53
53
  * @param {Object} [options] 配置项
54
- * @param {boolean} [options.loose=false] 宽松模式。如果为true,不校验校验位。
54
+ * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
55
55
  * @returns {boolean} 值是否为营业执照号
56
56
  * @example
57
57
  *
58
58
  * isBusinessLicense('310115600985533');
59
59
  * // => true
60
60
  *
61
- * isBusinessLicense('3101156009');
62
- * // => false
63
- *
64
- * isBusinessLicense('3101156009', { loose: true });
65
- * // => false
66
- *
67
61
  * isBusinessLicense('310115600985535');
68
62
  * // => false
69
63
  *
70
- * isBusinessLicense('310115600985535', { loose: true });
64
+ * isBusinessLicense('310115600985535', { checkCode: false });
71
65
  * // => true
66
+ *
67
+ * isBusinessLicense('31011560098', { checkCode: false });
68
+ * // => false
72
69
  */
73
70
 
74
71
 
75
72
  function isBusinessLicense(value) {
76
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
77
- _ref$loose = _ref.loose,
78
- loose = _ref$loose === void 0 ? false : _ref$loose;
79
-
80
- var valueStr = (0, _normalizeString["default"])(value);
73
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
74
+ var valueStr = (0, _normalizeString["default"])(value); // @ts-ignore
75
+ // TODO 下个版本废弃 loose
76
+
77
+ var _options$loose = options.loose,
78
+ loose = _options$loose === void 0 ? false : _options$loose,
79
+ _options$checkCode = options.checkCode,
80
+ cc = _options$checkCode === void 0 ? true : _options$checkCode;
81
+ var needCheckCode = !loose && cc;
81
82
  var passBaseRule = baseReg.test(valueStr); // 宽松模式 或 基础规则不通过直接返回
82
83
 
83
- if (loose || !passBaseRule) {
84
+ if (!needCheckCode || !passBaseRule) {
84
85
  return passBaseRule;
85
86
  } // 前14位
86
87
 
package/lib/isPassport.js CHANGED
@@ -9,11 +9,11 @@ var _normalizeString = _interopRequireDefault(require("./normalizeString"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
11
 
12
- // 护照号 9位,包括首字母和数字;支持 普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ)、澳门特区护照(MA)
13
- var reg = /^((e[\da-z])|(de)|(se)|(pe)|(k[\da-z])|(kj)|(ma))[\da-z]{7}$/i;
12
+ // 护照号 9位,包括首字母和数字;支持 普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ/H*)、澳门特区护照(MA/MB/M*)
13
+ var reg = /^((e[\da-z])|(de)|(se)|(pe)|([khm][\da-z]))[\da-z]{7}$/i;
14
14
  /**
15
15
  * 检测值是否为护照号
16
- * 支持普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ)、澳门特区护照(MA)
16
+ * 支持普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ/H*)、澳门特区护照(MA/MB/M*),注意不区分大小写
17
17
  *
18
18
  * @static
19
19
  * @alias module:Validator.isPassport
@@ -55,7 +55,7 @@ function sumCheckCode(preCode) {
55
55
  * @since 1.1.0
56
56
  * @param {*} value 要检测的值
57
57
  * @param {Object} [options] 配置项
58
- * @param {boolean} [options.loose=false] 宽松模式。如果为true,不校验校验位。
58
+ * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
59
59
  * @returns {boolean} 值是否为统一社会信用代码
60
60
  * @example
61
61
  *
@@ -65,22 +65,29 @@ function sumCheckCode(preCode) {
65
65
  * isSocialCreditCode('91350100M000100Y4A');
66
66
  * // => false
67
67
  *
68
- * // 宽松模式,不校验校验位。所以也可以通过
69
- * isSocialCreditCode('91350100M000100Y4A', {loose: true});
68
+ * // 不校验校验位
69
+ * isSocialCreditCode('91350100M000100Y4A', { checkCode: false });
70
70
  * // => true
71
71
  *
72
+ * isSocialCreditCode('91350100M000100Y', { checkCode: false });
73
+ * // => false
74
+ *
72
75
  */
73
76
 
74
77
 
75
78
  function isSocialCreditCode(value) {
76
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
77
- _ref$loose = _ref.loose,
78
- loose = _ref$loose === void 0 ? false : _ref$loose;
79
-
80
- var valueStr = (0, _normalizeString["default"])(value);
79
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
80
+ var valueStr = (0, _normalizeString["default"])(value); // @ts-ignore
81
+ // TODO 下个版本废弃 loose
82
+
83
+ var _options$loose = options.loose,
84
+ loose = _options$loose === void 0 ? false : _options$loose,
85
+ _options$checkCode = options.checkCode,
86
+ cc = _options$checkCode === void 0 ? true : _options$checkCode;
87
+ var needCheckCode = !loose && cc;
81
88
  var passBaseRule = baseReg.test(valueStr); // 宽松模式 或 基础规则不通过直接返回
82
89
 
83
- if (loose || !passBaseRule) {
90
+ if (!needCheckCode || !passBaseRule) {
84
91
  return passBaseRule;
85
92
  } // 前17位
86
93
 
package/lib/isTWCard.js CHANGED
@@ -9,8 +9,10 @@ var _normalizeString = _interopRequireDefault(require("./normalizeString"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
11
 
12
- // 台湾居民来往大陆通行证正则,支持一次性短期台胞证
13
- var regTWCard = /^(\d{8}|[\da-z]{10})$/i;
12
+ // 台湾居民来往大陆通行证正则
13
+ var regTWCard = /^\d{8}$/i; // 一次性短期台胞证
14
+
15
+ var singleRegTWCard = /^[\da-z]{10,12}$/i;
14
16
  /**
15
17
  * 检测值是否为台湾居民来往大陆通行证,俗称台胞证。
16
18
  *
@@ -19,18 +21,30 @@ var regTWCard = /^(\d{8}|[\da-z]{10})$/i;
19
21
  * @since 4.0.0
20
22
  * @see 参考 {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
21
23
  * @param {*} value 要检测的值
24
+ * @param {Object} [options] 配置项
25
+ * @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
22
26
  * @returns {boolean} 是否为台湾居民来往大陆通行证
23
27
  * @example
24
28
  * isTWCard('12345678') // true
25
29
  * isTWCard('07257456') // true
26
30
  *
27
31
  * // 一次性短期
28
- * isTWCard('F290299977') // true
32
+ * isTWCard('F290299977') // false
33
+ * isTWCard('F290299977', { loose: true }) // true
29
34
  */
30
35
 
31
36
  function isTWCard(value) {
37
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
38
+ _ref$loose = _ref.loose,
39
+ loose = _ref$loose === void 0 ? false : _ref$loose;
40
+
32
41
  var valueStr = (0, _normalizeString["default"])(value);
33
- return regTWCard.test(valueStr);
42
+
43
+ if (regTWCard.test(valueStr)) {
44
+ return true;
45
+ }
46
+
47
+ return loose ? singleRegTWCard.test(valueStr) : false;
34
48
  }
35
49
 
36
50
  var _default = isTWCard;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "4.10.0",
3
+ "version": "4.10.3",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -8,25 +8,22 @@ export default isBusinessLicense;
8
8
  * @since 3.5.0
9
9
  * @param {*} value 要检测的值
10
10
  * @param {Object} [options] 配置项
11
- * @param {boolean} [options.loose=false] 宽松模式。如果为true,不校验校验位。
11
+ * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
12
12
  * @returns {boolean} 值是否为营业执照号
13
13
  * @example
14
14
  *
15
15
  * isBusinessLicense('310115600985533');
16
16
  * // => true
17
17
  *
18
- * isBusinessLicense('3101156009');
19
- * // => false
20
- *
21
- * isBusinessLicense('3101156009', { loose: true });
22
- * // => false
23
- *
24
18
  * isBusinessLicense('310115600985535');
25
19
  * // => false
26
20
  *
27
- * isBusinessLicense('310115600985535', { loose: true });
21
+ * isBusinessLicense('310115600985535', { checkCode: false });
28
22
  * // => true
23
+ *
24
+ * isBusinessLicense('31011560098', { checkCode: false });
25
+ * // => false
29
26
  */
30
- declare function isBusinessLicense(value: any, { loose }?: {
31
- loose?: boolean | undefined;
27
+ declare function isBusinessLicense(value: any, options?: {
28
+ checkCode?: boolean | undefined;
32
29
  } | undefined): boolean;
@@ -1,7 +1,7 @@
1
1
  export default isPassport;
2
2
  /**
3
3
  * 检测值是否为护照号
4
- * 支持普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ)、澳门特区护照(MA)
4
+ * 支持普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ/H*)、澳门特区护照(MA/MB/M*),注意不区分大小写
5
5
  *
6
6
  * @static
7
7
  * @alias module:Validator.isPassport
@@ -8,7 +8,7 @@ export default isSocialCreditCode;
8
8
  * @since 1.1.0
9
9
  * @param {*} value 要检测的值
10
10
  * @param {Object} [options] 配置项
11
- * @param {boolean} [options.loose=false] 宽松模式。如果为true,不校验校验位。
11
+ * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
12
12
  * @returns {boolean} 值是否为统一社会信用代码
13
13
  * @example
14
14
  *
@@ -18,11 +18,14 @@ export default isSocialCreditCode;
18
18
  * isSocialCreditCode('91350100M000100Y4A');
19
19
  * // => false
20
20
  *
21
- * // 宽松模式,不校验校验位。所以也可以通过
22
- * isSocialCreditCode('91350100M000100Y4A', {loose: true});
21
+ * // 不校验校验位
22
+ * isSocialCreditCode('91350100M000100Y4A', { checkCode: false });
23
23
  * // => true
24
24
  *
25
+ * isSocialCreditCode('91350100M000100Y', { checkCode: false });
26
+ * // => false
27
+ *
25
28
  */
26
- declare function isSocialCreditCode(value: any, { loose }?: {
27
- loose?: boolean | undefined;
29
+ declare function isSocialCreditCode(value: any, options?: {
30
+ checkCode?: boolean | undefined;
28
31
  } | undefined): boolean;
@@ -7,12 +7,17 @@ export default isTWCard;
7
7
  * @since 4.0.0
8
8
  * @see 参考 {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
9
9
  * @param {*} value 要检测的值
10
+ * @param {Object} [options] 配置项
11
+ * @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
10
12
  * @returns {boolean} 是否为台湾居民来往大陆通行证
11
13
  * @example
12
14
  * isTWCard('12345678') // true
13
15
  * isTWCard('07257456') // true
14
16
  *
15
17
  * // 一次性短期
16
- * isTWCard('F290299977') // true
18
+ * isTWCard('F290299977') // false
19
+ * isTWCard('F290299977', { loose: true }) // true
17
20
  */
18
- declare function isTWCard(value: any): boolean;
21
+ declare function isTWCard(value: any, { loose }?: {
22
+ loose?: boolean | undefined;
23
+ } | undefined): boolean;