lib/normalize.js
function normalize(msg, list) {
  var lower = map(function(s) {
    return s.toLowerCase();
  }, list);
  var opts = msg.options || {};
  var integrations = opts.integrations || {};
  var providers = opts.providers || {};
  var context = opts.context || {};
  var ret = {};
  debug('<-', msg);

  // integrations.
  each(function(value, key) {
    if (!integration(key)) return;
    if (!has.call(integrations, key)) integrations[key] = value;
    delete opts[key];
  }, opts);

  // providers.
  delete opts.providers;
  each(function(value, key) {
    if (!integration(key)) return;
    if (type(integrations[key]) === 'object') return;
    if (has.call(integrations, key) && typeof providers[key] === 'boolean')
      return;
    integrations[key] = value;
  }, providers);

  // move all toplevel options to msg
  // and the rest to context.
  each(function(value, key) {
    if (includes(key, toplevel)) {
      ret[key] = opts[key];
    } else {
      context[key] = opts[key];
    }
  }, opts);

  // generate and attach a messageId to msg
  msg.messageId = 'ajs-' + md5(json.stringify(msg) + uuid());

  // cleanup
  delete msg.options;
  ret.integrations = integrations;
  ret.context = context;
  ret = defaults(ret, msg);
  debug('->', ret);
  return ret;

  function integration(name) {
    return !!(
      includes(name, list) ||
      name.toLowerCase() === 'all' ||
      includes(name.toLowerCase(), lower)
    );
  }
}
function normalize(msg, list) {
  var lower = map(function(s) {
    return s.toLowerCase();
  }, list);
  var opts = msg.options || {};
  var integrations = opts.integrations || {};
  var providers = opts.providers || {};
  var context = opts.context || {};
  var ret = {};
  debug('<-', msg);

  // integrations.
  each(function(value, key) {
    if (!integration(key)) return;
    if (!has.call(integrations, key)) integrations[key] = value;
    delete opts[key];
  }, opts);

  // providers.
  delete opts.providers;
  each(function(value, key) {
    if (!integration(key)) return;
    if (type(integrations[key]) === 'object') return;
    if (has.call(integrations, key) && typeof providers[key] === 'boolean')
      return;
    integrations[key] = value;
  }, providers);

  // move all toplevel options to msg
  // and the rest to context.
  each(function(value, key) {
    if (includes(key, toplevel)) {
      ret[key] = opts[key];
    } else {
      context[key] = opts[key];
    }
  }, opts);

  // generate and attach a messageId to msg
  msg.messageId = 'ajs-' + md5(json.stringify(msg) + uuid());

  // cleanup
  delete msg.options;
  ret.integrations = integrations;
  ret.context = context;
  ret = defaults(ret, msg);
  debug('->', ret);
  return ret;

  function integration(name) {
    return !!(
      includes(name, list) ||
      name.toLowerCase() === 'all' ||
      includes(name.toLowerCase(), lower)
    );
  }
}
function normalize ( msg , list ) { var lower = map ( function ( s ) { return s . toLowerCase ( ) ; } , list ) ; var opts = msg . options || { } ; var integrations = opts . integrations || { } ; var providers = opts . providers || { } ; var context = opts . context || { } ; var ret = { } ; debug ( '<-' , msg ) ; // integrations. each ( function ( value , key ) { if ( ! integration ( key ) ) return ; if ( ! has . call ( integrations , key ) ) integrations [ key ] = value ; delete opts [ key ] ; } , opts ) ; // providers. delete opts . providers ; each ( function ( value , key ) { if ( ! integration ( key ) ) return ; if ( type ( integrations [ key ] ) === 'object' ) return ; if ( has . call ( integrations , key ) && typeof providers [ key ] === 'boolean' ) return ; integrations [ key ] = value ; } , providers ) ; // move all toplevel options to msg // and the rest to context. each ( function ( value , key ) { if ( includes ( key , toplevel ) ) { ret [ key ] = opts [ key ] ; } else { context [ key ] = opts [ key ] ; } } , opts ) ; // generate and attach a messageId to msg msg . messageId = 'ajs-' + md5 ( json . stringify ( msg ) + uuid ( ) ) ; // cleanup delete msg . options ; ret . integrations = integrations ; ret . context = context ; ret = defaults ( ret , msg ) ; debug ( '->' , ret ) ; return ret ; function integration ( name ) { return ! ! ( includes ( name , list ) || name . toLowerCase ( ) === 'all' || includes ( name . toLowerCase ( ) , lower ) ) ; } }
Normalize `msg` based on integrations `list`.

@param {Object} msg
@param {Array} list
@return {Function}
Normalize msg based on integrations list .