0.6.3 • Published 2 years ago

borsh-esm v0.6.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Borsh JS ESM

Borsh ESM is an implementation of the Borsh compatible with ES modules.

That package implemented as experiment, and tested only in browser.

Examples

Serializing an object

const value = new Test({ x: 255, y: 20, z: '123', q: [1, 2, 3] });
const schema = new Map([[Test, { kind: 'struct', fields: [['x', 'u8'], ['y', 'u64'], ['z', 'string'], ['q', [3]]] }]]);
const buffer = borsh.serialize(schema, value);

Deserializing an object

const newValue = borsh.deserialize(schema, Test, buffer);

Type Mappings

BorshTypeScript
u8 integernumber
u16 integernumber
u32 integernumber
u64 integerBN
u128 integerBN
u256 integerBN
u512 integerBN
f32 floatN/A
f64 floatN/A
fixed-size byte arrayUint8Array
UTF-8 stringstring
optionnull or type
mapN/A
setN/A
structsany

Contributing

Install dependencies:

yarn install

Continuously build with:

yarn dev

Run tests:

yarn test

Run linter

yarn lint

Publish

Prepare dist version by running:

yarn build

When publishing to npm use np.

License

This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-MIT and LICENSE-APACHE for details.