I'm trying to use `AsYouType` from `libphonenumber...
# webassembly
e
I'm trying to use
AsYouType
from
libphonenumber-js
but I keep getting
JsException
without any information when I call
input
. Am I doing something wrong, or is there a way to find out what the actual error is?
Copy code
@JsModule("libphonenumber-js")
external class AsYouType(countryCode: String? = definedExternally) : JsAny {
  fun input(digits: String): String
}

internal actual fun formatPhoneNumber(phoneNumber: String): String {
  if(phoneNumber.isEmpty()) return ""
  val a = AsYouType("US")
  return phoneNumber.map { digit -> a.input(digit.toString()) }.last()
}
The issue was I needed a wrapping object around AsYouType
Copy code
@JsModule("libphonenumber-js")
external object LibPhoneNumber {
  class AsYouType(countryCode: String? = definedExternally) : JsAny {
    fun input(digits: String): String
  }
}

internal actual fun formatPhoneNumber(phoneNumber: String): String {
  if(phoneNumber.isEmpty()) return ""
  val a = LibPhoneNumber.AsYouType("US")
  return phoneNumber.map { digit -> a.input(digit.toString()) }.last()
}
a
Since 2.1.0 (RC2 is now available) the information about the thrown js value is available inside the JsException. Right now it's under
-Xwasm-attach-js-exception
flag
thank you color 1