Skip to content

Commit 7ae2cc3

Browse files
docs: add README usage for js package
1 parent 43f8a12 commit 7ae2cc3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ const example = require("./example.node");
5050
example.myHandler();
5151
```
5252

53+
### JS Helpers
54+
55+
In addition to the Node-API exposed via package `napi`, the `napi-go/js`
56+
package provides functions similar to the `syscall/js` standard library.
57+
58+
```go
59+
package main
60+
61+
import (
62+
"github.com/akshayganeshen/napi-go/entry"
63+
"github.com/akshayganeshen/napi-go/js"
64+
)
65+
66+
func init() {
67+
entry.Export("myCallback", js.AsCallback(MyCallback))
68+
}
69+
70+
func MyCallback(env js.Env, this js.Value, args []js.Value) any {
71+
return map[string]any{
72+
"message": "hello world",
73+
"args": args,
74+
}
75+
}
76+
77+
func main() {}
78+
```
79+
5380
## Examples
5481

5582
Check out the example addons in [`docs/examples`](docs/examples).

0 commit comments

Comments
 (0)