This feature allows custom serialization/deserialization API in seroval. The feature required massive restructuring in the core, such as moving the whole parser, serializer and deserializer code from functions to class-based, which will allow deduping and a lot more. It's required so that the underlying methods can be exposed for the plugin methods.
This resolves #17
This resolves #14
Example:
import { createPlugin, type SerovalNode } from 'seroval';
Add the Plugin API
const BufferPlugin = createPlugin<Buffer, SerovalNode>({ tag: 'Buffer', test(value) { return value instanceof Buffer; }, parse: { sync(value, ctx) { return ctx.parse(value.toString('base64')); }, async async(value, ctx) { return ctx.parse(value.toString('base64')); }, stream(value, ctx) { return ctx.parse(value.toString('base64')); }, }, serialize(node, ctx) { return
Buffer.from(${ctx.serialize(node)}, "base64")
; }, deserialize(node, ctx) { return Buffer.from(ctx.deserialize(node) as string, 'base64'); }, isIterable() { return true; }, });