package util import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.ReadableType class MapUtil { companion object { fun toHashMap(map: ReadableMap?): Map { val hashMap = HashMap() if (!isEmpty(map)) { val iterator = map?.keySetIterator() while (iterator?.hasNextKey() == true) { val key: String = iterator.nextKey() when (map.getType(key)) { ReadableType.Null -> hashMap[key] = null ReadableType.Boolean -> hashMap[key] = map.getBoolean(key).toString() ReadableType.Number -> hashMap[key] = map.getDouble(key).toString() ReadableType.String -> hashMap[key] = map.getString(key).toString() ReadableType.Map -> hashMap[key] = toHashMap(map.getMap(key)).toString() else -> throw IllegalArgumentException("Could not convert object with key: $key.") } } } return hashMap } fun isEmpty(map: ReadableMap?): Boolean { if (map == null) { return true } return !map.keySetIterator().hasNextKey() } } }