Skip to content

Commit

Permalink
Updated jsonnet readme
Browse files Browse the repository at this point in the history
  • Loading branch information
redoC-A2k committed May 31, 2024
1 parent f99f458 commit 4ff7f06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 29 additions & 1 deletion JS/jsonnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ This project aim to running Jsonnet in Wasm. The code is written in Rust and com

- [x] Jsonnet Snippet evaluation
- [x] External variable support
- [ ] External function support
- [x] External function support
- [x] Jsonnet file evaluation

## Usage

```bash
npm install arakoo-jsonnet
```
### You can evaluate snippet as follows -

```javascript
import Jsonnet from "arakoo-jsonnet";
Expand Down Expand Up @@ -47,6 +48,33 @@ console.log(result);
}
}
```
### You can evaluate functions directly from jsonnet as follows -

```javascript
import Jsonnet from "arakoo-jsonnet";

let jsonnet = new Jsonnet();
function addSomeNumber(a, b, c) {
return a+b+c
}
let result = jsonnet
.javascriptCallback("addSomeNumber",addSomeNumber)
.evaluateSnippet(`{
result : arakoo.native("addSomeNumber")(3,4,5)
}`)
```
First you need to register the javascript function you wish to call from jsonnet by calling javascriptCallback method of jsonnet instance . Then you can call the registered function by using arakoo.native method.

### Output
```json
{
"result": "12"
}
```

> Note -
>1. You can only return string from the function which you are calling from jsonnet . If you need to return any other type than you can JSON.stringify it and then std.parseJson in jsonnet.
>2. You need to add ```--experimental-wasm-modules``` flag while running the js file where you imported / required this jsonnet package
## Build

Expand Down
2 changes: 1 addition & 1 deletion JS/jsonnet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arakoodev/jsonnet",
"version": "0.3.0",
"version": "0.3.1",
"exports": {
"import": {
"default": "./src/index.mjs",
Expand Down

0 comments on commit 4ff7f06

Please sign in to comment.