Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Assign check digit to 0 if remainder is 10
  • Loading branch information
joelcuy committed Nov 12, 2024
commit de21f8df4e2d9dbd2280de0ceb86ad31b9c729c2
3 changes: 2 additions & 1 deletion src/lib/isISO6346.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export function isISO6346(str) {
} else sum += str[i] * (2 ** i);
}

const checkSumDigit = sum % 11;
let checkSumDigit = sum % 11;
if (checkSumDigit === 10) checkSumDigit = 0;
return Number(str[str.length - 1]) === checkSumDigit;
}

Expand Down
49 changes: 49 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13066,6 +13066,55 @@ describe('Validators', () => {
});
});

it('should validate ISO6346 shipping container IDs with checksum digit 10 represented as 0', () => {
test({
validator: 'isISO6346',
valid: [
'APZU3789870',
'TEMU1002030',
'DFSU1704420',
'CMAU2221480',
'SEGU5060260',
'FCIU8939320',
'TRHU3495670',
'MEDU3871410',
'CMAU2184010',
'TCLU2265970',
],
invalid: [
'APZU3789871', // Incorrect check digit
'TEMU1002031',
'DFSU1704421',
'CMAU2221481',
'SEGU5060261',
],
});
});
it('should validate ISO6346 shipping container IDs with checksum digit 10 represented as 0', () => {
test({
validator: 'isFreightContainerID',
valid: [
'APZU3789870',
'TEMU1002030',
'DFSU1704420',
'CMAU2221480',
'SEGU5060260',
'FCIU8939320',
'TRHU3495670',
'MEDU3871410',
'CMAU2184010',
'TCLU2265970',
],
invalid: [
'APZU3789871', // Incorrect check digit
'TEMU1002031',
'DFSU1704421',
'CMAU2221481',
'SEGU5060261',
],
});
});

// EU-UK valid numbers sourced from https://ec.europa.eu/taxation_customs/tin/specs/FS-TIN%20Algorithms-Public.docx or constructed by @tplessas.
it('should validate taxID', () => {
test({
Expand Down
Loading