Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign check digit to 0 if remainder is 10 #2492

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/lib/isISO6346.js
Original file line number Diff line number Diff line change
@@ -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;
}

49 changes: 49 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
@@ -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({
Loading