# scon-wasm

**SCON — Schema-Compact Object Notation: WASM module**

Rust tape decoder compiled to WebAssembly for browser and Node.js. Used automatically by `scon-notation` when available.

[![npm](https://img.shields.io/npm/v/scon-wasm.svg)](https://www.npmjs.com/package/scon-wasm)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

## With scon-notation (recommended)

```bash
npm install scon-notation
```

`scon-notation` includes `scon-wasm` as optional dependency — WASM loads automatically.

## Standalone in browser (no npm, no build)

```html
<script type="module">
import init, {
  scon_encode,
  scon_to_json,
  scon_minify,
  scon_expand
} from 'https://cdn.jsdelivr.net/npm/scon-wasm@1/scon_wasm.js';

await init();

// Encode JS object to SCON string
const scon = scon_encode({ name: 'test', version: 1 });
console.log(scon);

// Decode SCON string to JS object
const obj = JSON.parse(scon_to_json(scon));
console.log(obj);

// Minify / Expand
const mini = scon_minify(scon);
const expanded = scon_expand(mini, 1);
</script>
```

Copy, paste, works. No build step, no package manager.

## Standalone in Node.js

```js
import init, { scon_encode, scon_to_json } from 'scon-wasm';
await init();

const scon = scon_encode({ users: [{ name: 'Alice' }, { name: 'Bob' }] });
const obj = JSON.parse(scon_to_json(scon));
```

## API

| Function | Description |
|----------|-------------|
| `scon_encode(obj)` | JS object to SCON string |
| `scon_encode_indent(obj, n)` | JS object to SCON string with custom indent |
| `scon_to_json(scon)` | SCON string to JSON string (parse with `JSON.parse`) |
| `scon_minify(scon)` | SCON string to minified single-line |
| `scon_expand(mini, indent)` | Minified SCON to indented format |

## Performance

The WASM module uses the Rust single-pass tape decoder — same engine that beats simd-json on 2/3 benchmark datasets.

Full methodology: [DOI 10.5281/zenodo.14733092](https://doi.org/10.5281/zenodo.14733092)

## Also available

- **Rust**: `cargo add scon` — [crates.io/crates/scon](https://crates.io/crates/scon)
- **JavaScript (pure)**: `npm install scon-notation` — [npmjs.com/package/scon-notation](https://www.npmjs.com/package/scon-notation)
- **PHP**: `composer require scon/scon` — [packagist.org/packages/scon/scon](https://packagist.org/packages/scon/scon)

## License

MIT
