@left-curve/encoding
v1.0.0
Published
Encoding and serialization utilities for the [Dango](https://dango.exchange) ecosystem.
Readme
@left-curve/encoding
Encoding and serialization utilities for the Dango ecosystem.
Installation
npm install @left-curve/encodingUsage
import { encodeHex, decodeHex, encodeBase64, serialize } from "@left-curve/encoding";
const hex = encodeHex(new Uint8Array([0xde, 0xad]));
const bytes = decodeHex("0xdead");
const base64 = encodeBase64(new Uint8Array([1, 2, 3]));
const binary = serialize({ key: "value" });API
Hex
encodeHex(bytes)/decodeHex(hex)- hex string encodingisHex(value)- check if string is valid hexhexToBigInt(hex)- convert hex to bigint
Base64
encodeBase64(bytes)/decodeBase64(base64)- standard base64encodeBase64Url(bytes)/decodeBase64Url(base64)- URL-safe base64base64ToBase64Url(base64)/base64UrlToBase64(base64url)- conversion
Binary
serialize(value)/deserialize(binary)- binary serialization with snake/camel case conversion
JSON
serializeJson(value)/deserializeJson(json)- JSON with superjson supportsortedJsonStringify(value)- deterministic JSON stringificationsortedObject(obj)- recursively sort object keys
UTF-8
encodeUtf8(string)/decodeUtf8(bytes)- UTF-8 encoding
Endian
encodeEndian32(number)/decodeEndian32(bytes)- 32-bit big-endian encoding
Uint
encodeUint(value)- encode unsigned integer
License
TBD
