Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
import { curry, flatten, get } from 'chain-able-boost'
import {
  isNil,
  isSafe,
  isArray,
  toBoolean,
  isObj,
  toNumber,
  isNumber,
} from 'exotic'

const getOneOf = obj => (...paths) => {
  // @todo exotic has a check for this
  if (isArray(paths[0])) {
    paths = flatten(paths)
  }

  for (let index = 0; index < paths.length; index++) {
    // current path
    const path = paths[index]
    // fallback
    const value = get(obj, path)
    if (isSafe(value)) {
      return value
    }
  }

  return ''
  // isSafe(fallback)
  //   ? fallback
  //   : ''
}

const getOneOfFor = (...paths) => obj => getOneOf(obj)(...paths)

export { getOneOfFor, getOneOf }