Package Exports
- @ranklabs/schema
Readme
@ranklabs/schema
Authority-grade Schema.org JSON-LD for e-commerce and SaaS.
This package is the core “source of truth”: strongly-typed inputs, pure mappers that generate Schema.org nodes, and JSON-LD utilities for graph composition.
Install
pnpm add @ranklabs/schemaQuick start (recommended: graphs)
import {
createGraph,
withContext,
mapWebPage,
mapOrganization,
mapWebSite,
mapProduct,
type WebPageInput,
type OrganizationInput,
type WebSiteInput,
type ProductInput,
} from '@ranklabs/schema';
export function buildJsonLd(params: {
page: WebPageInput;
org: OrganizationInput;
site: WebSiteInput;
product?: ProductInput;
}) {
const nodes = [
mapWebPage(params.page),
mapOrganization(params.org),
mapWebSite(params.site),
...(params.product ? [mapProduct(params.product)] : []),
];
return withContext(createGraph(nodes));
}What you get
- Types
ProductInput,OfferInput,ReviewInput,AggregateRatingInputWebPageInput,WebSiteInput,OrganizationInput,BreadcrumbInputCollectionInput,FAQInput,ArticleInput,SaaSInputBrandInput,ImageInput,VideoInput
- Mappers
mapProduct,mapOffer,mapReview,mapAggregateRatingmapWebPage,mapWebSite,mapOrganization,mapBreadcrumbListmapCollectionPage,mapItemListmapArticle,mapFAQPagemapBrand,mapImage,mapVideo,mapSaaS
- JSON-LD utilities
createGraph,withContext,toJsonScriptTag,escapeJsonForHtml
- IDs & canonicalization
canonicalizeUrl,canonicalId.*
- Runtime utilities (opt-in)
cleanJsonLd,validateJsonLd
React adapters
If you want React components for rendering JSON-LD, use:
@ranklabs/schema-next(Next.js)@ranklabs/schema-hydrogen(Shopify Hydrogen)