package com.checkoutreactnativecomponents.utils import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableArray import com.facebook.react.bridge.WritableMap import kotlin.reflect.full.memberProperties public fun Any.toWritableMap(): WritableMap { val map: WritableMap = Arguments.createMap() this::class.memberProperties.forEach { prop -> val key = prop.name when (val value = prop.getter.call(this)) { null -> map.putNull(key) is String -> map.putString(key, value) is Boolean -> map.putBoolean(key, value) is Int -> map.putInt(key, value) is Double -> map.putDouble(key, value) is Float -> map.putDouble(key, value.toDouble()) is List<*> -> map.putArray(key, value.toWritableArray()) else -> map.putMap(key, value.toWritableMap()) } } return map } public fun List<*>.toWritableArray(): WritableArray { val array: WritableArray = Arguments.createArray() this.forEach { item -> when (item) { null -> array.pushNull() is String -> array.pushString(item) is Boolean -> array.pushBoolean(item) is Int -> array.pushInt(item) is Double -> array.pushDouble(item) is Float -> array.pushDouble(item.toDouble()) is List<*> -> array.pushArray(item.toWritableArray()) else -> array.pushMap(item.toWritableMap()) } } return array }