Skip to content

Commit

Permalink
Start implementing 7xxx AIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleavely committed Feb 5, 2020
1 parent 0e8518c commit 0fb72d6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/gs1/applicationIdentifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
fixedLength,
variableLength,
date,
dateRange,
fixedLengthDecimal,
variableLengthDecimal,
variableLengthISOCurrency,
Expand Down Expand Up @@ -289,6 +290,52 @@ exports.parseAi = (barcode) => {
return { ai: '427', title: 'ORIGIN SUBDIVISION', parser: variableLength(3) }
}
break
case '7':
switch (barcode.slice(1, 3)) {
case '00':
switch (barcode.slice(3, 4)) {
case '1':
case '2':
case '3':
case '4':
case '5':
return { ai: '700*', title: 'UNKNOWN', parser: variableLength(30) }
case '6':
return { ai: '7006', title: 'FIRST FREEZE DATE', parser: date() }
case '7':
return { ai: '7007', title: 'HARVEST DATE', parser: dateRange() }
case '8':
return { ai: '7008', title: 'AQUATIC SPECIES', parser: variableLength(3) }
case '9':
return { ai: '7009', title: 'FISHING GEAR TYPE', parser: variableLength(10) }
}
break
case '01':
return { ai: '7010',
title: 'PROD METHOD',
parser: (opts) => (output => {
const humanMapping = {
'01': 'Caught at Sea',
'02': 'Caught in Fresh Water',
'03': 'Farmed',
'04': 'Cultivated',
}
return { ...output, human: humanMapping[output.value] }
})(variableLength(2)(opts)) }

case '02':
switch (barcode.slice(3, 4)) {
case '0':
return { ai: '7020', title: '???' }
case '1':
return { ai: '7020', title: '???' }
case '2':
return { ai: '7020', title: '???' }
case '3':
return { ai: '7020', title: '???' }
}
}
break
case '8':
switch (barcode.slice(1, 4)) {
case '200':
Expand Down
12 changes: 12 additions & 0 deletions src/gs1/applicationIdentifiers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,19 @@ it.each([
const {
ai,
title,
parser,
} = parseAi(expectedAi)
expect(ai).toBe(expectedAi)
expect(title).toBe(expectedTitle)
expect(parser).toBeFunction()
})

describe('custom parsers', () => {
it('appends human readable values for AI 7010', () => {
const { parser } = parseAi('7010')
expect(parser({ barcode: '02' })).toMatchObject({
value: '02',
human: 'Caught in Fresh Water',
})
})
})

0 comments on commit 0fb72d6

Please sign in to comment.