0.1.0 • Published 8 months ago

braser v0.1.0

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

headline

Braser

The fast serialiser written in Rust!

Motivation

With braser you could serialise a lot of different data types without wastes. It encodes data to string and then decode it to the same data types as initial were.

Right now we support those types of data:

NameSupported
Stringyes
Numberyes
BigIntyes
Infinityyes
Dateyes
Booleanyes
NaNyes
Undefinedyes
Nullyes
Functionyes
Objectyes
Arrayyes
ClassNo
SymbolNo

Quick start

const br = require("braser");

console.log(br.decode(br.encode({foo: "bar"})));

Usage

The braser supports different targets, depending on your needs.

Usage in Browser

// @TODO

Usage in Nodejs

const br = require("braser");

console.log(br.decode(br.encode({foo: "bar"})));

Usage with Typescript/Webpack/Rollup/etc.

import br from "braser";

console.log(br.decode(br.encode({foo: "bar"})));

Use cases

In the most cases you have to transfer data between different storages. For example, you could use serialisation with such persistent storages:

  • Cache API
  • Cookies
  • DOM Storage (Local Storage)
  • File System API (browser-provided and sandboxed file system)
  • IndexedDB
  • Service workers

Comparing with JSON


Undefined transformation

JSON.parse(JSON.stringify({ test: undefined })); // {}
br.decode(br.encode({ test: undefined })); // { test: undefined }

NaN transformation

JSON.parse(JSON.stringify({ foo: NaN })); // {foo: null}
JSON.parse(JSON.stringify({ foo: NaN })); // { foo: NaN }

Lost Date instance

const res = JSON.parse(JSON.stringify({ test: new Date() })); // { test: '2022-08-16T13:04:28.698Z' }
res['test'] instanceof Date; // false

new Date() instanceof Date; // true
const res = br.decode(br.encode({ test: new Date() })); // { test: 2022-08-16T13:04:28.698Z }
res['test'] instanceof Date; // true

new Date() instanceof Date; // true

Function support

JSON.parse(JSON.stringify({ f: () => 'test' })) // {}
br.decode(br.encode({ f: () => 'test' })) // {f: function f()}

Typed errors

// @ TODO

Powered by

0.1.0

8 months ago