lib/utils.js
function deprecateOptions(config, fn) {
  if (process.noDeprecation === true) {
    return fn;
  }

  const msgHandler = config.msgHandler ? config.msgHandler : defaultMsgHandler;

  const optionsWarned = new Set();
  function deprecated() {
    const options = arguments[config.optionsIndex];

    // ensure options is a valid, non-empty object, otherwise short-circuit
    if (!isObject(options) || Object.keys(options).length === 0) {
      return fn.apply(this, arguments);
    }

    config.deprecatedOptions.forEach(deprecatedOption => {
      if (options.hasOwnProperty(deprecatedOption) && !optionsWarned.has(deprecatedOption)) {
        optionsWarned.add(deprecatedOption);
        const msg = msgHandler(config.name, deprecatedOption);
        emitDeprecationWarning(msg);
        if (this && this.getLogger) {
          const logger = this.getLogger();
          if (logger) {
            logger.warn(msg);
          }
        }
      }
    });

    return fn.apply(this, arguments);
  }

  // These lines copied from https://github.com/nodejs/node/blob/25e5ae41688676a5fd29b2e2e7602168eee4ceb5/lib/internal/util.js#L73-L80
  // The wrapper will keep the same prototype as fn to maintain prototype chain
  Object.setPrototypeOf(deprecated, fn);
  if (fn.prototype) {
    // Setting this (rather than using Object.setPrototype, as above) ensures
    // that calling the unwrapped constructor gives an instanceof the wrapped
    // constructor.
    deprecated.prototype = fn.prototype;
  }

  return deprecated;
}
function deprecateOptions(config, fn) {
  if (process.noDeprecation === true) {
    return fn;
  }

  const msgHandler = config.msgHandler ? config.msgHandler : defaultMsgHandler;

  const optionsWarned = new Set();
  function deprecated() {
    const options = arguments[config.optionsIndex];

    // ensure options is a valid, non-empty object, otherwise short-circuit
    if (!isObject(options) || Object.keys(options).length === 0) {
      return fn.apply(this, arguments);
    }

    config.deprecatedOptions.forEach(deprecatedOption => {
      if (options.hasOwnProperty(deprecatedOption) && !optionsWarned.has(deprecatedOption)) {
        optionsWarned.add(deprecatedOption);
        const msg = msgHandler(config.name, deprecatedOption);
        emitDeprecationWarning(msg);
        if (this && this.getLogger) {
          const logger = this.getLogger();
          if (logger) {
            logger.warn(msg);
          }
        }
      }
    });

    return fn.apply(this, arguments);
  }

  // These lines copied from https://github.com/nodejs/node/blob/25e5ae41688676a5fd29b2e2e7602168eee4ceb5/lib/internal/util.js#L73-L80
  // The wrapper will keep the same prototype as fn to maintain prototype chain
  Object.setPrototypeOf(deprecated, fn);
  if (fn.prototype) {
    // Setting this (rather than using Object.setPrototype, as above) ensures
    // that calling the unwrapped constructor gives an instanceof the wrapped
    // constructor.
    deprecated.prototype = fn.prototype;
  }

  return deprecated;
}
function deprecateOptions ( config , fn ) { if ( process . noDeprecation === true ) { return fn ; } const msgHandler = config . msgHandler ? config . msgHandler : defaultMsgHandler ; const optionsWarned = new Set ( ) ; function deprecated ( ) { const options = arguments [ config . optionsIndex ] ; // ensure options is a valid, non-empty object, otherwise short-circuit if ( ! isObject ( options ) || Object . keys ( options ) . length === 0 ) { return fn . apply ( this , arguments ) ; } config . deprecatedOptions . forEach ( deprecatedOption => { if ( options . hasOwnProperty ( deprecatedOption ) && ! optionsWarned . has ( deprecatedOption ) ) { optionsWarned . add ( deprecatedOption ) ; const msg = msgHandler ( config . name , deprecatedOption ) ; emitDeprecationWarning ( msg ) ; if ( this && this . getLogger ) { const logger = this . getLogger ( ) ; if ( logger ) { logger . warn ( msg ) ; } } } } ) ; return fn . apply ( this , arguments ) ; } // These lines copied from https://github.com/nodejs/node/blob/25e5ae41688676a5fd29b2e2e7602168eee4ceb5/lib/internal/util.js#L73-L80 // The wrapper will keep the same prototype as fn to maintain prototype chain Object . setPrototypeOf ( deprecated , fn ) ; if ( fn . prototype ) { // Setting this (rather than using Object.setPrototype, as above) ensures // that calling the unwrapped constructor gives an instanceof the wrapped // constructor. deprecated . prototype = fn . prototype ; } return deprecated ; }
Deprecates a given function's options.

@param {object} config configuration for deprecation
@param {string} config.name function name
@param {Array} config.deprecatedOptions options to deprecate
@param {number} config.optionsIndex index of options object in function arguments array
@param {function} [config.msgHandler] optional custom message handler to generate warnings
@param {function} fn the target function of deprecation
@return {function} modified function that warns once per deprecated option, and executes original function
@ignore
@api private
Deprecates a given function s options .