# hson-wasm

> Hson for javascript

Latest version **1.0.10** (published 2019-04-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install hson-wasm
pnpm add hson-wasm
yarn add hson-wasm
bun add hson-wasm
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2019-04-21 |
| First published | 2019-03-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 609.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Backprog |
| Maintainers | beambreath |
| Keywords | hson, wasm, rust, json |

## Links

- npm: https://www.npmjs.com/package/hson-wasm
- Homepage: https://github.com/backprog/hson_wasm
- npm.io page: https://npm.io/package/hson-wasm

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.10 (latest) — 2019-04-21
- 1.0.9 — 2019-04-16
- 1.0.8 — 2019-04-16
- 1.0.7 — 2019-04-16
- 1.0.6 — 2019-03-12
- 1.0.5 — 2019-03-05
- 1.0.4 — 2019-03-05
- 1.0.3 — 2019-03-04
- 1.0.2 — 2019-03-04
- 1.0.1 — 2019-03-04
- 1.0.0 — 2019-03-04

## README

# HSON-WASM

Use [hson](https://crates.io/crates/hson) from javascript.

## Usage

See example.js or example.html for full examples.  
The lib directory contains a ready to use wasm file.  
Run `cargo build --target wasm32-unknown-unknown --release` to rebuild the wasm file, 
copy the new wasm file from 'target/wasm32-unknown-unknown/release/hson_wasm.wasm' to 'lib' folder and rename it to `hson.wasm`.

### Instantiation

```js
const Hson = require('hson-wasm');

await Hson.instantiate();

// Client-side
await Hson.instantiate(path_to_wasm);

const hson = Hson.new();
```

### Parsing
```js
const data = `{
    "div": {
      "attrs": {
        "class": ["active", 123, 0.25864, "test"],
        "onClick": "doSomething"
      },
      "div": {
        "p": {
          "attrs": {
            "id": 12,
            "rate": 0.4321,
            "trusted": true,
            "text": "foo"
          },
          "span": {
            "text": "Hello"
          }
        },
        "p": {
          "span": {
            "text": "World"
          }
        }
      },
      "div": {
        "component": "test",
        "attrs": {},
        "onClick": "componentDoSomething"
      }
    }
  }`;

hson.parse(data);
/* ... */
```

### Stringify
```js
const s = hson.stringify();
console.log(s);
```

### Searching

See https://crates.io/crates/hson#Searching for all options.  
Searching will return an array of nodes identifier (int), see [Querying](#Querying) to get nodes vertexes.  

```js
const search = hson.search("div");
console.log(search); // [ 2, 10, 22 ]

// Search in a specific node
const search = hson.search_in(search[0], "div");
console.log(search); // [ 10, 22 ]
```

### Querying

Work as [Searching](#Searching) but return nodes vertexes instead of identifiers. 

```js
const query = hson.query("div");
console.log(query);

/* Will print:

[   
    { 
      childs: [ 3, 10, 22 ],
      id: 2,
      key: 'div',
      kind: 'Node',
      parent: 1,
      value: '"attrs":{"class":["active",123,0.25864,"test"],"onClick":"doSomething"},"div":{"p":{"attrs":{"id":12,"rate":0.4321,"trusted":true,"text":"foo"},"span":{"text":"Hello"}},"p":{"span":{"text":"World"}}},"div":{"component":"test","attrs":{},"onClick":"componentDoSomething"}' 
    },
    { 
      childs: [ 11, 19 ],
      id: 10,
      key: 'div',
      kind: 'Node',
      parent: 2,
      value: '"p":{"attrs":{"id":12,"rate":0.4321,"trusted":true,"text":"foo"},"span":{"text":"Hello"}},"p":{"span":{"text":"World"}}' 
    },
    { 
      childs: [ 23, 24, 25 ],
      id: 22,
      key: 'div',
      kind: 'Node',
      parent: 2,
      value: '"component":"test","attrs":{},"onClick":"componentDoSomething"' 
    } 
]
*/

// Or query a specific node
const query = hson.query_on(query[0], "div");
console.log(query);
```

### Insert

Insert data in the node at provided position.

```js
const new_data = `{
    "ul": {
      "li": {
        "text": "World"
      }
    }
  }`;

// node_id, position, data
hson.insert(search[0], 0, new_data);
  /* ... */
```

### Remove

```js
hson.remove(search[2]);
  /* ... */
```

### Replace 

```js
hson.replace(search[1], new_data);
  /* ... */
```

### Utils

#### Is_child

```js
console.log(hson.is_child(search[0], search[1]));
```

#### Cast

```js
const query = hson.query("id");
console.log(query[0].cast());
```

---
_Source: https://npm.io/package/hson-wasm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
