npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ripp/seo-head

v1.0.0

Published

TypeScript library for managing SEO meta tags in the document head with automatic platform-specific tag mapping.

Readme

@ripp/seo-head

A Zero-Dependency, SSR-friendly, TypeScript library for managing SEO meta tags. Automatically maps standard SEO keys to platform-specific tags (Open Graph, Twitter/X, etc.).

Also see the Playground UI and UI Quick Start

Installation

npm install @ripp/seo-head

Quick Start

import { SeoHead } from "@ripp/seo-head";

// Initialize once with site defaults
const seoHead = new SeoHead({
  defaults: {
    siteName: "My Site",
    robots: "index, follow",
  },
});

// Update tags as you navigate
seoHead.update({
  title: "Home Page",
  description: "Welcome to my awesome page",
  canonical: "https://example.com/",
  image: "https://example.com/og-image.jpg",
});

That's it! The library automatically creates and updates <meta>, <link>, and <title> tags for:

  • Standard SEO (title, description, canonical)
  • Open Graph (Facebook, LinkedIn)
  • Twitter/X Cards
  • And more...

API Methods

// Get current SEO context
const current = seoHead.getCurrent();

// Reset to defaults (useful for navigation)
seoHead.reset();

// Clear all SEO tags
seoHead.clear();

// Clear specific key
seoHead.clearKey('title');

// Inspect current state (for debugging)
const { context, tags } = seoHead.inspect();

Advanced Features

Title Templates

// String template
const seoHead = new SeoHead({
  titleTemplate: '%s | My Site',
});
seoHead.update({ title: 'Home' }); // → "Home | My Site"

// Functional template
const seoHead = new SeoHead({
  titleTemplate: (title, context) => {
    return context.type === 'article' 
      ? `${title} - Blog`
      : `${title} | Site`;
  },
});

URL Pattern Matching

Match routes dynamically using glob patterns or RegExp:

const seoHead = new SeoHead({
  // Exact match (backward compatible)
  urlMapping: {
    '/about': { type: 'website' },
  },
  // Pattern matching
  urlPatterns: [
    { pattern: '/blog/*', context: { type: 'article' } },
    { pattern: /^\/user\/\d+$/, context: { type: 'profile' } },
  ],
});

Validation & Diagnostics

const seoHead = new SeoHead({
  validate: true, // Enable all validations
  onValidationWarning: (warning) => {
    console.warn(`SEO Issue: ${warning.key}`, warning.message);
  },
});

// Or enable specific validations
const seoHead = new SeoHead({
  validate: {
    title: true,
    description: true,
    images: false,
    canonical: false,
  },
});

Validates:

  • Title length (10-60 chars recommended)
  • Description length (50-160 chars recommended)
  • Missing images on articles
  • Missing alt text on images
  • Missing canonical on articles

PWA & Performance Tags

seoHead.update({
  // PWA
  themeColor: '#00695c',
  manifestUrl: '/manifest.json',
  appleTouchIcon: '/apple-touch-icon.png',
  appleStatusBarStyle: 'black-translucent',
  
  // Performance
  preconnect: ['https://fonts.googleapis.com'],
  dnsPrefetch: ['https://fonts.gstatic.com'],
  preload: [
    { href: '/fonts/main.woff2', as: 'font', type: 'font/woff2', crossorigin: 'anonymous' },
  ],
});

Event Callbacks

const seoHead = new SeoHead({
  onUpdate: (context) => {
    console.log('SEO updated:', context);
  },
  onTagsChanged: ({ added, removed, updated }) => {
    console.log('Tags changed:', { added, removed, updated });
  },
});

JSON-LD Structured Data

seoHead.update({
  title: "Article Title",
  jsonLdScripts: [
    {
      "@context": "https://schema.org",
      "@type": "Article",
      headline: "Article Title",
      datePublished: "2024-01-01",
    },
  ],
});

Custom Tag Mappings

const seoHead = new SeoHead({
  tagMapping: {
    customKey: [
      {
        tag: "meta",
        selector: 'meta[name="custom-key"]',
        attrs: { name: "custom-key", content: (value) => value },
      },
    ],
  },
});

Fallback to Existing DOM Elements

const seoHead = new SeoHead({
  fallbackTitle: true,        // Use existing <title> if no title provided
  fallbackDescription: true,  // Use existing meta description
  fallbackIcon: true,         // Use existing favicon
});

Features

  • Automatic tag mapping: One object updates multiple platform-specific tags (OG, X/Twitter, etc.)
  • Title templates: Format titles consistently with templates or functions
  • URL pattern matching: Dynamic route-based SEO with glob patterns or RegExp
  • Validation: Built-in SEO best practice validation with warnings
  • PWA support: Theme colors, manifest, and Apple-specific tags
  • Performance optimization: Preconnect, DNS prefetch, and preload tags
  • Event callbacks: React to SEO updates with custom handlers
  • JSON-LD support: Built-in structured data handling
  • API methods: Get, reset, clear, and inspect SEO state
  • Lazy loading: Elements created only when needed
  • Memory efficient: Cleans up unused references automatically
  • Type-safe: Full TypeScript support with comprehensive types

Use Cases

Single Page Applications (SPAs)

Update SEO tags dynamically as users navigate between routes without page reloads.

// React Router example
router.subscribe((route) => {
  seoHead.update({
    title: route.meta.title,
    description: route.meta.description,
    canonical: `https://example.com${route.path}`,
  });
});

Server-Side Rendering (SSR)

Set SEO tags during server-side rendering for optimal initial page load and crawler support.

// Next.js, Remix, or similar
export async function loader() {
  const data = await fetchPageData();
  seoHead.update({
    title: data.title,
    description: data.description,
    image: data.ogImage,
  });
  return { data };
}

Content Management Systems

Manage SEO for dynamic content like blog posts, products, or articles with consistent tag generation.

// Blog post example
function renderPost(post) {
  seoHead.update({
    title: post.title,
    description: post.excerpt,
    type: "article",
    contentAuthor: post.author.name,
    contentPublishedAt: post.publishedAt,
    jsonLdScripts: [{
      "@context": "https://schema.org",
      "@type": "BlogPosting",
      headline: post.title,
      datePublished: post.publishedAt,
    }],
  });
}