The fast serialiser written in Rust!
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. It similar to JSON, but has some differencies
Right now we support those types of data:
Name | Supported |
---|---|
String | yes |
Number | yes |
BigInt | yes |
Infinity | yes |
Date | yes |
Boolean | yes |
NaN | yes |
Undefined | yes |
Null | yes |
Function | yes |
Object | yes |
Array | yes |
Class | No |
Symbol | No |
npm i braser
The braser supports different targets, depending on your needs. Right now it is supported for usage in nodejs, web (with webpack/rollup/esbuild/etc) or either with a script tag.
// @TODO
const br = require("braser");
console.log(br.decode(br.encode({foo: "bar"})));
import br from "braser";
console.log(br.decode(br.encode({foo: "bar"})));
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
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()}
// @ TODO
Powered by