Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/takase1121/watson.js

Library to deal with WATSON
https://github.com/takase1121/watson.js

Last synced: 4 days ago
JSON representation

Library to deal with WATSON

Awesome Lists containing this project

README

        

# WATSON.js

A encoder and decoder for [WATSON](https://github.com/genkami/watson).

The API is similiar to [JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON).

Supports Node.js > 10 or browser with similiar level of JS support.

### Examples:
```js
const WATSON = require('watson.js')
const data = { hello: 'world' }
const s = WATSON.stringify(data)

const prettified = WATSON.stringify(data, { prettify: true })
const SFirst = WATSON.stringify(data, { mode: 'S' })

WATSON.parse(s)
WATSON.parse(SFirst, { mode: 'S' })

// unsafe parsing
// this mode tries to replace possible string operations with float instead of int
// this is because WATSON's int maps to BigInt, which is slow on most platforms
// this mode detects sadd/snew, inew and replace them with float operations
WATSON.parse(s, { unsafe: true })
```

#### Some notes
The implementation is now faster after most lazy evaluation code is replaced with eager evaluations.
Any improvements are still welcome.

#### Benchmark because why not
```
stringify x 55,492 ops/sec ±2.63% (77 runs sampled)
parse x 51,515 ops/sec ±2.52% (80 runs sampled)
parse unsafe x 54,400 ops/sec ±2.51% (74 runs sampled)
```