Last active
July 4, 2018 02:05
-
-
Save stephenquan/d396397f7f2b4a3deb18a4968176e493 to your computer and use it in GitHub Desktop.
aamva_decode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert AAMVA string to JSON | |
function aamva_decode(data) { | |
var m = data.match(/^@\n\u001e\r(ANSI )(\d{6})(\d{2})(\d{2})(\d{2})/); | |
if (!m) { | |
return null; | |
} | |
var obj = { | |
header: { | |
IIN: m[2], | |
AAMVAVersion: parseInt(m[3]), | |
jurisdictionVersion: parseInt(m[4]), | |
numberOfEntries: parseInt(m[5]) | |
} | |
}; | |
for (var i = 0; i < obj.header.numberOfEntries; i++) { | |
var offset = 21 + i * 10; | |
m = data.substring(offset, offset + 10).match(/(.{2})(\d{4})(\d{4})/); | |
var header = { | |
subfileType: m[1], | |
offset: parseInt(m[2]), | |
length: parseInt(m[3]) | |
}; | |
obj[header.subfileType] = data.substring(header.offset + 2, header.offset + header.length - 1).split("\n").reduce(function (p, c) { | |
p[c.substring(0,3)] = c.substring(3); | |
return p; | |
}, { } ); | |
} | |
return obj; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.aamva.org/dl-id-card-design-standard/ | |
// 2013 AAMVA DL/ID Card Design Standard | |
// D.13 Example of raw PDF417 data | |
var data = [ | |
"@\n\u001e\r", | |
"ANSI 636000080002DL00410278ZV03190008DLDAQT64235789L\n", | |
"DCSSAMPLE\n", | |
"DDENL\n", | |
"DACMICHAEL\n", | |
"DDFN\n", | |
"DADJOHN\n", | |
"DDGN\n", | |
"DCUJR\n", | |
"DCAD\n", | |
"DCBK\n", | |
"DCDPH\n", | |
"DBD06062008\n", | |
"DBB06061986\n", | |
"DBA12102013\n", | |
"DBC1\n", | |
"DAU068 in\n", | |
"DAYBRO\n", | |
"DAG2300 WEST BROAD STREET\n", | |
"DAIRICHMOND\n", | |
"DAJVA\n", | |
"DAK232690000\n", | |
"DCF2424244747474786102204\n", | |
"DCGUSA\n", | |
"DCK123456789\n", | |
"DDAM\n", | |
"DDB06062008\n", | |
"DDC06062009\n", | |
"DDD1\r", | |
"ZVZVA01\r" | |
].join(""); | |
aamva_decode(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"header": { | |
"AAMVAVersion": 8, | |
"IIN": "636000", | |
"jurisdictionVersion": 0, | |
"numberOfEntries": 2 | |
}, | |
"DL": { | |
"DAQ": "T64235789L", | |
"DCS": "SAMPLE", | |
"DDE": "NL", | |
"DAC": "MICHAEL", | |
"DDF": "N", | |
"DAD": "JOHN", | |
"DDG": "N", | |
"DCU": "JR", | |
"DCA": "D", | |
"DCB": "K", | |
"DCD": "PH", | |
"DBD": "06062008", | |
"DBB": "06061986", | |
"DBA": "12102013", | |
"DBC": "1", | |
"DAU": "068 in", | |
"DAY": "BRO", | |
"DAG": "2300 WEST BROAD STREET", | |
"DAI": "RICHMOND", | |
"DAJ": "VA", | |
"DAK": "232690000", | |
"DCF": "2424244747474786102204", | |
"DCG": "USA", | |
"DCK": "123456789", | |
"DDA": "M", | |
"DDB": "06062008", | |
"DDC": "06062009", | |
"DDD": "1" | |
}, | |
"ZV": { | |
"ZVA": "01" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment