"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.checkIsPatternsMatchFilename = checkIsPatternsMatchFilename;
exports.modifyAsExclude = modifyAsExclude;

var _ignore = _interopRequireDefault(require("ignore"));

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

/** 
  @param {Array<String>} patterns: 
  // include src folder, include deskapp folder, exclude node modules
  [
    "src",
    "deskapp",
    "!node_modules"
  ]
  @param {String} filename : 
  filename : 'D:/MyWork/..../desk_client_app/supportapp/src/components/Avatar/Avatar.module.css,

  @return {Boolean} : true or false
*/
function checkIsPatternsMatchFilename(patterns, filename) {
  if (typeof patterns === 'undefined') {
    return true;
  }

  if (typeof patterns === 'function') {
    return patterns(filename);
  }

  if (typeof patterns === 'string') {
    // eslint-disable-next-line no-param-reassign
    patterns = [patterns];
  }

  if (Array.isArray(patterns)) {
    return patterns.length ? (0, _ignore.default)({
      allowRelativePaths: true
    }).add(patterns).ignores(filename) : true;
  } // eslint-disable-next-line no-throw-literal


  throw `UnKnown pattern Error ${JSON.stringify(patterns)}`;
}

function modifyAsExclude(patterns) {
  return patterns.map(pattern => pattern[0] === '!' ? pattern.slice(1) : `!${pattern}`);
}