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    
exotic / src / types / collection / toMap.ts
Size: Mime:
import toPairs from '../array/pairs/toPairs'
import { isPairs } from '../array/pairs/isPairs'
import isObj from '../obj/check/isObj'
import isMap from './isMap'
import fromPairsToMap from './fromPairsToMap'

// Nil => empty(Map)
// Map => identity(Map) // can also clone map this way too, an entity for Map
// Pairs => Map
// Array => Map
// Obj => Array => Map

/**
 * @since 5.0.0-beta.9
 * @memberOf cast
 *
 * @param  {*} x anything => Map
 * @return {Map}
 *
 * @example
 *   isMap(toMap({eh: true}))    //=> true
 *   toMap({eh: true}).has('eh') //=> true
 */
const toMap = (x: any): Map<string, any> => {
  // if (isNil(x)) return new Map()
  if (isMap(x)) return x
  else if (isPairs(x)) return fromPairsToMap(x)
  else if (isObj(x)) return fromPairsToMap(toPairs(x))
  else return new Map()
}

export default toMap