Skip to main content
Module

x/cav/mod.ts>Serializer

A server framework for Deno
Go to Latest
interface Serializer
import { type Serializer } from "https://deno.land/x/cav@0.0.21/mod.ts";

A group of functions used to recognize (check), serialize, and deserialize objects and special values that are not strings, basic numbers, booleans, or nulls into objects that are JSON compatible.

Type Parameters

optional
I = unknown
optional
O = unknown

Methods

check(value: unknown): boolean

Function for checking if the serializer applies to a given value. JSON primitives like basic numbers, strings, booleans, and nulls skip all serializers and are returned as-is. For example, check: (v) => typeof v === "string" always returns false.

serialize(value: I): O

Transforms the value into its output on the resulting json-compatible object. The value returned by this function will be reserialized; the output does not need to be JSON-compatible.

deserialize(raw: unknown, whenDone: WhenDone<O>): I

Transforms serialized values into their original shape and structure. Initially, the value is only constructed from the raw serialized JSON. Values that are more complex and need things like referential equality or non-POJO/Array objects will need to use the whenDone registration function to access the equivalent of the value returned from serialize() when the value was serialized. (See the docs for the WhenDone type for more details.)