From 66ede20c611d9224a12e12a7038770e739e617e3 Mon Sep 17 00:00:00 2001 From: RPacetti Date: Thu, 22 Feb 2018 13:20:50 -0700 Subject: [PATCH 1/3] Add all current versions, date and version methods, updated example --- README.md | 27 +++--- example.html | 98 ++++++++++---------- index.js | 249 +++++++++++++++++++++++++++++++++++++++++++-------- package.json | 66 +++++++++----- 4 files changed, 323 insertions(+), 117 deletions(-) diff --git a/README.md b/README.md index 57e3edf..47b53fe 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://drone.io/github.com/winfinit/aamvajs/status.png)](https://drone.io/github.com/winfinit/aamvajs/latest) + # aamva.js small helper library that provides one an ability to parse AAMVA magnetic stripe. @@ -30,21 +32,21 @@ and I would love to add support or fix things that are not working yet** '; var res = aamva.stripe(stripe_data); - console.log("DMV ID:",res.id()); /* D621720820090 */ - console.log("First name:",res.name().first); /* JOHN */ - console.log("Last name:",res.name().last); /* DOE */ - console.log("Middle name:",res.name().middle); /* "" */ - console.log("Sex:",res.sex()); /* MALE, FEMALE, MISSING/INVALID */ - console.log("DOB:",res.birthday()); /* Thu Jan 08 1987 00:00:00 GMT-0500 (EST) */ + console.log("DMV ID:",res.id); /* D621720820090 */ + console.log("First name:",res.name.first); /* JOHN */ + console.log("Last name:",res.name.last); /* DOE */ + console.log("Middle name:",res.name.middle); /* "" */ + console.log("Sex:",res.sex); /* MALE, FEMALE, MISSING/INVALID */ + console.log("DOB:",res.birthday); /* Thu Jan 08 1987 00:00:00 GMT-0500 (EST) */ console.log("Entire object", res); var res2 = aamva.pdf417(barcode_data); - console.log("DMV ID:",res2.id()); /* D621720820090 */ - console.log("First name:",res2.name().first); /* JOHN */ - console.log("Last name:",res2.name().last); /* DOE */ - console.log("Middle name:",res2.name().middle); /* "" */ - console.log("Sex:",res2.sex()); /* MALE, FEMALE, MISSING/INVALID */ - console.log("DOB:",res2.birthday()); /* Thu Jan 08 1987 00:00:00 GMT-0500 (EST) */ + console.log("DMV ID:",res2.id); /* D621720820090 */ + console.log("First name:",res2.name.first); /* JOHN */ + console.log("Last name:",res2.name.last); /* DOE */ + console.log("Middle name:",res2.name.middle); /* "" */ + console.log("Sex:",res2.sex); /* MALE, FEMALE, MISSING/INVALID */ + console.log("DOB:",res2.birthday); /* Thu Jan 08 1987 00:00:00 GMT-0500 (EST) */ console.log("Entire object", res2); /* @@ -100,6 +102,7 @@ If you find a bug or willing to add some enhancement, pull requests are very wel * 0.0.12 fixed duplicate name key * 0.0.13 added pdf417 support, added example page, and changed plugin to be compatible with browser * 0.0.16 fixed version regex for pdf417, and added MD tests. +* 1.2.0 added all current versions, version and date parsing functions, updated example ## Legal diff --git a/example.html b/example.html index 7e1290c..4a2a308 100644 --- a/example.html +++ b/example.html @@ -1,59 +1,65 @@ + - - + + - - +

-                
+		
 
-                
-

Sample data

-

Florida stripe

-
+		
+

Sample data

+

Florida stripe

+
 %FLDELRAY DESERT^DOE$JOHN$^5929 N ROCK BLVD^                            ?;6360101062271087008=2101198799080=?#! 44556      I               1600                                   ECCECC00000?
-                
+
-

Florida PDF417

-
+		

Florida PDF417

