From f7eb1864cb287a32e9749de05ceb7008ecb81ff5 Mon Sep 17 00:00:00 2001 From: Jean Carlo Nascimento Date: Sat, 25 Mar 2017 02:46:57 -0300 Subject: [PATCH] Updating to functional ES6 I think it's more updated. --- README.md | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 0ff613a..ce1f79b 100644 --- a/README.md +++ b/README.md @@ -40,25 +40,35 @@ that's not possible we'll fallback to precompiled binaries. ### Example ```javascript -var openalpr = require ("node-openalpr"); - -function identify (id, path) { - console.log (openalpr.IdentifyLicense (path, function (error, output) { - var results = output.results; - console.log (id +" "+ output.processing_time_ms +" "+ ((results.length > 0) ? results[0].plate : "No results")); - - if (id == 349) { - console.log (openalpr.Stop ()); - } - })); -} - -openalpr.Start (); -openalpr.GetVersion (); - -for (var i = 0; i < 350; i++) { - identify (i, "lp.jpg"); -} +const openalpr = require ("node-openalpr") + +const findImage = (file) => + file.endsWith( '.jpg' ) || file.endsWith( '.png' ) + +const getFiles = (PATH) => + fs.readdirSync(PATH).filter( findImage ) + +const showResults = ( id, output ) => + console.log( id +" "+ output.processing_time_ms +" "+ + ( (output.results.length > 0) + ? output.results[0].plate + : "No results" ) + ) + +const showStop = ( id, output ) => + showResults( id, output ) || console.log (openalpr.Stop ()) + +const identify = ( path, id, arr ) => + openalpr.IdentifyLicense( path, ( error, output ) => + (id === arr.length - 1) + ? showStop( id, output ) + : showResults( id, output ) + ) + +openalpr.Start() +openalpr.GetVersion() + +getFiles('./').map( identify ) ``` ### Methods