Skip to content

Commit

Permalink
fix(issocialcreditcode): 修复校验位为0时验证结果不准确问题
Browse files Browse the repository at this point in the history
  • Loading branch information
caijf committed Apr 15, 2022
1 parent 328e072 commit c2c997b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/isSocialCreditCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function sumCheckCode(preCode) {
// 计算整数求余函数MOD
const remainder = total % 31;
// 校验码字符值序号
const checkCodeIndex = 31 - remainder;
const checkCodeIndex = remainder !== 0 ? 31 - remainder : 0;

return baseCodeArr[checkCodeIndex];
}
Expand Down
3 changes: 3 additions & 0 deletions test/validator/isSocialCreditCode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ describe('isSocialCreditCode', () => {
it('"91350100M000100Y4A" => false', () => {
expect(isSocialCreditCode('91350100M000100Y4A')).toBe(false);
});
it('校验位为0 "911101005JLR20JR60" => true', () => {
expect(isSocialCreditCode('911101005JLR20JR60')).toBe(true);
});
it('宽松模式,"91350100M000100Y4AB" => true', () => {
expect(isSocialCreditCode('91350100M000100Y4A', { loose: true })).toBe(true);
});
Expand Down

0 comments on commit c2c997b

Please sign in to comment.