IMB
Simple encoder and decoder for the USPS' IMB service based on:
In that spirit, I've included their comment below:
USPS "Intelligent Mail Barcode" Decoder
You may use this code for any purpose, with no restrictions. However, there is NO WARRANTY for this code; use it at your own risk. This work is released under the Creative Commons Zero License. To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
This is a simple and small module (6kb) designed to easily transform an IMB ready object to an IMB String and back again. It supports both synchronous and asynchronous (callback) implementations.
Encoding
Synchronous
const imb = ; const imb_string = imb; // Result// ATTFAATTFTADFDATDDADAATTTTTTTTADFFFFFDFAFATTDAADATDDDTADAFFDFDTFT
Asynchronous
const imb = ; imb;
Decoding
Synchronous
const imb = ; const imb_object = imb; // imb_object// { // barcode_id: '12',// service_type: '234',// mailer_id: '567094',// serial_num: '987654321' // }
Asynchronous
const imb = ; imb;
CLI
I have included a basic CLI that should help easily encode or decode single records.
Option | Descriptive | Abbreviated | Meaning |
---|---|---|---|
Type | --type | -t | "encode" or "decode" |
Barcode | --barcode | -b | Automatically set type to 'decode' and decode value |
You should be able to encode an object using:
$ imb? Would you like to encode or decode an IMB? encode ❯ decode? Delivery Point 2-Characters :? Zip :? Zip Plus 4 :? Barcode ID: 12? Service Type: 234? USPS Mailer ID: 567094? USPS Serial Number: 987654321 Encoded output ATTFAATTFTADFDATDDADAATTTTTTTTADFFFFFDFAFATTDAADATDDDTADAFFDFDTFT
And decoding an object is even easier:
$ imb? Would you like to encode or decode an IMB? encode ❯ decode? Barcode String: ATTFAATTFTADFDATDDADAATTTTTTTTADFFFFFDFAFATTDAADATDDDTADAFFDFDTFT Decoded output barcode_id: 12 service_type: 234 mailer_id: 567094 serial_num: 987654321
Alternatively, Decoding is the default behavior so you can simply run:
$ imb ATTFAATTFTADFDATDDADAATTTTTTTTADFFFFFDFAFATTDAADATDDDTADAFFDFDTFT Decoded output barcode_id: 12 service_type: 234 mailer_id: 567094 serial_num: 987654321
Support
Hey,
I hope that you were able to find this module helpful. If so, let me know! Who doesn't love hearing that they made a difference, even if it's a little one. Don't worry, it's totally free - but if it really made a difference, you can send a little love using the link below 🍻!
Cheers!