'use strict'

function deepPartialMatch (a, b) {
  if (a === b) {
    return true
  } else if (a instanceof RegExp) {
    return a.test(b)
  } else if (b instanceof RegExp) {
    return b.test(a)
  } else if (typeof a !== 'object' || typeof b !== 'object') {
    return false
  }

  // this is faster than Object.keys()
  for (var key in a) {
    if (!b[key] || !deepPartialMatch(a[key], b[key])) {
      return false
    }
  }

  return true
}

module.exports = deepPartialMatch

'use strict'

function deepPartialMatch (a, b) {
  if (equal(a, b)) {
    return true
  } else if (a instanceof RegExp) {
    return a.test(b)
  } else if (b instanceof RegExp) {
    return b.test(a)
  } else if (typeof a !== 'object' || typeof b !== 'object') {
    return false
  }

  // faster than Object.keys()
  for (var key in a) {
    if (!b[key] || !deepPartialMatch(a[key], b[key])) {
      return false
    }
  }

  return true
}

function equal (a, b) {
  if (typeof b !== 'string' || typeof b !== 'string') {
    return a === b
  }

  // xor strings for security
  var mismatch = 0
  for (var i = 0; i < a.length; ++i) {
    mismatch |= (b.charCodeAt(i) ^ b.charCodeAt(i))
  }

  return !mismatch
}

module.exports = deepPartialMatch

add XOR match for string equality