Skip to main content

Utils

The following utilities are provided to help you work with document and asset data inside your Satellite. They simplify tasks such as decoding and encoding data, serializing custom types, and interacting with Juno’s core features in a consistent way.

📦 Library

All utilities on this page are provided by the @junobuild/functions library.

To use them, add this to your project:

npm i @junobuild/functions

decodeDocData​

Decodes the raw data of a document into a typed object. Use this inside hooks or assertions to retrieve the original contents of a document.

function decodeDocData<T>(data: Uint8Array): T;

📦 Import from @junobuild/functions/utils

Parameters:​

  • data: A Uint8Array containing the raw binary document data.

Returns:​

  • A deserialized object of type T.

encodeDocData​

Encodes an object into a raw binary format for storing document data. Use this when creating or modifying a document inside a hook or assertion.

function encodeDocData<T>(data: T): Uint8Array;

📦 Import from @junobuild/functions/utils

Parameters:​

  • data: A JavaScript object to serialize.

Returns:​

  • A Uint8Array containing the encoded binary data.