util-helpers 5.5.1 → 5.6.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/esm/VERSION.js CHANGED
@@ -1,3 +1,3 @@
1
- var VERSION = "5.5.1";
1
+ var VERSION = "5.6.0";
2
2
 
3
3
  export { VERSION as default };
package/esm/index.js CHANGED
@@ -20,7 +20,7 @@ export { default as isHMCard } from './isHMCard.js';
20
20
  export { default as isTWCard } from './isTWCard.js';
21
21
  export { default as isSwiftCode } from './isSwiftCode.js';
22
22
  export { default as isValidNumber } from './isValidNumber.js';
23
- export { default as checkResult } from './checkResult.js';
23
+ export { default as isUnifiedIdentifier } from './isUnifiedIdentifier.js';
24
24
  export { default as formatMoney } from './formatMoney.js';
25
25
  export { default as formatBankCard } from './formatBankCard.js';
26
26
  export { default as replaceChar } from './replaceChar.js';
@@ -57,6 +57,7 @@ export { default as calculateCursorPosition } from './calculateCursorPosition.js
57
57
  export { default as getExtname } from './getExtname.js';
58
58
  export { default as randomString } from './randomString.js';
59
59
  export { default as strlen } from './strlen.js';
60
+ export { default as checkResult } from './checkResult.js';
60
61
  export { default as transformFieldNames } from './transformFieldNames.js';
61
62
  export { default as listToTree } from './listToTree.js';
62
63
  export { default as treeToList } from './treeToList.js';
@@ -1,33 +1,5 @@
1
- import { toString } from 'ut2';
1
+ import isUnifiedIdentifier from './isUnifiedIdentifier.js';
2
2
 
3
- var baseReg = /^[\dA-HJ-NPQRTUWXY]{2}\d{6}[\dA-HJ-NPQRTUWXY]{10}$/;
4
- var baseCodeArr = '0123456789ABCDEFGHJKLMNPQRTUWXY'.split('');
5
- function sumCheckCode(preCode) {
6
- var total = 0;
7
- var _loop_1 = function (i) {
8
- var index = baseCodeArr.findIndex(function (item) { return item === preCode[i]; });
9
- var wf = Math.pow(3, i) % 31;
10
- total += index * wf;
11
- };
12
- for (var i = 0; i < 17; i++) {
13
- _loop_1(i);
14
- }
15
- var remainder = total % 31;
16
- var checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
17
- return baseCodeArr[checkCodeIndex];
18
- }
19
- function isSocialCreditCode(value, options) {
20
- var valueStr = toString(value);
21
- var _a = (options || {}).checkCode, needCheckCode = _a === void 0 ? true : _a;
22
- var passBaseRule = baseReg.test(valueStr);
23
- if (!needCheckCode || !passBaseRule) {
24
- return passBaseRule;
25
- }
26
- var preCode = valueStr.substring(0, 17);
27
- var lastCode = valueStr.substring(valueStr.length - 1);
28
- var checkCode = sumCheckCode(preCode);
29
- return lastCode === checkCode;
30
- }
31
- isSocialCreditCode.sumCheckCode = sumCheckCode;
3
+ var isSocialCreditCode = isUnifiedIdentifier;
32
4
 
33
5
  export { isSocialCreditCode as default };
@@ -0,0 +1,33 @@
1
+ import { toString } from 'ut2';
2
+
3
+ var baseReg = /^[\dA-HJ-NPQRTUWXY]{2}\d{6}[\dA-HJ-NPQRTUWXY]{10}$/;
4
+ var baseCodeArr = '0123456789ABCDEFGHJKLMNPQRTUWXY'.split('');
5
+ function sumCheckCode(preCode) {
6
+ var total = 0;
7
+ var _loop_1 = function (i) {
8
+ var index = baseCodeArr.findIndex(function (item) { return item === preCode[i]; });
9
+ var wf = Math.pow(3, i) % 31;
10
+ total += index * wf;
11
+ };
12
+ for (var i = 0; i < 17; i++) {
13
+ _loop_1(i);
14
+ }
15
+ var remainder = total % 31;
16
+ var checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
17
+ return baseCodeArr[checkCodeIndex];
18
+ }
19
+ function isUnifiedIdentifier(value, options) {
20
+ var valueStr = toString(value);
21
+ var _a = (options || {}).checkCode, needCheckCode = _a === void 0 ? true : _a;
22
+ var passBaseRule = baseReg.test(valueStr);
23
+ if (!needCheckCode || !passBaseRule) {
24
+ return passBaseRule;
25
+ }
26
+ var preCode = valueStr.substring(0, 17);
27
+ var lastCode = valueStr.substring(valueStr.length - 1);
28
+ var checkCode = sumCheckCode(preCode);
29
+ return lastCode === checkCode;
30
+ }
31
+ isUnifiedIdentifier.sumCheckCode = sumCheckCode;
32
+
33
+ export { isUnifiedIdentifier as default };
package/lib/VERSION.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "5.5.1";
3
+ var VERSION = "5.6.0";
4
4
 
5
5
  module.exports = VERSION;
