index.js 425 B

12345678910111213141516
  1. 'use strict';
  2. var inspect = require('util').inspect;
  3. module.exports = function isResolvable(moduleId, options) {
  4. if (typeof moduleId !== 'string') {
  5. throw new TypeError(inspect(moduleId) + ' is not a string. Expected a valid Node.js module identifier (<string>), for example \'eslint\', \'./index.js\', \'./lib\'.');
  6. }
  7. try {
  8. require.resolve(moduleId, options);
  9. return true;
  10. } catch (err) {
  11. return false;
  12. }
  13. };