-
Notifications
You must be signed in to change notification settings - Fork 30
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
base: master
Are you sure you want to change the base?
Changes from 8 commits
aed25ee
93834e2
31f9013
faf38a7
7f782ec
e9f35e1
bbcb0d8
d662f6b
2bc90d3
0853e0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
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 | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
}) | ||
|
||
|
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 | ||
` |
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 | ||
` |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ exports.CodeToKey = { | |
DCB: 'jurisdictionRestrictionCodes', | ||
DCD: 'jurisdictionEndorsementCodes', | ||
DBA: 'dateOfExpiry', | ||
DAA: 'fullName', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new DAA key |
||
DCS: 'lastName', | ||
DAC: 'firstName', | ||
DAD: 'middleName', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename data by state