fix(tw/ubn): accept 2023 relaxed check-digit rule (divisible by 5)#159
Conversation
Effective 2023-04-01, Taiwan's Ministry of Finance changed the Unified Business Number (統一編號) check-digit logic so the weighted digit sum only needs to be divisible by 5 (previously 10), expanding the number space while keeping the same 8-digit format. Every old, divisible-by-10 number is still divisible by 5, so existing numbers remain valid. - Relax the checksum from `sum % 10 === 0` to `sum % 5 === 0`. - Keep the 7th-digit-is-7 special case (7*4=28 sums to 10), now checked against the mod-5 remainder. - Add tests: an old-rule number (04595257), a new divisible-by-5 number (00501508), and a new 7th-digit special case (00000074). Ref: https://www.fia.gov.tw/singlehtml/3?cntId=c4d9cff38c8642ef8872774ee9987283 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request updates the UBN validation logic to align with the official 2023 Ministry of Finance specification change in Taiwan. By relaxing the checksum requirement from divisible-by-10 to divisible-by-5, the validator now correctly accepts newer business numbers while remaining fully backward compatible with older ones. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates the Taiwan Unified Business Number (UBN) validation logic to support the relaxed check-digit rules introduced on 2023-04-01, where the weighted digit sum only needs to be divisible by 5 instead of 10. It also updates the documentation and adds corresponding test cases for old-rule numbers, new-rule numbers, and the 7th-digit special case. There are no review comments, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Problem
The Taiwan Unified Business Number (統一編號 / UBN) validator uses the old rule where the weighted digit sum must be divisible by 10. Effective 2023-04-01, Taiwan's Ministry of Finance relaxed the check-digit logic from "divisible by 10" to "divisible by 5" to expand the available number space. The 8-digit format is unchanged, and every old (divisible-by-10) number is also divisible by 5, so the change is fully backward compatible.
As a result, the current implementation incorrectly rejects legitimate UBNs issued after 2023 (those divisible by 5 but not 10) as
InvalidChecksum.Note: upstream python-stdnum still uses the mod-10 rule, so this brings stdnum-js in line with the current official spec ahead of it.
Fix
sum % 10 === 0tosum % 5 === 0.7(7 * 4 = 28, whose digit sum is 10 and may be counted as either 1 or 0), now evaluated against the mod-5 remainder.Tests
0459525700501503005015080000007400501502jest src/tw/ubn.spec.ts→ 7 passed. lint and tsc both pass.Reference
https://www.fia.gov.tw/singlehtml/3?cntId=c4d9cff38c8642ef8872774ee9987283
🤖 Generated with Claude Code