Skip to content

Commit a066cd2

Browse files
authored
Assign check digit to 0 if remainder is 10 (#2492)
1 parent fc31e6e commit a066cd2

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/lib/isISO6346.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export function isISO6346(str) {
2727
} else sum += str[i] * (2 ** i);
2828
}
2929

30-
const checkSumDigit = sum % 11;
30+
let checkSumDigit = sum % 11;
31+
if (checkSumDigit === 10) checkSumDigit = 0;
3132
return Number(str[str.length - 1]) === checkSumDigit;
3233
}
3334

test/validators.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13066,6 +13066,55 @@ describe('Validators', () => {
1306613066
});
1306713067
});
1306813068

13069+
it('should validate ISO6346 shipping container IDs with checksum digit 10 represented as 0', () => {
13070+
test({
13071+
validator: 'isISO6346',
13072+
valid: [
13073+
'APZU3789870',
13074+
'TEMU1002030',
13075+
'DFSU1704420',
13076+
'CMAU2221480',
13077+
'SEGU5060260',
13078+
'FCIU8939320',
13079+
'TRHU3495670',
13080+
'MEDU3871410',
13081+
'CMAU2184010',
13082+
'TCLU2265970',
13083+
],
13084+
invalid: [
13085+
'APZU3789871', // Incorrect check digit
13086+
'TEMU1002031',
13087+
'DFSU1704421',
13088+
'CMAU2221481',
13089+
'SEGU5060261',
13090+
],
13091+
});
13092+
});
13093+
it('should validate ISO6346 shipping container IDs with checksum digit 10 represented as 0', () => {
13094+
test({
13095+
validator: 'isFreightContainerID',
13096+
valid: [
13097+
'APZU3789870',
13098+
'TEMU1002030',
13099+
'DFSU1704420',
13100+
'CMAU2221480',
13101+
'SEGU5060260',
13102+
'FCIU8939320',
13103+
'TRHU3495670',
13104+
'MEDU3871410',
13105+
'CMAU2184010',
13106+
'TCLU2265970',
13107+
],
13108+
invalid: [
13109+
'APZU3789871', // Incorrect check digit
13110+
'TEMU1002031',
13111+
'DFSU1704421',
13112+
'CMAU2221481',
13113+
'SEGU5060261',
13114+
],
13115+
});
13116+
});
13117+
1306913118
// EU-UK valid numbers sourced from https://ec.europa.eu/taxation_customs/tin/specs/FS-TIN%20Algorithms-Public.docx or constructed by @tplessas.
1307013119
it('should validate taxID', () => {
1307113120
test({

0 commit comments

Comments
 (0)