Sleavely / Bark-JS

🔬 Parse barcode inputs 🏷️ in a unified GS1-128 format 📦🌐
Other
28 stars 8 forks source link

Parse Issue #8

Closed arthurbrazil closed 3 years ago

arthurbrazil commented 3 years ago

I have two similar barcodes. One will scan correctly and the other will not: Produces Error (Uncaught Error: Invalid AI at start of barcode: 197): 01108573260055401722081110A2021121092220084115197 Does Not Produce Error: 01108573260055401721102910A1905221042920115956137

arthurbrazil commented 3 years ago

It seems that on both, bark is unable to pick up AI (21) which is the identifier for serial number

Sleavely commented 3 years ago

Hi @arthurbrazil,

Does your scanner include FNC characters? Because AI 10 (Batch/Lot) is variable-length, Bark will read each character and assume it belongs to the previous AI until it has reached the max length allowed (which is 20 characters for AI 10) unless it encounters an FNC character (default is ASCII 29, or commonly referred to as <GS> (group separator)).

In this case it looks like there is no FNC in either of the codes, so the Batch/Lot gets allocated 20 characters, leaving only the last 3 characters of the string to be interpreted as AIs.

For the sake of illustrating, I'm manually overriding the default with a _.

bark('01108573260055401722081110A20_21121092220084115197', { fnc: '_' }).elements

[
  {
    ai: '01',
    title: 'GTIN',
    value: '10857326005540',
    raw: '10857326005540'
  },
  {
    ai: '17',
    title: 'USE BY OR EXPIRY',
    value: '2022-08-11',
    raw: '220811'
  },
  {
    ai: '10',
    title: 'BATCH/LOT',
    value: 'A20',
    raw: 'A20_'
  },
  {
    ai: '21',
    title: 'SERIAL',
    value: '121092220084115197',
    raw: '121092220084115197'
  }
]

A lot of AIs are variable length so it's important that your barcodes are generated with GS1-128-compatible software, and that your scanner is configured to include these "invisible" characters for parsing to succeed.

Sleavely commented 3 years ago

Closing this for now, feel free to reopen or create a new issue if you have additional questions.