Modes 2 and 3 are used for parcel carrier labels (like UPS) to pack a 60-bit primary message (postal code, country, and service class) ahead of the secondary message.
- Mode 2: Uses a numeric postcode. A 5-digit US ZIP (country 840) is zero-filled to 9 digits. The postcode must be 1–9 digits.
- Mode 3: Uses an alphanumeric postcode (1–6 characters from
A-Z, space, and ASCII range " to :).
If the postalCode is malformed (e.g., non-numeric in Mode 2, or out-of-charset in Mode 3), the library will throw an InvalidInputError.
import { maxicode } from "etiket"
// US: numeric ZIP+4 (Mode 2)
maxicode("SHIPMENT 4711", {
mode: 2,
postalCode: "12345",
countryCode: 840,
serviceClass: 1,
})
// UK: alphanumeric postcode (Mode 3)
maxicode("PACKAGE", {
mode: 3,
postalCode: "SN34RD",
countryCode: 826,
serviceClass: 11,
})