jsMain.kotlinext.js.Helpers.kt Maven / Gradle / Ivy
package kotlinext.js
import js.core.Object
import js.core.jso
inline fun js(builder: dynamic.() -> Unit): dynamic =
jso(builder)
fun clone(obj: T) = Object.assign(jso(), obj)
inline fun assign(obj: T, builder: T.() -> Unit) = clone(obj).apply(builder)
fun toPlainObjectStripNull(obj: Any) = js {
for (key in Object.keys(obj)) {
val value = obj.asDynamic()[key]
if (value != null) this[key] = value
}
}