From aed25ee8b2aa2ad271fa5b4fa2342ff68ac1e4e8 Mon Sep 17 00:00:00 2001 From: Chance Smith Date: Mon, 6 Dec 2021 15:26:46 -0600 Subject: [PATCH 1/8] add DLDAQ --- src/keys.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/keys.js b/src/keys.js index 68a972e..faf045d 100644 --- a/src/keys.js +++ b/src/keys.js @@ -18,6 +18,7 @@ exports.CodeToKey = { DAJ: 'addressState', DAK: 'addressPostalCode', DAQ: 'documentNumber', + DLDAQ: 'documentNumberAlt', DCF: 'documentDiscriminator', DCG: 'issuer', DDE: 'lastNameTruncated', From 93834e2418acb99d3774f9e178c4082057f448f0 Mon Sep 17 00:00:00 2001 From: Chance Date: Mon, 6 Dec 2021 16:03:06 -0600 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=93=A6=20=20FEAT:=20[parseUsdl]=20add?= =?UTF-8?q?=20DLDAQ=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/parseUsdl.spec.js | 6 ++++++ spec/sample/data_3.js | 36 ++++++++++++++++++++++++++++++++++++ spec/sample/index.js | 1 + src/keys.js | 1 - src/parseUsdl.js | 10 +++++++++- 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 spec/sample/data_3.js diff --git a/spec/parseUsdl.spec.js b/spec/parseUsdl.spec.js index b93204a..cdb0d54 100644 --- a/spec/parseUsdl.spec.js +++ b/spec/parseUsdl.spec.js @@ -1,5 +1,6 @@ const UsdlData1 = require('./sample/index').UsdlData1 const UsdlData2 = require('./sample/index').UsdlData2 +const UsdlData3 = require('./sample/index').UsdlData3 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 @@ -18,6 +19,11 @@ describe('USDL Parser', () => { expect(parsedData.sex).toBe('F') }) + it('should correctly identify DL', () => { + const parsedData = parse(UsdlData3, {suppressErrors: true}) + expect(parsedData.documentNumber).toBe('099964088') + }) + it('should not throw error if invalid code is passed and warming suppress is on', () => { function parseData() { return parse(UsdlData_error, { suppressErrors: true }) diff --git a/spec/sample/data_3.js b/spec/sample/data_3.js new file mode 100644 index 0000000..65ad271 --- /dev/null +++ b/spec/sample/data_3.js @@ -0,0 +1,36 @@ +exports.UsdlData3 = `@ + +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 +` diff --git a/spec/sample/index.js b/spec/sample/index.js index aed9603..f332a8f 100644 --- a/spec/sample/index.js +++ b/spec/sample/index.js @@ -1,5 +1,6 @@ exports.UsdlData1 = require('./data_1').UsdlData1 exports.UsdlData2 = require('./data_2').UsdlData2 +exports.UsdlData3 = require('./data_3').UsdlData3 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 diff --git a/src/keys.js b/src/keys.js index faf045d..68a972e 100644 --- a/src/keys.js +++ b/src/keys.js @@ -18,7 +18,6 @@ exports.CodeToKey = { DAJ: 'addressState', DAK: 'addressPostalCode', DAQ: 'documentNumber', - DLDAQ: 'documentNumberAlt', DCF: 'documentDiscriminator', DCG: 'issuer', DDE: 'lastNameTruncated', diff --git a/src/parseUsdl.js b/src/parseUsdl.js index f26cb42..c9aba5f 100644 --- a/src/parseUsdl.js +++ b/src/parseUsdl.js @@ -13,13 +13,21 @@ exports.parse = function parseCode128(str, options = defaultOptions) { if (!started) { if (line.indexOf('ANSI ') === 0) { started = true + + // has DLDAQ + if(line.indexOf('DLDAQ') !== -1) { + const lineArray = line.split('DLDAQ') + line = 'DAQ' + lineArray[1] + } + } else { + return } - return } let code = getCode(line) let value = getValue(line) let key = getKey(code) + if (!key) { if (options.suppressErrors) { return From 31f9013d488aa1f3c5a3d2a9b37d729f6ab4425c Mon Sep 17 00:00:00 2001 From: Chance Smith Date: Tue, 7 Dec 2021 09:51:27 -0600 Subject: [PATCH 3/8] [parseUsdl] slim down DLDAQ conditional --- src/parseUsdl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parseUsdl.js b/src/parseUsdl.js index c9aba5f..675327f 100644 --- a/src/parseUsdl.js +++ b/src/parseUsdl.js @@ -15,7 +15,7 @@ exports.parse = function parseCode128(str, options = defaultOptions) { started = true // has DLDAQ - if(line.indexOf('DLDAQ') !== -1) { + if(line.includes('DLDAQ')) { const lineArray = line.split('DLDAQ') line = 'DAQ' + lineArray[1] } From faf38a7d5f6921f8d0d76781b9771c1407efc02e Mon Sep 17 00:00:00 2001 From: Chance Date: Tue, 7 Dec 2021 10:11:59 -0600 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=90=9B=20=20FIX:=20[parsedl]=20fix=20?= =?UTF-8?q?tests=20by=20skipping=20ANSI=20if=20no=20DLDAQ=20case=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parseUsdl.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/parseUsdl.js b/src/parseUsdl.js index 675327f..996a09d 100644 --- a/src/parseUsdl.js +++ b/src/parseUsdl.js @@ -15,9 +15,11 @@ exports.parse = function parseCode128(str, options = defaultOptions) { started = true // has DLDAQ - if(line.includes('DLDAQ')) { + if (line.includes('DLDAQ')) { const lineArray = line.split('DLDAQ') line = 'DAQ' + lineArray[1] + } else { + return } } else { return From 7f782ece5e500f85e68ae4f8c08d278d6e757744 Mon Sep 17 00:00:00 2001 From: Chance Date: Tue, 7 Dec 2021 11:47:20 -0600 Subject: [PATCH 5/8] =?UTF-8?q?=E2=9A=A1=20=20REFACTOR:=20rename=20data3?= =?UTF-8?q?=20to=20UsdlDataTN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/parseUsdl.spec.js | 4 ++-- spec/sample/{data_3.js => data_TN.js} | 2 +- spec/sample/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename spec/sample/{data_3.js => data_TN.js} (84%) diff --git a/spec/parseUsdl.spec.js b/spec/parseUsdl.spec.js index cdb0d54..bcd2cb6 100644 --- a/spec/parseUsdl.spec.js +++ b/spec/parseUsdl.spec.js @@ -1,6 +1,6 @@ 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 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 @@ -20,7 +20,7 @@ describe('USDL Parser', () => { }) it('should correctly identify DL', () => { - const parsedData = parse(UsdlData3, {suppressErrors: true}) + const parsedData = parse(UsdlDataTN, { suppressErrors: true }) expect(parsedData.documentNumber).toBe('099964088') }) diff --git a/spec/sample/data_3.js b/spec/sample/data_TN.js similarity index 84% rename from spec/sample/data_3.js rename to spec/sample/data_TN.js index 65ad271..3d6f45c 100644 --- a/spec/sample/data_3.js +++ b/spec/sample/data_TN.js @@ -1,4 +1,4 @@ -exports.UsdlData3 = `@ +exports.UsdlDataTN = `@  ANSI 636053060002DL00410258ZT02990037DLDAQ099964088 DCSSMITH diff --git a/spec/sample/index.js b/spec/sample/index.js index f332a8f..556421c 100644 --- a/spec/sample/index.js +++ b/spec/sample/index.js @@ -1,6 +1,6 @@ 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.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 From e9f35e1afac6c883e5f78fcd050d22d5b6884420 Mon Sep 17 00:00:00 2001 From: Chance Date: Tue, 7 Dec 2021 14:03:07 -0600 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=93=A6=20=20FEAT:=20[parseUsdl]=20add?= =?UTF-8?q?=20for=20DAA=20and=20parse=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/parseUsdl.spec.js | 10 ++++++++++ spec/sample/data_MS.js | 24 ++++++++++++++++++++++++ spec/sample/index.js | 1 + src/keys.js | 1 + src/parseUsdl.js | 10 +++++++++- 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 spec/sample/data_MS.js diff --git a/spec/parseUsdl.spec.js b/spec/parseUsdl.spec.js index bcd2cb6..f09d094 100644 --- a/spec/parseUsdl.spec.js +++ b/spec/parseUsdl.spec.js @@ -1,6 +1,7 @@ const UsdlData1 = require('./sample/index').UsdlData1 const UsdlData2 = require('./sample/index').UsdlData2 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,6 +15,15 @@ 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') + }) + it('should correctly identify female', () => { const parsedData = parse(UsdlData2) expect(parsedData.sex).toBe('F') diff --git a/spec/sample/data_MS.js b/spec/sample/data_MS.js new file mode 100644 index 0000000..2df8a2c --- /dev/null +++ b/spec/sample/data_MS.js @@ -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 +` diff --git a/spec/sample/index.js b/spec/sample/index.js index 556421c..6949ea0 100644 --- a/spec/sample/index.js +++ b/spec/sample/index.js @@ -1,6 +1,7 @@ exports.UsdlData1 = require('./data_1').UsdlData1 exports.UsdlData2 = require('./data_2').UsdlData2 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 diff --git a/src/keys.js b/src/keys.js index 68a972e..e41fa33 100644 --- a/src/keys.js +++ b/src/keys.js @@ -5,6 +5,7 @@ exports.CodeToKey = { DCB: 'jurisdictionRestrictionCodes', DCD: 'jurisdictionEndorsementCodes', DBA: 'dateOfExpiry', + DAA: 'fullName', DCS: 'lastName', DAC: 'firstName', DAD: 'middleName', diff --git a/src/parseUsdl.js b/src/parseUsdl.js index 996a09d..62c14bf 100644 --- a/src/parseUsdl.js +++ b/src/parseUsdl.js @@ -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) { 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] + } + if (isSexField(code)) value = getSex(code, value) props[key] = isDateField(key) ? getDateFormat(value) : value From 2bc90d3d127f0f595a656f27b06c60a9de2e2670 Mon Sep 17 00:00:00 2001 From: Chance Smith Date: Tue, 7 Dec 2021 14:21:38 -0600 Subject: [PATCH 7/8] remove log --- spec/parseUsdl.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/parseUsdl.spec.js b/spec/parseUsdl.spec.js index f8e30b3..e9f1167 100644 --- a/spec/parseUsdl.spec.js +++ b/spec/parseUsdl.spec.js @@ -17,7 +17,6 @@ describe('USDL Parser', () => { 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') From 0853e0e4ce766d9d6964cc993d77bfd0ff13fa57 Mon Sep 17 00:00:00 2001 From: Chance Smith Date: Tue, 7 Dec 2021 14:24:20 -0600 Subject: [PATCH 8/8] [parseUsdl] remove log --- src/parseUsdl.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/parseUsdl.js b/src/parseUsdl.js index 62c14bf..3d9ce93 100644 --- a/src/parseUsdl.js +++ b/src/parseUsdl.js @@ -8,7 +8,6 @@ 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) {