A encoder and decoder for WATSON.
The API is similiar to JSON.
Supports Node.js > 10 or browser with similiar level of JS support.
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 })
The implementation is now faster after most lazy evaluation code is replaced with eager evaluations. Any improvements are still welcome.
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)