Skip to main content

Installation

Installing encodexx

Install encodexx using your preferred package manager

Import the library into your code and create your first schema

index.ts
import { Serializer, t } from "encodexx";
const serializer = new Serializer({
name: t.str,
date: {
createAt: t.or(t.date, t.none),
updatedAt: t.optional(t.date),
},
age: t.uint8,
});

Caution

Note that the order of types in t.or() and t.enumerate() is important.

Run the encode and decode methods

const encoded = serializer.encode({
name: "my name",
date: {
createAt: new Date()
},
age: 22
})
console.log(serializer.decode(encoded))

What’s next?

Learn about the Serializer class parameters