setSanitizerConfig = config => {
  if (typeof config !== 'object') {
    throw 'Invalid value given to setSanitizerConfig, expected config object'
  }

  if (config.hasOwnProperty('clobberingProtection')) {
    ['document', 'form', 'namespaceAttributes'].forEach(type => {
      if (config.clobberingProtection.hasOwnProperty(type) && typeof config.clobberingProtection[type] === 'boolean') {
        sanitizerConfig.clobberingProtection[type] = config.clobberingProtection[type]
      }
    })
  }
  if (config.hasOwnProperty('backends')) {
    if (typeof config.backends === 'object') {
      Object.keys(config.backends).forEach(implementation => sanitizerConfig.backends[implementation] = config.backends[implementation])
    } else {
      throw 'backends config expected to be an Object'
    }
  }
  if (config.hasOwnProperty('backendOrder')) {
    sanitizerConfig.backendOrder = []
    if (Array.isArray(config.backendOrder)) {
      config.backendOrder.forEach(backend => {
        if (sanitizerConfig.backends.hasOwnProperty(backend)) {
          sanitizerConfig.backendOrder.push(backend)
        } else {
          throw 'unknown sanitizer backend ' + backend
        }
      })
    } else {
      throw 'backendOrder config expected to be an Array of backend keys as strings'
    }
  }
}
Sanitizer utility for handling untrusted HTML