Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MS sample data + new DAA field #27

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
15 changes: 13 additions & 2 deletions spec/parseUsdl.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const UsdlData1 = require('./sample/index').UsdlData1
const UsdlData2 = require('./sample/index').UsdlData2
const UsdlData3 = require('./sample/index').UsdlData3
const UsdlDataTN = require('./sample/index').UsdlDataTN
const UsdlDataMS = require('./sample/index').UsdlDataMS
Comment on lines +3 to +4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename data by state

const UsdlData_error = require('./sample/index').UsdlData_error
const UsdlData_invalid_characters = require('./sample/index').UsdlData_invalid_characters
const UsdlData_invalid_characters_2 = require('./sample/index').UsdlData_invalid_characters_2
Expand All @@ -14,13 +15,23 @@ describe('USDL Parser', () => {
expect(parsedData).toEqual(default_fixture)
})

it('should parse MS correct values', () => {
const parsedData = parse(UsdlDataMS, { suppressErrors: true })
console.log({ parsedData })
expect(parsedData.documentNumber).toEqual('802926467')
expect(parsedData.firstName).toEqual('JANICE')
expect(parsedData.lastName).toEqual('SMITH')
expect(parsedData.middleName).toEqual('C')
Comment on lines +20 to +23
Copy link
Contributor Author

@chancesmith chancesmith Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse full name into separate fields

})

it('should correctly identify female', () => {
const parsedData = parse(UsdlData2)
expect(parsedData.sex).toBe('F')
})

it('should correctly identify DL', () => {
const parsedData = parse(UsdlData3, {suppressErrors: true})
const parsedData = parse(UsdlDataTN, { suppressErrors: true })

expect(parsedData.documentNumber).toBe('099964088')
})

Expand Down
24 changes: 24 additions & 0 deletions spec/sample/data_MS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
exports.UsdlDataMS = `@

ANSI6360510101DL00290258DLDAQ802926467
DAASMITH,JANICE,C,
DAYBLU
DAG3546 HWY 22 N 21/102
DAISOUTHAVEN
DAJMS
DAK38671
DARR
DAS1
DAT
DAU504
DAW165
DBA20220329
DBB19340329
DBCF
DBD20170706
DBHN
DAL3546 HWY 22 N 21/102
DANSOUTHAVEN
DAOMS
DAP38671
`
36 changes: 36 additions & 0 deletions spec/sample/data_TN.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
exports.UsdlDataTN = `@

ANSI 636053060002DL00410258ZT02990037DLDAQ099964088
DCSSMITH
DDEU
DACJOHN
DDFU
DADFORD
DDGU
DCAD
DCBNONE
DCDNONE
DBD04112016
DBB04261966
DBA04112024
DBC1
DAU073 in
DAYHAZ
DAG123 WOW CV
DAIMEMPHIS
DAJAR
DAK383010000
DCF9911609514837257
DCGUSA
DCK161020014567280101
DDB12022121
DDK1

ZTZTAN
ZTBN
ZTC
ZTDN
ZTE1
ZTFN
ZTG00
`
3 changes: 2 additions & 1 deletion spec/sample/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
exports.UsdlData1 = require('./data_1').UsdlData1
exports.UsdlData2 = require('./data_2').UsdlData2
exports.UsdlData3 = require('./data_3').UsdlData3
exports.UsdlDataTN = require('./data_TN').UsdlDataTN
exports.UsdlDataMS = require('./data_MS').UsdlDataMS
exports.UsdlData_error = require('./data_error').UsdlData_error
exports.UsdlData_invalid_characters = require('./data_invalid_characters').UsdlData_invalid_characters
exports.UsdlData_invalid_characters_2 = require('./data_invalid_characters_2').UsdlData_invalid_characters_2
1 change: 1 addition & 0 deletions src/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports.CodeToKey = {
DCB: 'jurisdictionRestrictionCodes',
DCD: 'jurisdictionEndorsementCodes',
DBA: 'dateOfExpiry',
DAA: 'fullName',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new DAA key

DCS: 'lastName',
DAC: 'firstName',
DAD: 'middleName',
Expand Down
10 changes: 9 additions & 1 deletion src/parseUsdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ exports.parse = function parseCode128(str, options = defaultOptions) {
const props = {}
const rawLines = str.trim().split(lineSeparator)
const lines = rawLines.map((rawLine) => sanitizeData(rawLine))
// console.log(lines)
let started
lines.slice(0, -1).forEach((line) => {
if (!started) {
if (line.indexOf('ANSI ') === 0) {
if (line.indexOf('ANSI') === 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove space from ANSI to check for MS when space doesn't exist

started = true

// has DLDAQ
Expand All @@ -38,6 +39,13 @@ exports.parse = function parseCode128(str, options = defaultOptions) {
}
}

if (code === 'DAA') {
const nameArray = value.split(',')
props.firstName = nameArray[1]
props.lastName = nameArray[0]
props.middleName = nameArray[2]
}
Comment on lines +41 to +46
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

past full name to separate fields


if (isSexField(code)) value = getSex(code, value)

props[key] = isDateField(key) ? getDateFormat(value) : value
Expand Down