0.1.1 • Published 4 years ago

@holo-host/data-translator v0.1.1

Weekly downloads
86
License
ISC
Repository
github
Last release
4 years ago

npm.io npm.io

Holo Data Translator

A tool for translating payloads across Holo services.

npm.io npm.io npm.io

Overview

The main feature of this tool is packing or unpacking messages.

Usage

Server-side

const { Package } = require("@holo-host/data-translator");

...

// Create a normal package
ws.on("message", (msg) => {
    let pack = new Package( "Super normal payload..." );

    ws.send( pack.toString() );
});

// Create an error package
ws.on("message", (msg) => {
    let pack;

    try {
        ...something breaks
    } catch ( err ) {
        pack = Package.createFromError( "HoloError", err ) );
    }

    ws.send( pack.toString() );
});

Client-side

const hhdt = require("@holo-host/data-translator");

...

ws.on("message", (msg) => {
    const pack = hhdt.parse( msg );
    const payload = pack.value();

    // Normal package
    console.log( payload ); // "Super normal payload..."

    // Error package
    console.log( payload instanceof Error ); // true
});

API Reference

See API.md

Contributing

See CONTRIBUTING.md