Package Exports
- ld-generator
Readme
ld-generator
Typed Schema.org JSON-LD builders for TypeScript projects. The library returns plain JavaScript objects that are ready to serialize with JSON.stringify(...) and embed into HTML.
Features
- Zero runtime dependencies
- Typed factory functions for common Schema.org entities
- Small modular API with one schema per file
- ESM build output with declaration files
- Works well with React, Next.js, and server-rendered HTML
Installation
npm install ld-generatorQuick Start
import {offer, product} from 'ld-generator';
const productData = product({
name: 'Sample Product',
description: 'A compact example product.',
image: 'https://example.com/image.jpg',
brand: 'Brand Name',
offers: offer({
price: 29.99,
priceCurrency: 'USD',
availability: 'InStock',
}),
});
export function ProductSchema() {
return (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{__html: JSON.stringify(productData)}}
/>
);
}Grouped convenience API is also available:
import {schema} from 'ld-generator';
const productData = schema.product({
name: 'Sample Product',
description: 'A compact example product.',
image: 'https://example.com/image.jpg',
brand: 'Brand Name',
offers: schema.offer({
price: 29.99,
priceCurrency: 'USD',
}),
});When bundle size matters, prefer direct named imports like product and offer.
Documentation
Contributing
Contributions are welcome. Start with CONTRIBUTING.md and the development guide.