Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

index.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var fs = require('fs')
  2. var core
  3. if (process.platform === 'win32' || global.TESTING_WINDOWS) {
  4. core = require('./windows.js')
  5. } else {
  6. core = require('./mode.js')
  7. }
  8. module.exports = isexe
  9. isexe.sync = sync
  10. function isexe (path, options, cb) {
  11. if (typeof options === 'function') {
  12. cb = options
  13. options = {}
  14. }
  15. if (!cb) {
  16. if (typeof Promise !== 'function') {
  17. throw new TypeError('callback not provided')
  18. }
  19. return new Promise(function (resolve, reject) {
  20. isexe(path, options || {}, function (er, is) {
  21. if (er) {
  22. reject(er)
  23. } else {
  24. resolve(is)
  25. }
  26. })
  27. })
  28. }
  29. core(path, options || {}, function (er, is) {
  30. // ignore EACCES because that just means we aren't allowed to run it
  31. if (er) {
  32. if (er.code === 'EACCES' || options && options.ignoreErrors) {
  33. er = null
  34. is = false
  35. }
  36. }
  37. cb(er, is)
  38. })
  39. }
  40. function sync (path, options) {
  41. // my kingdom for a filtered catch
  42. try {
  43. return core.sync(path, options || {})
  44. } catch (er) {
  45. if (options && options.ignoreErrors || er.code === 'EACCES') {
  46. return false
  47. } else {
  48. throw er
  49. }
  50. }
  51. }