GitHub - ChiChuRita/shorn: Compact binary serialization for Zod, Valibot, and ArkType · GitHub
/" data-turbo-transient="true" />
Skip to content
Type / to search
Sign in<br>Sign upAppearance settings
You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
{{ message }}
ChiChuRita
shorn
Public
Notifications<br>You must be signed in to change notification settings
Fork
Star
main
BranchesTags
Go to file
CodeOpen more actions menu
Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit
History<br>28 Commits<br>28 Commits
.github/workflows
.github/workflows
bench
bench
docs
docs
examples
examples
src
src
test
test
.gitignore
.gitignore
AGENTS.md
AGENTS.md
CHANGELOG.md
CHANGELOG.md
LICENSE
LICENSE
README.md
README.md
package.json
package.json
pnpm-lock.yaml
pnpm-lock.yaml
pnpm-workspace.yaml
pnpm-workspace.yaml
tsconfig.json
tsconfig.json
tsdown.config.ts
tsdown.config.ts
View all files
Repository files navigation
shorn
shorn turns a validation schema you already have into compact binary<br>serialization. Pass a Zod, Valibot, or ArkType schema to encode and get bytes<br>back — no schema language, no code generation, no second source of truth.
Field names and type tags stay out of the payload because the schema already<br>provides them. The saving comes from the schema, not a compressor, so it costs<br>no CPU: up to 6.2× faster to encode and 13.5× faster to decode than JSON bytes.
shorn is experimental alpha and runs in Node, Bun, Deno, browsers, and workers.
Installation
npm install @chichurita/shorn zod
ESM only, Node 20 or newer. require("@chichurita/shorn") works from Node 20.19 and 22.12 on;<br>before that a CommonJS caller needs await import("@chichurita/shorn").
Encode a value
import { z } from "zod";<br>import { decode, encode } from "@chichurita/shorn";
const Person = z.object({<br>name: z.string(),<br>age: z.int().nonnegative(),<br>sex: z.enum(["M", "F", "X"]),<br>});
const person = { name: "Grace", age: 45, sex: "F" } as const;
const bytes = encode(Person, person); // Uint8Array(8)<br>const back = decode(Person, bytes); // typed and validated
The same record is 35 bytes of minified JSON. Validation runs on encode and<br>again on decode, and equivalent schemas across validators produce the same bytes.
Store and queue safely
Bare payloads carry no wire identifier. Add a fingerprint to anything stored,<br>queued, or read across deployments:
import { compile, fingerprinted } from "@chichurita/shorn";
const PersonWire = fingerprinted(compile(Person), { bytes: 4 });
const bytes = PersonWire.encode(person); // 4-byte fingerprint + payload<br>PersonWire.decode(bytes); // rejects a different wire shape
A fingerprint identifies wire structure, not refinements. Keep old codecs while<br>old payloads exist.
Use another validator
Pass a Zod 4.2+ schema or an ArkType 2.1.28+ type directly. For Valibot 1.x,<br>pass toStandardJsonSchema(schema) as the trailing argument. shorn reads<br>validation through Standard Schema and<br>structure through Standard JSON Schema.
Scope
shorn covers strings, booleans, integers, numbers, literals, enums, nullable<br>values, arrays, tuples, records, unions — discriminated, or with no two branches<br>sharing a JSON type — recursive schemas, dynamic values (z.any()), and<br>objects — closed or open, with optional fields. It does not support unions whose<br>branches overlap, streaming, or automatic schema evolution. Date, bigint,<br>Map, and Set need an explicit wire representation.
Documentation
See getting started and the<br>API reference for the complete workflow. The<br>docs also cover the byte layout,<br>supported types,<br>rejected shapes,<br>fingerprinting, and<br>performance.
MIT licensed.
About<br>Compact binary serialization for Zod, Valibot, and ArkType<br>shorn.dev<br>Topics<br>arktypebinarycodecmsgpackserializationstandard-schematypescriptvalibotzod<br>Resources<br>Readme<br>MIT license<br>Activity<br>Stars<br>1 star<br>Watchers<br>0 watching<br>Forks<br>0 forks<br>Report repository
Releases
Packages
Contributors
Languages
You can’t perform that action at this time.