All files config.js

100% Statements 8/8
100% Branches 8/8
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 243x             3x 3386x 3386x               3x 14x 14x   14x    
const MPI_CONFIG_KEY = '__mpi'
 
/**
 * Get the Segment Wrapper config from window
 * @param {string=} key Key config to extract. If not provided, all the config will be returned
 * @return {any} Config value or all the config if not key provided
 */
export const getConfig = key => {
  const config = window?.[MPI_CONFIG_KEY]?.segmentWrapper || {}
  return key ? config[key] : config
}
 
/**
 * Set a config value to the Segment Wrapper config
 * @param {string} key Config key to update
 * @param {boolean|string|number|object} value Value to set on the config key
 */
export const setConfig = (key, value) => {
  window[MPI_CONFIG_KEY] = window[MPI_CONFIG_KEY] || {}
  window[MPI_CONFIG_KEY].segmentWrapper =
    window[MPI_CONFIG_KEY].segmentWrapper || {}
  window[MPI_CONFIG_KEY].segmentWrapper[key] = value
}