Transpile JVM function to JS script at runtime?

Is this possible? As a learning project, I’m creating a library to load kotlin scripts, use custom builders to output an html page. I have all the html and css stuff sufficiently covered, but I’d like to add scripts to them, so the user can write kotlin code that the app can translate to js inside tags. Is there functionality for this in the standard library or in a third party library that you know of?