Use dependencies from npm
In Kotlin/JS projects, all dependencies can be managed through the Gradle plugin. This includes Kotlin/Multiplatform libraries such as
npm function that lets you specify packages you want to import from npm. Let's consider the import of an NPM package called
The corresponding part in the Gradle build file looks as follows:
is-sorted package which offers only one function, this declaration is small to write. Inside the source folder, create a new file called
is-sorted.kt, and fill it with these contents:
Please note that if you're using CommonJS as a target, the
@JsNonModule annotations need to be adjusted accordingly.
dynamic ), proper compiler support and type-checking is also available.
Running these three lines either in the browser or Node.js, the output shows that the call to
sorted was properly mapped to the function exported by the