Assign check digit to 0 if remainder is 10 by joelcuy · Pull Request #2492 · validatorjs/validator.js

Title:

feat(isISO6346): improve ISO6346 container ID validation with checksum adjustments

Description:

This PR enhances the isISO6346 validator to comply more accurately with the ISO 6346 standard, specifically addressing checksum validation for container IDs where the checksum result is 10. According to the standard, if the checksum is 10, the check digit should be represented as 0. This update improves accuracy in validating container IDs, particularly for freight containers (category 'U') where the checksum is mandatory.

Changes include:

  • Adjusting checksum validation to handle cases where the checksum is 10, setting the check digit to 0 as per the standard.
  • Adding tests for container IDs with check digits of 0 (when the checksum is 10) to ensure the validator correctly processes edge cases.

References:

"If the final difference is 10, then the check digit becomes 0. To ensure that this does not happen the standard recommends that serial numbers should not be used which produce a final difference of 10; however, there are containers in the market which do not follow this recommendation, so handling this case has to be included if a check digit calculator is programmed."

I think this should be considered as I'm currently working for a logistics company and we get container numbers that end with 0 (checksum is 10) very often. Hence, decided to help contribute. Let me know what you think!

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)