How to call Number.toLocaleString() in Kotlin/js?


I am currently experimenting with Kotlin/js and I wanted to add thousand separators to some numbers. The best way seems to be to use JavaScript’s Number.toLocaleString() method.
I have not found a way to call it directly so I used the “js(…)” method to do so.

It looks like this:

fun Int.toLocaleString(): String {
    val data = this
    return js("data.toLocaleString()") as String

“data” gets marked as unused, so I had to suppress it.

My questions are:

  1. is there a way to call JavaScript’s native Number.toLocaleString() method?
  2. if not is there any sane way to implement the thousand separator?
  3. is there any way to let Kotlin know that the local variable “data” is not unused?