All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jsMain.kotlinx.io.js.TextEncoders.kt Maven / Gradle / Ivy

There is a newer version: 0.1.16
Show newest version
package kotlinx.io.js

import org.khronos.webgl.*

internal external class TextEncoder() {
    val encoding: String

    fun encode(input: String): Uint8Array
}

internal fun TextEncoderCtor(): TextEncoder {
    // PhantomJS does not support TextEncoder yet so we use node module text-encoding for tests
    if (js("typeof TextEncoder") == "undefined") {
        val module = js("require('text-encoding')")
        if (module.TextEncoder === undefined) throw IllegalStateException("TextEncoder is not supported by your browser and no text-encoding module found")
        val ctor = module.TextEncoder
        val objPrototype = js("Object").create(ctor.prototype)

        @Suppress("UnsafeCastFromDynamic")
        return ctor.call(objPrototype)
    }

    return TextEncoder()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy