JSPM

@yingyeothon/codec

0.4.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q21517F
  • License MIT

A stub for codec such as JsonCodec

Package Exports

  • @yingyeothon/codec
  • @yingyeothon/codec/lib/codec.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@yingyeothon/codec) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Codec Stub

A simple stub for codec such as JsonCodec.

Usage

import { JsonCodec } from "@yingyeothon/codec";

interface IMessage {
  payload: string;
}

const message: IMessage = {
  payload: "Hello, world!"
};

const codec = new JsonCodec();
const encoded = codec.encode(message);
const decoded = codec.decode<IMessage>(encoded);

And we can implement new codec from ICodec interface.

import { ICodec } from "@yingyeothon/codec";

class ByteCodec implements ICodec<Uint8Array> {
  public encode<T>(item: T): Uint8Array {
    // ...
  }

  public decode<T>(value: Uint8Array): T {
    // ...
  }
}

License

MIT