JSPM

ld-generator

1.2.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 1
    • Score
      100M100P100Q63752F
    • License MIT

    A lightweight TypeScript library with no dependencies for generating Schema.org microdata in JSON-LD format, enabling easy integration of structured data for products, reviews, events, and more.

    Package Exports

    • ld-generator

    Readme

    LD Generator logo

    npm version MIT License TypeScript Dependencies

    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-generator

    Quick 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.

    License

    MIT