package/lib/index.js CHANGED
@@ -22,7 +22,7 @@ var isHMCard = require('./isHMCard.js');
22
22
  var isTWCard = require('./isTWCard.js');
23
23
  var isSwiftCode = require('./isSwiftCode.js');
24
24
  var isValidNumber = require('./isValidNumber.js');
25
- var checkResult = require('./checkResult.js');
25
+ var isUnifiedIdentifier = require('./isUnifiedIdentifier.js');
26
26
  var formatMoney = require('./formatMoney.js');
27
27
  var formatBankCard = require('./formatBankCard.js');
28
28
  var replaceChar = require('./replaceChar.js');
@@ -59,6 +59,7 @@ var calculateCursorPosition = require('./calculateCursorPosition.js');
59
59
  var getExtname = require('./getExtname.js');
60
60
  var randomString = require('./randomString.js');
61
61
  var strlen = require('./strlen.js');
62
+ var checkResult = require('./checkResult.js');
62
63
  var transformFieldNames = require('./transformFieldNames.js');
63
64
  var listToTree = require('./listToTree.js');
64
65
  var treeToList = require('./treeToList.js');
@@ -94,7 +95,7 @@ exports.isHMCard = isHMCard;
94
95
  exports.isTWCard = isTWCard;
95
96
  exports.isSwiftCode = isSwiftCode;
96
97
  exports.isValidNumber = isValidNumber;
97
- exports.checkResult = checkResult;
98
+ exports.isUnifiedIdentifier = isUnifiedIdentifier;
98
99
  exports.formatMoney = formatMoney;
99
100
  exports.formatBankCard = formatBankCard;
100
101
  exports.replaceChar = replaceChar;
@@ -131,6 +132,7 @@ exports.calculateCursorPosition = calculateCursorPosition;
131
132
  exports.getExtname = getExtname;
132
133
  exports.randomString = randomString;
133
134
  exports.strlen = strlen;
135
+ exports.checkResult = checkResult;
134
136
  exports.transformFieldNames = transformFieldNames;
135
137
  exports.listToTree = listToTree;
136
138
  exports.treeToList = treeToList;
@@ -1,35 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var ut2 = require('ut2');
3
+ var isUnifiedIdentifier = require('./isUnifiedIdentifier.js');
4
4
 
5
- var baseReg = /^[\dA-HJ-NPQRTUWXY]{2}\d{6}[\dA-HJ-NPQRTUWXY]{10}$/;
6
- var baseCodeArr = '0123456789ABCDEFGHJKLMNPQRTUWXY'.split('');
7
- function sumCheckCode(preCode) {
8
- var total = 0;
9
- var _loop_1 = function (i) {
10
- var index = baseCodeArr.findIndex(function (item) { return item === preCode[i]; });
11
- var wf = Math.pow(3, i) % 31;
12
- total += index * wf;
13
- };
14
- for (var i = 0; i < 17; i++) {
15
- _loop_1(i);
16
- }
17
- var remainder = total % 31;
18
- var checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
19
- return baseCodeArr[checkCodeIndex];
20
- }
21
- function isSocialCreditCode(value, options) {
22
- var valueStr = ut2.toString(value);
23
- var _a = (options || {}).checkCode, needCheckCode = _a === void 0 ? true : _a;
24
- var passBaseRule = baseReg.test(valueStr);
25
- if (!needCheckCode || !passBaseRule) {
26
- return passBaseRule;
27
- }
28
- var preCode = valueStr.substring(0, 17);
29
- var lastCode = valueStr.substring(valueStr.length - 1);
30
- var checkCode = sumCheckCode(preCode);
31
- return lastCode === checkCode;
32
- }
33
- isSocialCreditCode.sumCheckCode = sumCheckCode;
5
+ var isSocialCreditCode = isUnifiedIdentifier;
34
6
 
35
7
  module.exports = isSocialCreditCode;
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ var ut2 = require('ut2');
4
+
5
+ var baseReg = /^[\dA-HJ-NPQRTUWXY]{2}\d{6}[\dA-HJ-NPQRTUWXY]{10}$/;
6
+ var baseCodeArr = '0123456789ABCDEFGHJKLMNPQRTUWXY'.split('');
7
+ function sumCheckCode(preCode) {
8
+ var total = 0;
9
+ var _loop_1 = function (i) {
10
+ var index = baseCodeArr.findIndex(function (item) { return item === preCode[i]; });
11
+ var wf = Math.pow(3, i) % 31;
12
+ total += index * wf;
13
+ };
14
+ for (var i = 0; i < 17; i++) {
15
+ _loop_1(i);
16
+ }
17
+ var remainder = total % 31;
18
+ var checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;
19
+ return baseCodeArr[checkCodeIndex];
20
+ }
21
+ function isUnifiedIdentifier(value, options) {
22
+ var valueStr = ut2.toString(value);
23
+ var _a = (options || {}).checkCode, needCheckCode = _a === void 0 ? true : _a;
24
+ var passBaseRule = baseReg.test(valueStr);
25
+ if (!needCheckCode || !passBaseRule) {
26
+ return passBaseRule;
27
+ }
28
+ var preCode = valueStr.substring(0, 17);
29
+ var lastCode = valueStr.substring(valueStr.length - 1);
30
+ var checkCode = sumCheckCode(preCode);
31
+ return lastCode === checkCode;
32
+ }
33
+ isUnifiedIdentifier.sumCheckCode = sumCheckCode;
34
+
35
+ module.exports = isUnifiedIdentifier;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "5.5.1",
3
+ "version": "5.6.0",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
package/types/index.d.ts CHANGED
@@ -25,7 +25,7 @@ export { default as isHMCard } from './isHMCard';
25
25
  export { default as isTWCard } from './isTWCard';