+
 @ANSI 6360100102DL00390190ZF02290063DLDAADOE,JOHNDAG5929 N ROCK STDAIDELRAY SHOREDAJFLDAK44556-     DAQJ621625830080DARI   DAS          DAT     DBA20210108DBB19770204DBC1DBD20120612DBHN         DAU600ZFZFAREPLACED: 00000000ZFB ZFCP771206120090ZFD ZFE07-01-11
-                
- +
diff --git a/index.js b/index.js index 0b97184..644f629 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ (function(global) { + // parse any data var parse = function(data) { data = data.replace(/\n/, ""); // replace spaces with regular space @@ -15,6 +16,7 @@ } }; + // reformats MMDDYYYY dates to YYYYMMDD var parseDate = function(date) { var start = parseInt(date[0] + date[1]); if (start < 13) { @@ -23,6 +25,24 @@ return date; }; + // splits dates into month, day, and year + var splitDate = function(date) { + var start = parseInt(date[0] + date[1]); + if (start < 13) { + return { + year: date[4] + date[5] + date[6] + date[7], + month: date[0] + date[1], + day: date[2] + date[3] + } + } + return { + year: date[0] + date[1] + date[2] + date[3], + month: date[4] + date[5], + day: date[6] + date[7] + } + }; + + // parse magstripe data var stripe = function(data) { data = data.replace(/\n/, ""); // replace spaces with regular space @@ -106,15 +126,28 @@ }; }; - var pdf417 = function(data) { + // determines the version of the pdf417 data + var pdf417version = function(data) { data = data.replace(/\n/, ""); // replace spaces with regular space data = data.replace(/\s/g, " "); - // get version of aamva (before 2000 or after) - var version = data.match(/[A-Z ]{5}\d{6}(\d{2})/); + if ( /^@/.test(data) === true ) { + // get version of aamva + var version = data.match(/[A-Z ]{5}\d{6}(\d{2})/); + return version[1]; + } + return 0; + }; + // parses pdf417 data + var pdf417 = function(data) { + data = data.replace(/\n/, ""); + // replace spaces with regular space + data = data.replace(/\s/g, " "); + // get version of aamva + var version = data.match(/[A-Z ]{5}\d{6}(\d{2})/); var parseRegex; @@ -122,7 +155,6 @@ switch (Number(version[1])) { case 1: { parseRegex = new RegExp( - '(DAQ.*?)?' + // Drivers license number '(DAA.*?)?' + // Driver License Name '(DAG.*?)?' + // Driver Mailing Street Address '(DAI.*?)?' + // Driver Mailing City @@ -188,18 +220,14 @@ '(DCD.*?)?' + // Jurisdiction-specific endorsement codes '(DBA.*?)?' + // Document Expiration Date '(DCS.*?)?' + // Customer Family Name - '(DCT.*?)?' + // Customer Given Names - '(DCU.*?)?' + // Name Suffix '(DBD.*?)?' + // Document Issue Date '(DBB.*?)?' + // Date of Birth - '(DBC.*?)?' + // Physical Description – Sex '(DAY.*?)?' + // Physical Description – Eye Color '(DAU.*?)?' + // Physical Description – Height '(DCE.*?)?' + // Physical Description – Weight Range - '(DAG.*?)?' + // Address – Street 1 '(DAI.*?)?' + // Address – City '(DAJ.*?)?' + // Address – Jurisdiction Code @@ -208,7 +236,6 @@ '(DCF.*?)?' + // Document Discriminator '(DCG.*?)?' + // Country Identification '(DCH.*?)?' + // Federal Commercial Vehicle Codes - /* optional elements '(DAH.*?)?' + // Address – Street 2 '(DAZ.*?)?' + // Hair color @@ -217,7 +244,6 @@ '(DCK.*?)?' + // Inventory control number '(DBN.*?)?' + // Alias / AKA Family Name '(DCL.*?)?' + // Race / ethnicity - '(DCM.*?)?' + // Standard vehicle classification '(DCN.*?)?' + // Standard endorsement code '(DCO.*?)?' + // Standard restriction code @@ -274,36 +300,181 @@ ); break; } + /* version 04 year 2009 */ + case 4: { + parseRegex = new RegExp( + '(DCA.*?)?' + // Jurisdiction-specific vehicle class + '(DCB.*?)?' + // Jurisdiction-specific restriction codes + '(DCD.*?)?' + // Jurisdiction-specific endorsement codes + '(DBA.*?)?' + // Document Expiration Date + '(DCS.*?)?' + // Customer Family Name + '(DAC.*?)?' + // Customer First Name + '(DAD.*?)?' + // Customer Middle Name(s) + '(DBD.*?)?' + // Document Issue Date + '(DBB.*?)?' + // Date of Birth + '(DBC.*?)?' + // Physical Description – Sex + '(DAY.*?)?' + // Physical Description – Eye Color + '(DAU.*?)?' + // Physical Description – Height + '(DAG.*?)?' + // Address – Street 1 + '(DAI.*?)?' + // Address – City + '(DAJ.*?)?' + // Address – Jurisdiction Code + '(DAK.*?)?' + // Address – Postal Code + '(DAQ.*?)?' + // Customer ID Number + '(DCF.*?)?' + // Document Discriminator + '(DCG.*?)?' + // Country Identification + '(DDE.*?)?' + // Family name truncation + '(DDF.*?)?' + // First name truncation + '(DDG.*?)?' + // Middle name truncation + /* optional elements + '(DAH.*?)?' + // Address – Street 2 + '(DAZ.*?)?' + // Hair color + '(DCI.*?)?' + // Place of birth + '(DCJ.*?)?' + // Audit information + '(DCK.*?)?' + // Inventory control number + '(DBN.*?)?' + // Alias / AKA Family Name + '(DBG.*?)?' + // Alias / AKA Given Name + '(DBS.*?)?' + // Alias / AKA Suffix Name + '(DCU.*?)?' + // Name Suffix + '(DCE.*?)?' + // Physical Description – Weight Range + '(DCL.*?)?' + // Race / ethnicity + '(DCM.*?)?' + // Standard vehicle classification + '(DCN.*?)?' + // Standard endorsement code + '(DCO.*?)?' + // Standard restriction code + '(DCP.*?)?' + // Jurisdiction- specific vehicle classification description + '(DCQ.*?)?' + // Jurisdiction- specific endorsement code description + '(DCR.*?)?' + // Jurisdiction- specific restriction code description + '(DDA.*?)?' + // Compliance Type + '(DDB.*?)?' + // Card Revision Date + '(DDC.*?)?' + // HAZMAT Endorsement Expiration Date + '(DDD.*?)?' + // Limited Duration Document Indicator + '(DAW.*?)?' + // Weight (pounds) + '(DAX.*?)?' // Weight (kilograms) + */ + '$' + ); + break; + } + /* version 05 year 2010 */ + case 5: { + parseRegex = new RegExp( + '(DCA.*?)?' + // Jurisdiction-specific vehicle class + '(DCB.*?)?' + // Jurisdiction-specific restriction codes + '(DCD.*?)?' + // Jurisdiction-specific endorsement codes + '(DBA.*?)?' + // Document Expiration Date + '(DCS.*?)?' + // Customer Family Name + '(DAC.*?)?' + // Customer First Name + '(DAD.*?)?' + // Customer Middle Name(s) + '(DBD.*?)?' + // Document Issue Date + '(DBB.*?)?' + // Date of Birth + '(DBC.*?)?' + // Physical Description – Sex + '(DAY.*?)?' + // Physical Description – Eye Color + '(DAU.*?)?' + // Physical Description – Height + '(DAG.*?)?' + // Address – Street 1 + '(DAI.*?)?' + // Address – City + '(DAJ.*?)?' + // Address – Jurisdiction Code + '(DAK.*?)?' + // Address – Postal Code + '(DAQ.*?)?' + // Customer ID Number + '(DCF.*?)?' + // Document Discriminator + '(DCG.*?)?' + // Country Identification + '(DDE.*?)?' + // Family name truncation + '(DDF.*?)?' + // First name truncation + '(DDG.*?)?' + // Middle name truncation + /* optional elements + '(DAH.*?)?' + // Address – Street 2 + '(DAZ.*?)?' + // Hair color + '(DCI.*?)?' + // Place of birth + '(DCJ.*?)?' + // Audit information + '(DCK.*?)?' + // Inventory control number + '(DBN.*?)?' + // Alias / AKA Family Name + '(DBG.*?)?' + // Alias / AKA Given Name + '(DBS.*?)?' + // Alias / AKA Suffix Name + '(DCU.*?)?' + // Name Suffix + '(DCE.*?)?' + // Physical Description – Weight Range + '(DCL.*?)?' + // Race / ethnicity + '(DCM.*?)?' + // Standard vehicle classification + '(DCN.*?)?' + // Standard endorsement code + '(DCO.*?)?' + // Standard restriction code + '(DCP.*?)?' + // Jurisdiction- specific vehicle classification description + '(DCQ.*?)?' + // Jurisdiction- specific endorsement code description + '(DCR.*?)?' + // Jurisdiction- specific restriction code description + '(DDA.*?)?' + // Compliance Type + '(DDB.*?)?' + // Card Revision Date + '(DDC.*?)?' + // HAZMAT Endorsement Expiration Date + '(DDD.*?)?' + // Limited Duration Document Indicator + '(DAW.*?)?' + // Weight (pounds) + '(DAX.*?)?' + // Weight (kilograms) + '(DDH.*?)?' + // Under 18 Until + '(DDI.*?)?' + // Under 19 Until + '(DDJ.*?)?' // Under 21 Until + */ + '$' + ); + break; + } + /* version 06 year 2011 */ case 6: { - parseRegex = new RegExp( - '(DAQ.*?)?' + - '(DCS.*?)?' + - '(DDE.*?)?' + - '(DAC.*?)?' + - '(DDF.*?)?' + - '(DAD.*?)?' + - '(DDG.*?)?' + - '(DCA.*?)?' + - '(DCB.*?)?' + - '(DCD.*?)?' + - '(DBD.*?)?' + - '(DBB.*?)?' + - '(DBA.*?)?' + - '(DBC.*?)?' + - '(DAU.*?)?' + - '(DAY.*?)?' + - '(DAG.*?)?' + - '(DAI.*?)?' + - '(DAJ.*?)?' + - '(DAK.*?)?' + - '(DCF.*?)?' + - /* optional */ - '$' - ); - break; + parseRegex = new RegExp( + '(DCA.*?)?' + // Jurisdiction-specific vehicle class + '(DCB.*?)?' + // Jurisdiction-specific restriction codes + '(DCD.*?)?' + // Jurisdiction-specific endorsement codes + '(DBA.*?)?' + // Document Expiration Date + '(DCS.*?)?' + // Customer Family Name + '(DAC.*?)?' + // Customer First Name + '(DAD.*?)?' + // Customer Middle Name(s) + '(DBD.*?)?' + // Document Issue Date + '(DBB.*?)?' + // Date of Birth + '(DBC.*?)?' + // Physical Description – Sex + '(DAY.*?)?' + // Physical Description – Eye Color + '(DAU.*?)?' + // Physical Description – Height + '(DAG.*?)?' + // Address – Street 1 + '(DAI.*?)?' + // Address – City + '(DAJ.*?)?' + // Address – Jurisdiction Code + '(DAK.*?)?' + // Address – Postal Code + '(DAQ.*?)?' + // Customer ID Number + '(DCF.*?)?' + // Document Discriminator + '(DCG.*?)?' + // Country Identification + '(DDE.*?)?' + // Family name truncation + '(DDF.*?)?' + // First name truncation + '(DDG.*?)?' + // Middle name truncation + /* optional elements + '(DAH.*?)?' + // Address – Street 2 + '(DAZ.*?)?' + // Hair color + '(DCI.*?)?' + // Place of birth + '(DCJ.*?)?' + // Audit information + '(DCK.*?)?' + // Inventory control number + '(DBN.*?)?' + // Alias / AKA Family Name + '(DBG.*?)?' + // Alias / AKA Given Name + '(DBS.*?)?' + // Alias / AKA Suffix Name + '(DCU.*?)?' + // Name Suffix + '(DCE.*?)?' + // Physical Description – Weight Range + '(DCL.*?)?' + // Race / ethnicity + '(DCM.*?)?' + // Standard vehicle classification + '(DCN.*?)?' + // Standard endorsement code + '(DCO.*?)?' + // Standard restriction code + '(DCP.*?)?' + // Jurisdiction- specific vehicle classification description + '(DCQ.*?)?' + // Jurisdiction- specific endorsement code description + '(DCR.*?)?' + // Jurisdiction- specific restriction code description + '(DDA.*?)?' + // Compliance Type + '(DDB.*?)?' + // Card Revision Date + '(DDC.*?)?' + // HAZMAT Endorsement Expiration Date + '(DDD.*?)?' + // Limited Duration Document Indicator + '(DAW.*?)?' + // Weight (pounds) + '(DAX.*?)?' + // Weight (kilograms) + '(DDH.*?)?' + // Under 18 Until + '(DDI.*?)?' + // Under 19 Until + '(DDJ.*?)?' + // Under 21 Until + '(DDK.*?)?' // Organ Donor Indicator + */ + '$' + ); + break; } /* version 07 year 2012 */ - case 7: { + /* version 08 year 2013 */ + /* version 09 year 2016 */ + case 7: + case 8: + case 9: { parseRegex = new RegExp( '(DCA.*?)?' + // Jurisdiction-specific vehicle class '(DCB.*?)?' + // Jurisdiction-specific restriction codes @@ -468,10 +639,10 @@ return rawData; }; - - global.parse = parse; global.stripe = stripe; global.pdf417 = pdf417; + global.pdf417version = pdf417version; + global.splitDate = splitDate; }(this)); diff --git a/package.json b/package.json index 725a8d5..c32624b 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,43 @@ { - "name": "aamva", - "version": "1.1.0", - "description": "Parse AAMVA magnetic stripe", - "main": "index.js", - "scripts": { - "test": "make test" + "_from": "aamva", + "_id": "aamva@1.2.0", + "_inBundle": false, + "_integrity": "sha1-a8MKXv+CFIOBY9B6oNYODV05cPc=", + "_location": "/aamva", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "aamva", + "name": "aamva", + "escapedName": "aamva", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" }, - "repository": { - "type": "git", - "url": "https://github.com/winfinit/aamvajs.git" + "_requiredBy": [ + "#USER" + ], + "_resolved": "https://registry.npmjs.org/aamva/-/aamva-1.1.0.tgz", + "_shasum": "6bc30a5eff8214838163d07aa0d60e0d5d3970f7", + "_spec": "aamva", + "_where": "C:\\Users\\rpacetti", + "author": { + "name": "Roman Jurkov", + "email": "winfinit@gmail.com" + }, + "bugs": { + "url": "https://github.com/winfinit/aamvajs/issues" }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "Parse AAMVA magnetic stripe", + "devDependencies": { + "chai": "^1.9.1", + "mocha": "^1.21.4" + }, + "homepage": "https://github.com/winfinit/aamvajs", "keywords": [ "aamva", "driver", @@ -17,17 +45,15 @@ "AAMVA", "AMVA" ], - "author": "Roman Jurkov ", - "license": "GNU General Public License", - "bugs": { - "url": "https://github.com/winfinit/aamvajs/issues" + "license": "GPL-3.0-or-later", + "main": "index.js", + "name": "aamva", + "repository": { + "type": "git", + "url": "git+https://github.com/winfinit/aamvajs.git" }, - "dependencies": { - + "scripts": { + "test": "make test" }, - "homepage": "https://github.com/winfinit/aamvajs", - "devDependencies": { - "mocha": "^1.21.4", - "chai": "^1.9.1" - } + "version": "1.2.0" } From 8abefb6dd7a561ea8fb0707a8b6779a28570e409 Mon Sep 17 00:00:00 2001 From: RPacetti Date: Thu, 22 Feb 2018 13:29:25 -0700 Subject: [PATCH 2/3] Fix package.json --- package.json | 66 ++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index c32624b..0bb9394 100644 --- a/package.json +++ b/package.json @@ -1,43 +1,15 @@ { - "_from": "aamva", - "_id": "aamva@1.2.0", - "_inBundle": false, - "_integrity": "sha1-a8MKXv+CFIOBY9B6oNYODV05cPc=", - "_location": "/aamva", - "_phantomChildren": {}, - "_requested": { - "type": "tag", - "registry": true, - "raw": "aamva", - "name": "aamva", - "escapedName": "aamva", - "rawSpec": "", - "saveSpec": null, - "fetchSpec": "latest" - }, - "_requiredBy": [ - "#USER" - ], - "_resolved": "https://registry.npmjs.org/aamva/-/aamva-1.1.0.tgz", - "_shasum": "6bc30a5eff8214838163d07aa0d60e0d5d3970f7", - "_spec": "aamva", - "_where": "C:\\Users\\rpacetti", - "author": { - "name": "Roman Jurkov", - "email": "winfinit@gmail.com" - }, - "bugs": { - "url": "https://github.com/winfinit/aamvajs/issues" + "name": "aamva", + "version": "1.2.0", + "description": "Parse AAMVA magnetic stripe and barcode", + "main": "index.js", + "scripts": { + "test": "make test" }, - "bundleDependencies": false, - "dependencies": {}, - "deprecated": false, - "description": "Parse AAMVA magnetic stripe", - "devDependencies": { - "chai": "^1.9.1", - "mocha": "^1.21.4" + "repository": { + "type": "git", + "url": "https://github.com/winfinit/aamvajs.git" }, - "homepage": "https://github.com/winfinit/aamvajs", "keywords": [ "aamva", "driver", @@ -45,15 +17,17 @@ "AAMVA", "AMVA" ], - "license": "GPL-3.0-or-later", - "main": "index.js", - "name": "aamva", - "repository": { - "type": "git", - "url": "git+https://github.com/winfinit/aamvajs.git" + "author": "Roman Jurkov ", + "license": "GNU General Public License", + "bugs": { + "url": "https://github.com/winfinit/aamvajs/issues" }, - "scripts": { - "test": "make test" + "dependencies": { + }, - "version": "1.2.0" + "homepage": "https://github.com/winfinit/aamvajs", + "devDependencies": { + "mocha": "^1.21.4", + "chai": "^1.9.1" + } } From 5f7115e557a9c12b0f42b20624b607b96750393f Mon Sep 17 00:00:00 2001 From: RPacetti Date: Thu, 22 Feb 2018 14:27:21 -0700 Subject: [PATCH 3/3] Handle parsing of dates with format YYMM --- example.html | 11 ++++++++++- index.js | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/example.html b/example.html index 4a2a308..6b1f337 100644 --- a/example.html +++ b/example.html @@ -24,6 +24,11 @@ $('#city').html(output.city); $('#state').html(output.state); $('#zip').html(output.postal_code); + $('#exp').html(output.expiration_date); + var splitExp = splitDate(output.expiration_date); + $('#expm').html(splitExp.month); + $('#expd').html(splitExp.day); + $('#expy').html(splitExp.year); }); }); @@ -47,7 +52,11 @@
  • Address:
  • City:
  • State:
  • -
  • zip:
  • +
  • Zip:
  • +
  • Exp Date:
  • +
  • Exp Month:
  • +
  • Exp Day:
  • +
  • Exp Year:

  • diff --git a/index.js b/index.js index 644f629..956d944 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,14 @@ // splits dates into month, day, and year var splitDate = function(date) { + if (date.length == 4) { + // format is YYMM + return { + year: '20' + date[0] + date[1], + month: date[2] + date[3], + day: undefined + } + } var start = parseInt(date[0] + date[1]); if (start < 13) { return {