HEX
Server: Apache/2.4.41
System: Linux mainweb 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: nationalmedicaregrp (1119)
PHP: 8.3.7
Disabled: exec,passthru,shell_exec,system,popen,proc_open,pcntl_exec
Upload Files
File: /home/ubuntu/.nvm/versions/node/v14.15.1/lib/node_modules/npm/lib/search/package-filter.js
'use strict'

module.exports = filter
function filter (data, include, exclude, opts) {
  return typeof data === 'object' &&
         filterWords(data, include, exclude, opts)
}

function getWords (data, opts) {
  return [ data.name ]
    .concat((opts && opts.description) ? data.description : [])
    .concat((data.maintainers || []).map(function (m) {
      return '=' + m.name
    }))
    .concat(data.versions && data.versions.length && data.url && ('<' + data.url + '>'))
    .concat(data.keywords || [])
    .map(function (f) { return f && f.trim && f.trim() })
    .filter(function (f) { return f })
    .join(' ')
    .toLowerCase()
}

function filterWords (data, include, exclude, opts) {
  var words = getWords(data, opts)
  for (var i = 0, l = include.length; i < l; i++) {
    if (!match(words, include[i])) return false
  }
  for (i = 0, l = exclude.length; i < l; i++) {
    if (match(words, exclude[i])) return false
  }
  return true
}

function match (words, pattern) {
  if (pattern.charAt(0) === '/') {
    pattern = pattern.replace(/\/$/, '')
    pattern = new RegExp(pattern.substr(1, pattern.length - 1))
    return words.match(pattern)
  }
  return words.indexOf(pattern) !== -1
}