{"size": 872, "ext": "js", "max_stars_repo_path": "src/make-filter.js", "max_stars_repo_name": "tao-zeng/rollup-plugin-jscc", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/make-filter.js", "max_issues_repo_name": "tao-zeng/rollup-plugin-jscc", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/make-filter.js", "max_forks_repo_name": "tao-zeng/rollup-plugin-jscc", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.25, "max_line_length": 75, "alphanum_fraction": 0.6422018349}
import { createFilter } from 'rollup-pluginutils'
import { extname } from 'path'

/**
 * Creates a filter for the options `include`, `exclude`, and `extensions`.
 *
 * Since `extensions` is not a rollup option, I think is widely used.
 *
 * @param {import('..').Options} opts The user options
 * @param {array|string} exts Default extensions
 * @returns {function} Filter function that returns true if a given file
 *    matches the filter.
 */
const makeFilter = function makeFilter (opts, exts) {

  const _filt = createFilter(opts.include, opts.exclude)

  exts = opts.extensions || exts
  if (!exts || exts === '*') {
    return _filt   // do not filter extensions
  }

  if (!Array.isArray(exts)) {
    exts = [exts]
  }
  exts = exts.map((e) => (e[0] !== '.' ? `.${e}` : e))

  return (id) => _filt(id) && exts.indexOf(extname(id)) > -1
}

export default makeFilter
