Repository URL to install this package:
|
Version:
2.0.1 ▾
|
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