Darryl Miles
03/12/2024, 4:51 PM// This snippet is from Kotlin/JS not WasmJS
window.fetch(
url, RequestInit(
method = method,
body = body,
headers = json( // THIS PART: Is there a WASM equivalent to kotlin.js.json
"Content-Type" to "application/json",
"Accept" to "application/json",
"pragma" to "no-cache"
)
)
)
Is it possible to perform something like:
@JsFun("(value) => JSON.stringify(value)")
external fun jsonStringify(value: JsAny?): JsString = definedExternally
How about:
@JsFun("(value, replacer, space) => JSON.stringify(value, replacer, space)")
external fun jsonStringify(value: JsAny?, replacer: (JsString, JsAny?) -> JsAny, space: JsAny): JsString = definedExternally
Artem Kobzar
03/12/2024, 5:14 PMDarryl Miles
03/12/2024, 5:26 PMDarryl Miles
03/12/2024, 7:51 PMUnit.toJsReference()
results in JSON object having {}
not the key being removed.
The Unit.toJsReference()
is is documentation somewhere.
private val UNDEFINED: JsAny? = js("undefined")
fun main() {
val result = json(
"Content-Type".toJsString() to "application/json".toJsString(),
"Accept".toJsString() to "application/json".toJsString(),
"pragma".toJsString() to "no-cache".toJsString(),
"bf".toJsString() to true.toJsBoolean(),
"int".toJsString() to (-1).toJsNumber(),
"double".toJsString() to (42.0).toJsNumber(),
"null".toJsString() to null,
"undef1".toJsString() to Unit.toJsReference(), // results in {}
"undef2".toJsString() to UNDEFINED
)
println(JSON.stringify(result))
}
Like the original I there is error on website Unhandled JavaScript exception: wasm validation error: at offset 87: bad type
Maybe it is FF115 ESR I use on this machineDarryl Miles
03/12/2024, 8:06 PM@JsFun("(o,k) => { return delete o[k] }") // need JS keyword access
external fun DELETE(o: JsAny, k: JsString): JsBoolean = definedExternally
fun JsObject.delete(key: JsString): JsBoolean {
return DELETE(this, key)
}
fun JsObject.delete(key: String): Boolean {
return delete(key.toJsString()).toBoolean()
}
Maybe I can mitigate the lack of JsAny.undefined
as a reference to a thing, with the above.