Plugins
Custom Serializers
Extend JSON serialization for custom types — Date, BigInt, or your own classes.
Register custom type handlers that run during JSON stringify/parse. Useful when you need to preserve types that JSON.stringify drops.
Setup
import { } from "katman/plugins"
const = ()
.("Date", {
: () => instanceof ,
: () => .toISOString(),
: () => new (),
})
.("BigInt", {
: () => typeof === "bigint",
: () => .toString(),
: () => (),
})Usage
// As JSON replacer/reviver
const = .(data, serializer.replacer)
const = .(, serializer.reviver)
// Or use the convenience methods
const = serializer.stringify(data)
const = serializer.parse()Wire format
Custom types are wrapped during serialization:
{ "created": { "__$type": "Date", "__$value": "2026-01-01T00:00:00.000Z" } }The reviver unwraps them back to the original type on parse.
When to use this vs devalue
| Scenario | Use |
|---|---|
| Need Date, Map, Set, BigInt | devalue (built-in, zero config) |
| Need custom classes (Money, Decimal, etc.) | Custom serializer |
| Need control over wire format | Custom serializer |
| Client and server both use Katman | devalue |