a module style for js.
do you know monad? :)
<script src="https://saber2pr.top/mod/mod.min.js"></script>
function mod<T>(creator: () => Promise<T>): Promise<T>
function mod<T>(
creator: (join: (dep: string) => Promise<any>) => Promise<T>
): Promise<T>
- define a module:
// ./add.js
mod(() => {
const add = (a, b) => a + b
return add
})
- import a module
// ./main.js
mod(async require => {
// import module
const add = await require("./add.js")
console.log(add(1, 2))
})
It looks like the do-block in haskell?
MIT
Author: saber2pr