'use strict'

var isObj = require('isobj')

var Flatten = module.exports = function (obj, options) {
  options = options || {}
  var blacklist = options.blacklist || []
  var separator = options.separator == null ? '.' : options.separator


  var isBlacklisted = function (obj) {
    return blacklist.some(function (type) {
      return obj instanceof type
    })
  }

  var result = {}

  (function iterator (obj, prefix) {
    var n = 0
    var keys = Object.keys(obj)
    var len = keys.length
    var key, val

    for (; n < len; n++) {
      key = keys[n]
      val = obj[key]

      if (isObj(val) && !isBlacklisted(val)) {
        iterator(val, prefix + key + separator)
        continue
      }

      result[prefix + key] = val
    }
  })(obj, '')

  return result
}

'use strict'

var isObj = require('isobj')

module.exports = function flatten (obj, options) {
  options = options || {}
  var blacklist = options.blacklist || []
  var separator = options.separator == null ? '.' : options.separator


  var isBlacklisted = function (obj) {
    return blacklist.some(function (type) {
      return obj instanceof type
    })
  }

  var result = {}

  (function iterator (obj, prefix) {
    var n = 0
    var keys = Object.keys(obj)
    var len = keys.length
    var key, val

    for (; n < len; n++) {
      key = keys[n]
      val = obj[key]

      if (isObj(val) && !isBlacklisted(val)) {
        iterator(val, prefix + key + separator)
        continue
      }

      result[prefix + key] = val
    }
  })(obj, '')

  return result
}

remove unused variable