'use strict';

exports.__esModule = true;
exports.default = ignore;

var _path = require('path');

var _es6Set = require('es6-set');

var _es6Set2 = _interopRequireDefault(_es6Set);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// one-shot memoized
var cachedSet = void 0,
    lastSettings = void 0;
function validExtensions(_ref) {
  var settings = _ref.settings;

  if (cachedSet && settings === lastSettings) {
    return cachedSet;
  }

  // todo: add 'mjs'?
  lastSettings = settings;
  // breaking: default to '.js'
  // cachedSet = new Set(settings['import/extensions'] || [ '.js' ])
  cachedSet = 'import/extensions' in settings ? new _es6Set2.default(settings['import/extensions']) : { has: function has() {
      return true;
    } }; // the set of all elements

  return cachedSet;
}

function ignore(path, context) {
  // ignore node_modules by default
  var ignoreStrings = context.settings['import/ignore'] ? [].concat(context.settings['import/ignore']) : ['node_modules'];

  // check extension whitelist first (cheap)
  if (!validExtensions(context).has((0, _path.extname)(path))) return true;

  if (ignoreStrings.length === 0) return false;

  for (var i = 0; i < ignoreStrings.length; i++) {
    var regex = new RegExp(ignoreStrings[i]);
    if (regex.test(path)) return true;
  }

  return false;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvcmUvaWdub3JlLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztrQkFxQndCLE07O0FBckJ4Qjs7QUFDQTs7Ozs7O0FBRUE7QUFDQSxJQUFJLGtCQUFKO0FBQUEsSUFBZSxxQkFBZjtBQUNBLFNBQVMsZUFBVCxPQUF1QztBQUFBLE1BQVosUUFBWSxRQUFaLFFBQVk7O0FBQ3JDLE1BQUksYUFBYSxhQUFhLFlBQTlCLEVBQTRDO0FBQzFDLFdBQU8sU0FBUDtBQUNEOztBQUVEO0FBQ0EsaUJBQWUsUUFBZjtBQUNBO0FBQ0E7QUFDQSxjQUFZLHVCQUF1QixRQUF2QixHQUNSLHFCQUFRLFNBQVMsbUJBQVQsQ0FBUixDQURRLEdBRVIsRUFBRS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