@@ -37,12 +37,14 @@ <h1 id='header'>Read A Driver's License <a href="javascript:void(0)" id='readAga
3737 < div id ="resultAlert_content " class ="resultAlert_content "> </ div >
3838 </ div >
3939 < script src ="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@9.0.2/dist/dbr.js "> </ script >
40+ < script src ="https://cdn.jsdelivr.net/npm/dynamsoft-code-parser@1.1.0/dist/dcp.js "> </ script >
4041 < script >
4142 /** LICENSE ALERT - README
4243 * To use the library, you need to first specify a license key using the API "license" as shown below.
4344 */
4445
4546 Dynamsoft . DBR . BarcodeReader . license = 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9' ;
47+ Dynamsoft . DCP . CodeParser . license = 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9' ;
4648
4749 /**
4850 * You can visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=github&product=dbr&package=js to get your own trial license good for 30 days.
@@ -58,6 +60,8 @@ <h1 id='header'>Read A Driver's License <a href="javascript:void(0)" id='readAga
5860 let timer = null ;
5961 // scanner for decoding video
6062 let pScanner = null ;
63+ // parser for parsing code
64+ let pParser = null ;
6165 ( async ( ) => {
6266 //Load the library on page load to speed things up.
6367 try {
@@ -165,44 +169,28 @@ <h1 id='header'>Read A Driver's License <a href="javascript:void(0)" id='readAga
165169 return node ;
166170 }
167171
168- function getDLInfo ( txt ) {
169- let lines = txt . split ( "\n" ) ;
170- let abbrs = Object . keys ( DriverLicenseFields ) ;
171- let dlInfo = { } ;
172- lines . forEach ( ( line , i ) => {
173- let abbr ;
174- let content ;
175- if ( i === 1 ) {
176- abbr = "DAQ" ;
177- content = line . substring ( line . indexOf ( abbr ) + 3 ) ;
178- } else {
179- abbr = line . substring ( 0 , 3 ) ;
180- content = line . substring ( 3 ) . trim ( ) ;
181- }
182- if ( abbrs . includes ( abbr ) ) {
183- dlInfo [ abbr ] = {
184- description : DriverLicenseFields [ abbr ] ,
185- value : content ,
186- } ;
187- }
188- } ) ;
189- return dlInfo ;
190- }
191172 async function extractResultAlert ( text ) {
192- let parsedDLInfo = getDLInfo ( text ) ;
193- let resultShowNode = document . createElement ( "p" ) ;
194- for ( let o in parsedDLInfo ) {
195- resultShowNode . appendChild ( createNode ( "span" , parsedDLInfo [ o ] . description ) ) ;
196- resultShowNode . appendChild ( createNode ( "br" ) ) ;
197- resultShowNode . appendChild ( createNode ( "strong" , parsedDLInfo [ o ] . value ) ) ;
198- resultShowNode . appendChild ( createNode ( "br" ) ) ;
199- resultShowNode . appendChild ( createNode ( "span" , "------------------------------" ) ) ;
200- resultShowNode . appendChild ( createNode ( "br" ) ) ;
173+ try {
174+ let parser = await ( pParser = pParser || Dynamsoft . DCP . CodeParser . createInstance ( ) ) ;
175+ await parser . setCodeFormat ( Dynamsoft . DCP . EnumCodeFormat . CF_AUTO ) ;
176+
177+ let parsedDLInfo = await parser . parseData ( text ) ;
178+ let resultShowNode = document . createElement ( "p" ) ;
179+ for ( let o in parsedDLInfo ) {
180+ resultShowNode . appendChild ( createNode ( "span" , parsedDLInfo [ o ] . description ) ) ;
181+ resultShowNode . appendChild ( createNode ( "br" ) ) ;
182+ resultShowNode . appendChild ( createNode ( "strong" , parsedDLInfo [ o ] . value ) ) ;
183+ resultShowNode . appendChild ( createNode ( "br" ) ) ;
184+ resultShowNode . appendChild ( createNode ( "span" , "------------------------------" ) ) ;
185+ resultShowNode . appendChild ( createNode ( "br" ) ) ;
186+ }
187+ document . getElementById ( 'resultAlert_content' ) . innerHTML = "" ;
188+ document . getElementById ( 'resultAlert_content' ) . appendChild ( resultShowNode ) ;
189+ document . getElementById ( 'resultAlert' ) . hidden = false ;
190+ document . addEventListener ( "mousedown" , clickToHide ) ;
191+ } catch ( ex ) {
192+ alert ( ex . message ) ;
201193 }
202- document . getElementById ( 'resultAlert_content' ) . innerHTML = "" ;
203- document . getElementById ( 'resultAlert_content' ) . appendChild ( resultShowNode ) ;
204- document . getElementById ( 'resultAlert' ) . hidden = false ;
205- document . addEventListener ( "mousedown" , clickToHide ) ;
206194 }
207195
208196 function clickToHide ( e ) {
@@ -221,93 +209,7 @@ <h1 id='header'>Read A Driver's License <a href="javascript:void(0)" id='readAga
221209 } , 3000 ) ;
222210 }
223211 }
224- const DriverLicenseFields = {
225- 'DCA' : 'Jurisdiction-specific vehicle class' ,
226- 'DCB' : 'Jurisdiction-specific restriction codes' ,
227- 'DCD' : 'Jurisdiction-specific endorsement codes' ,
228- 'DBA' : 'Document Expiration Date' ,
229- 'DCS' : 'Customer Last Name' ,
230- 'DAC' : 'Customer First Name' ,
231- 'DBD' : 'Document Issue Date' ,
232- 'DBB' : 'Date of Birth' ,
233- 'DBC' : 'Physical Description - Sex' ,
234- 'DAY' : 'Physical Description - Eye Color' ,
235- 'DAU' : 'Physical Description - Height' ,
236- 'DAG' : 'Address - Street 1' ,
237- 'DAI' : 'Address - City' ,
238- 'DAJ' : 'Address - Jurisdiction Code' ,
239- 'DAK' : 'Address - Postal Code' ,
240- 'DAQ' : 'Customer ID Number' ,
241- 'DCF' : 'Document Discriminator' ,
242- 'DCG' : 'Country Identification' ,
243- 'DDE' : 'Family Name Truncation' ,
244- 'DDF' : 'First Names Truncation' ,
245- 'DDG' : 'Middle Names Truncation' ,
246- 'DAH' : 'Address - Street 2' ,
247- 'DAZ' : 'Hair Color' ,
248- 'DCI' : 'Place of birth' ,
249- 'DCJ' : 'Audit information' ,
250- 'DCK' : 'Inventory Control Number' ,
251- 'DBN' : 'Alias / AKA Family Name' ,
252- 'DBG' : 'Alias / AKA Given Name' ,
253- 'DBS' : 'Alias / AKA Suffix Name' ,
254- 'DCU' : 'Name Suffix' ,
255- 'DCE' : 'Physical Description Weight Range' ,
256- 'DCL' : 'Race / Ethnicity' ,
257- 'DCM' : 'Standard vehicle classification' ,
258- 'DCN' : 'Standard endorsement code' ,
259- 'DCO' : 'Standard restriction code' ,
260- 'DCP' : 'Jurisdiction-specific vehicle classification description' ,
261- 'DCQ' : 'Jurisdiction-specific endorsement code description' ,
262- 'DCR' : 'Jurisdiction-specific restriction code description' ,
263- 'DDA' : 'Compliance Type' ,
264- 'DDB' : 'Card Revision Date' ,
265- 'DDC' : 'HazMat Endorsement Expiration Date' ,
266- 'DDD' : 'Limited Duration Document Indicator' ,
267- 'DAW' : 'Weight(pounds)' ,
268- 'DAX' : 'Weight(kilograms)' ,
269- 'DDH' : 'Under 18 Until' ,
270- 'DDI' : 'Under 19 Until' ,
271- 'DDJ' : 'Under 21 Until' ,
272- 'DDK' : 'Organ Donor Indicator' ,
273- 'DDL' : 'Veteran Indicator' ,
274- // old standard
275- 'DAA' : 'Customer Full Name' ,
276- 'DAB' : 'Customer Last Name' ,
277- 'DAE' : 'Name Suffix' ,
278- 'DAF' : 'Name Prefix' ,
279- 'DAL' : 'Residence Street Address1' ,
280- 'DAM' : 'Residence Street Address2' ,
281- 'DAN' : 'Residence City' ,
282- 'DAO' : 'Residence Jurisdiction Code' ,
283- 'DAP' : 'Residence Postal Code' ,
284- 'DAR' : 'License Classification Code' ,
285- 'DAS' : 'License Restriction Code' ,
286- 'DAT' : 'License Endorsements Code' ,
287- 'DAV' : 'Height in CM' ,
288- 'DBE' : 'Issue Timestamp' ,
289- 'DBF' : 'Number of Duplicates' ,
290- 'DBH' : 'Organ Donor' ,
291- 'DBI' : 'Non-Resident Indicator' ,
292- 'DBJ' : 'Unique Customer Identifier' ,
293- 'DBK' : 'Social Security Number' ,
294- 'DBL' : 'Date Of Birth' ,
295- 'DBM' : 'Social Security Number' ,
296- 'DCH' : 'Federal Commercial Vehicle Codes' ,
297- 'DBO' : 'Customer Last Name' ,
298- 'DBP' : 'Customer First Name' ,
299- 'DBQ' : 'Customer Middle Name(s)' ,
300- 'DBR' : 'Name Suffix' ,
301- 'PAA' : 'Permit Classification Code' ,
302- 'PAB' : 'Permit Expiration Date' ,
303- 'PAC' : 'Permit Identifier' ,
304- 'PAD' : 'Permit IssueDate' ,
305- 'PAE' : 'Permit Restriction Code' ,
306- 'PAF' : 'Permit Endorsement Code' ,
307- 'ZVA' : 'Court Restriction Code' ,
308- 'DCT' : 'Customer First Name' ,
309- 'DAD' : 'Customer Middle Name(s)'
310- } ;
212+
311213 </ script >
312214</ body >
313215< style >
0 commit comments