Summary
The Japan Post 4-state barcode check digit in src/encoders/fourstate.ts uses modulo 10 on digit values, but some specifications indicate modulo 19 on bar state values should be used.
Details
Current code (mod 10 on digit values):
let sum = 0;
for (const ch of data) {
sum += ch === "-" ? 10 : Number.parseInt(ch, 10);
}
data += ((10 - (sum % 10)) % 10).toString();
Japan Post specification reportedly uses:
Sum all the bar state values (each bar has a numeric value 1-4) across all data bars, then compute (19 - (sum % 19)) % 19 to get the check digit.
The distinction matters because:
- The modulus is different (10 vs 19)
- The input to the sum is different (character digit values vs bar state values)
Additional concern
The address encoding only accepts digits and dash (/^[\d-]+$/), but Japan Post barcodes can encode alphanumeric characters using control character prefixes (CC1-CC4). Letters A-Z are encoded as CC prefix + digit pair.
Verification needed
Cross-reference with the official Japan Post Customer Barcode Technical Specification and reference implementations (OkapiBarcode has a Java implementation).
References
Summary
The Japan Post 4-state barcode check digit in
src/encoders/fourstate.tsuses modulo 10 on digit values, but some specifications indicate modulo 19 on bar state values should be used.Details
Current code (mod 10 on digit values):
Japan Post specification reportedly uses:
Sum all the bar state values (each bar has a numeric value 1-4) across all data bars, then compute
(19 - (sum % 19)) % 19to get the check digit.The distinction matters because:
Additional concern
The address encoding only accepts digits and dash (
/^[\d-]+$/), but Japan Post barcodes can encode alphanumeric characters using control character prefixes (CC1-CC4). Letters A-Z are encoded as CC prefix + digit pair.Verification needed
Cross-reference with the official Japan Post Customer Barcode Technical Specification and reference implementations (OkapiBarcode has a Java implementation).
References