Questions tagged [kotlin-js-interop]
62 questions
2
votes
2 answers
Kotlin Unsigned Bytes with javascript Uint8ClampedArray
I have a program which is trying to set values in ImageData represented as a Uint8ClampedArray in a Kotlin program. According to the specification for the set method, I need to pass a Kotlin byte into the array, but Kotlin bytes are signed:
…

Matthew Torrence
- 71
- 4
2
votes
0 answers
kotlin-js convert string to another encoding
I parse site and get String in windows-1251 encoding. I want print it to console for example. But in console I see incomprehensible symbols. How I can convert windows-1251 String to UTF-8 or how I can print normal string using kotlin-js ?

Artem Viter
- 804
- 7
- 12
2
votes
1 answer
Assigning properties to a javascript object using dynamic property names
I would like to do something like this but I have no idea, and I can't use js() to insert any dynamic data into because js() only takes constant string parameters (or is there a way to do that?)
val doc: dynamic = Any()
doc._id = name
…

ycomp
- 8,316
- 19
- 57
- 95
2
votes
2 answers
How to create a Promise from the nested kotlin.js.Promise?
kotlin.js.Promise has function then with this declaration:
open fun then(
onFulfilled: (T) -> S,
onRejected: (Throwable) -> S = definedExternally
): Promise
I have two functions a() and b(). They both return a Promise. (They…

user3706629
- 209
- 2
- 9
1
vote
0 answers
Kotlin/JS package is empty
In the following project:
https://github.com/MarcinMoskala/AnkiMarkdown
When I push a package to NPM, it seems empty. No binary code. I do export a single…

MarcinM
- 428
- 7
- 15
1
vote
1 answer
Kotlin/JS unable to create bindings for jwt-decode library
So, I'm kind of new to Kotlin/JS and I'm trying to create Kotlin bindings for the jwt-decode library.
Here are the Kotlin bindings I've written:
/**
* A Kotlin definition for the jwt-decode library's invalid token error class
*/
external class…

Jojo01
- 1,269
- 4
- 14
- 35
1
vote
0 answers
Kotlin/JS - pretty print HTML/XML
I'm writing a unit test where I'd like to compare some HTML that's generated by a library (KVision) to some expected HTML.
To do this I wanted to format the HTML so it's laid out nicely, and the expected and actual HTML can be compared…

aSemy
- 5,485
- 2
- 25
- 51
1
vote
1 answer
Strange behaviour of lambdas that return `dynamic` in Kotlin/JS interop
I want to write a lambda function that returns dynamic that ends with an assignment operation. The following does not type-check:
var a: Int?
val f: () -> dynamic = {
a = 42
}
Note: this example is somewhat artificial for the purposes of making…

lsparki
- 113
- 5
1
vote
2 answers
How to create an "options object" (Object with many optional properties) in Kotlin compiling to JavaScript?
Background: Options-objects in JavaScript
A common concept in JavaScript is something like this:
function MyLibrary(options) {
if (options.optionA) { /* ... */ }
if (options.optionB) { /* ... */ }
if (options.flagC) { /* ... */ }
}
new…

yankee
- 38,872
- 15
- 103
- 162
1
vote
1 answer
Javascript structure representation using Kotlin JS
my question is about creating javascript structure within KotlinJS and use them calling external modules.
Let's say we have the following js code and we want to translate it into KotlinJS.
const config = {
defs : "something",
resolvers : {
Query:…

Yak O'Poe
- 760
- 4
- 14
1
vote
1 answer
How to import a JS file in kotlin/JS
I am trying to use THREE.js with kotlin/JS. It works great so far, however, I struggle on how to import the gLTFLoader. The documentation says I should do:
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
In…

Alex
- 871
- 7
- 23
1
vote
1 answer
Modelling external JS objects
PixiJS (or rather, Resource Loader), returns a JS object shaped like this in the callback of the load function:
{
"resource-you-asked-for.png": {
url: "foo.png",
error: ,
data:
},
…

Max
- 4,882
- 2
- 29
- 43
1
vote
1 answer
Launch-Coroutine and others not supported for KotlinJS 1.2?
I'm currently trying out coroutines for my kotlin-js project on node.js.
I'm using IntelliJ-Idea and kotlin plugin 1.2.40
Coroutines should be supported, are they? But the "launch"-coroutine is not found by the IDE?!
On the other hand the namespace…

Christoph Berghuber
- 81
- 1
- 2
- 5
1
vote
1 answer
How to generate a javascript function with `this.field=value` in body, in KotlinJs
When I use KotlinJS with riot, it requires a function like following to define a tag:
function (opts) {
var self = this
self.name = "sample"
self.message = "init-message"
self.onCreate = fun(opts: dynamic) {
self.message =…

Freewind
- 193,756
- 157
- 432
- 708
1
vote
1 answer
What's difference between RBuilder and RDomBuilder?
In the kotlin react demo projects i see both
fun RBuilder.someComponent(){...}
and
fun RDOMBuilder<*>.someComponent(){...}
What is the difference between these two?

deviant
- 3,539
- 4
- 32
- 47