Consider exploring the capabilities of Kotlin for your project.
Kotlin is a versatile language that can transpile to JavaScript and also compile to Java bytecode.
While using Kotlin, you have access to its utilities, though not directly to Java or JS/TS types when integrating with both Java and ts/js code; however, you can utilize the kotlin stdlib.
If your task mainly involves calculations, specific java/js classes/functions may not be necessary.
It's worth considering conducting the calculation on the backend, as suggested by VLAZ in the comments.
Integration with IntelliJ IDE
To set up such a project in IntelliJ, choose Kotlin
in the New Project
Window and select the Library
project template.
https://i.sstatic.net/HjpKf.png
Ensure you include targets like common
, jvm
, and js
. For non-native development, omit the native
target.
https://i.sstatic.net/obopj.png
You can then use the kotlin library in various projects, including JavaScript frameworks (e.g., Angular) and Java applications, as a dependency.
In a Java project, reference
KOTLIN_PROJECT/build/classes/kotlin/jvm/main
(compiled Java classes location).
In a JavaScript (e.g., Angular) project, refer to
KOTLIN_PROJECT/build/js/packages/kotlinToJavaAndJS
.
For demonstration purposes, I've created this GitHub repository.