26
26
  export { default as isSwiftCode } from './isSwiftCode';
27
27
  export { default as isValidNumber } from './isValidNumber';
28
- export { default as checkResult } from './checkResult';
28
+ export { default as isUnifiedIdentifier } from './isUnifiedIdentifier';
29
29
  /**
30
30
  * 数据处理
31
31
  *
@@ -117,6 +117,7 @@ export { default as calculateCursorPosition } from './calculateCursorPosition';
117
117
  export { default as getExtname } from './getExtname';
118
118
  export { default as randomString } from './randomString';
119
119
  export { default as strlen } from './strlen';
120
+ export { default as checkResult } from './checkResult';
120
121
  /**
121
122
  * 树结构数据查询、过滤、转换等处理方法
122
123
  *
@@ -4,9 +4,11 @@ type Options = {
4
4
  /**
5
5
  * 检测值是否为营业执照号,也叫工商注册号。由14位数字本体码和1位数字校验码组成,其中本体码从左至右依次为:6位首次登记机关码、8位顺序码。
6
6
  *
7
+ * @private
7
8
  * @alias module:Validator.isBusinessLicense
8
9
  * @since 3.5.0
9
10
  * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html GS15—2006 工商行政管理市场主体注册号编制规则}
11
+ * @deprecated 即将废弃。
10
12
  * @param {*} value 要检测的值
11
13
  * @param {Object} [options] 配置项
12
14
  * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,默认`true`。如果为false,不校验校验位。
@@ -1,12 +1,12 @@
1
- type Options = {
2
- checkCode?: boolean;
3
- };
1
+ import isUnifiedIdentifier from './isUnifiedIdentifier';
4
2
  /**
5
3
  * 检测值是否为统一社会信用代码,也叫三证合一组织代码。由18位数字和大写字母组成,不使用I、O、Z、S、V。
6
4
  *
5
+ * @private
7
6
  * @alias module:Validator.isSocialCreditCode
8
7
  * @since 1.1.0
9
8
  * @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则 GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
9
+ * @deprecated 即将废弃,请使用 `isUnifiedIdentifier` 替代。
10
10
  * @param {*} value 要检测的值
11
11
  * @param {Object} [options] 配置项
12
12
  * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
@@ -22,8 +22,5 @@ type Options = {
22
22
  * isSocialCreditCode('91350100M000100Y', { checkCode: false }); // false
23
23
  *
24
24
  */
25
- declare function isSocialCreditCode(value: any, options?: Options): boolean;
26
- declare namespace isSocialCreditCode {
27
- var sumCheckCode: (preCode: string) => string;
28
- }
25
+ declare const isSocialCreditCode: typeof isUnifiedIdentifier;
29
26
  export default isSocialCreditCode;
@@ -0,0 +1,30 @@
1
+ type Options = {
2
+ checkCode?: boolean;
3
+ };
4
+ /**
5
+ * 检测值是否为统一社会信用代码,也叫三证合一组织代码。由18位数字和大写字母组成,不使用I、O、Z、S、V。
6
+ *
7
+ * @alias module:Validator.isUnifiedIdentifier
8
+ * @since 5.6.0
9
+ * @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则 GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
10
+ * @see {@link https://std.samr.gov.cn/gb/search/gbDetailed?id=71F772D808D6D3A7E05397BE0A0AB82A 法人和其他组织统一社会信用代码编码规则}
11
+ * @param {*} value 要检测的值
12
+ * @param {Object} [options] 配置项
13
+ * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
14
+ * @returns {boolean} 值是否为统一社会信用代码
15
+ * @example
16
+ *
17
+ * isUnifiedIdentifier('91350100M000100Y43'); // true
18
+ * isUnifiedIdentifier('91350100M000100Y4A'); // false
19
+ *
20
+ * // 不校验校验位,长度和类型还是有校验的
21
+ * isUnifiedIdentifier('91350100M000100Y4A', { checkCode: false }); // true
22
+ * isUnifiedIdentifier('91350100M000100YIO', { checkCode: false }); // false
23
+ * isUnifiedIdentifier('91350100M000100Y', { checkCode: false }); // false
24
+ *
25
+ */
26
+ declare function isUnifiedIdentifier(value: any, options?: Options): boolean;
27
+ declare namespace isUnifiedIdentifier {
28
+ var sumCheckCode: (preCode: string) => string;
29
+ }
30
+ export default isUnifiedIdentifier;