summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/is-resolvable/index.js
blob: 807817b9373fd4dc8ff2ee550335fc922dbe54cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';

var tryit = require('tryit');

module.exports = function isResolvable(moduleId) {
  if (typeof moduleId !== 'string') {
    throw new TypeError(
      moduleId +
      ' is not a string. A module identifier to be checked if resolvable is required.'
    );
  }

  var result;
  tryit(function() {
    require.resolve(moduleId);
  }, function(err) {
    if (err) {
      result = false;
      return;
    }

    result = true;
  });

  return result;
};