How can I access str.prototype.normalize using Kot...
# javascript
p
How can I access str.prototype.normalize using Kotlin/JS?
Or a more general question: How can I access the js api from Kotlin? What do I need to import?
a
js(...)
is a literal js injection
p
Oh I see so I need to write something like
js("'test'.normalize()")
?
a
t
js
function isn’t recommended in common case
You can write custom extension:
Copy code
fun String.normalize():String =
    asDynamic().normalize()
👌 2
👍 1
a
Using js functions instead of stdlib also is not recommended.
👌 2
p
Well yes I could write it myself but that would mean I have to write the function myself 😆
I can access the Java std lib on JVM and the WIN32 API on Windows. Why can’t I access the JS std lib?
a
Because you need kotlin wrappers for them. Most of those are present in
stdlib-js
p
Yes that’s what I was thinking but the string class is apparently not one of them
a
You have kotlin string for that. I am not sure. but maybe you could find something in kotlin.text
p
Nope, Kotlin stdlib doesn’t have string normalization
That would be the easiest solution of course
a
Then the solution from @turansky is the best you can do. It is no quite different from js inlining, but looks better.
p
Thanks, I’ll give it a try
This seems to work, thanks 👍