@holo-host/data-translator

0.1.1 • Public • Published

Holo Data Translator

A tool for translating payloads across Holo services.

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

Readme

Keywords

none

Package Sidebar

Install

npm i @holo-host/data-translator

Weekly Downloads

23

Version

0.1.1

License

ISC

Unpacked Size

27.3 kB

Total Files

5

Last publish

Collaborators

  • mrruby
  • evangineer
  • brisebom
  • peeech
  • jetttech
  • robbiecarlton
  • zo-el