typediagram-core
v0.8.0
Published
A small DSL for diagramming algebraic data types (records + tagged unions). Language-neutral. No methods.
Readme
typediagram-core
Type-safe diagrams and source code from one schema. Parse a tiny DSL (records, tagged unions, aliases) into a model, then generate SVG diagrams and round-trip types for TypeScript, Python, Rust, Go, C#, and F#.
Live demo: typediagram.dev

Install
npm install typediagram-coreQuick start
import { parse, layout, renderSvg } from "typediagram-core";
const source = `
typeDiagram
type User {
id: UUID
name: String
email: Option<Email>
}
union Option<T> {
Some { value: T }
None
}
alias Email = String
`;
const model = parse(source);
const laid = await layout(model);
const svg = renderSvg(laid);The DSL
Three constructs:
type— recordsunion— tagged sum typesalias— newtypes
Generics with <T>. Comments with #.
Explicit numeric discriminants are supported on union variants:
union ErrorCode {
ParseError = -32700
InvalidRequest = -32600
MethodNotFound = -32601
}Subpath exports
typediagram-core— high-levelparse,layout,renderSvgtypediagram-core/parser— parser onlytypediagram-core/model— model typestypediagram-core/layout— layout enginetypediagram-core/render-svg— SVG renderertypediagram-core/markdown— markdown integration
Related packages
typediagram— CLI binary- TypeDiagram VS Code extension — syntax highlighting + live preview (search "TypeDiagram" by nimblesite on the Marketplace)
Links
- Docs: typediagram.dev/docs
- Source: github.com/Nimblesite/typeDiagram
MIT © Nimblesite
