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

@tpmjs/tools-links-catalog

v0.2.0

Published

Extract and categorize all links from web pages

Readme

@tpmjs/tools-links-catalog

Extract and categorize all links from web pages into internal, external, and anchor links.

Installation

npm install @tpmjs/tools-links-catalog

Usage

import { linksCatalogTool } from '@tpmjs/tools-links-catalog';

const result = await linksCatalogTool.execute({
  url: 'https://example.com'
});

console.log(result);
// {
//   url: 'https://example.com',
//   internal: [
//     { href: 'https://example.com/about', text: 'About Us' },
//     { href: 'https://example.com/contact', text: 'Contact' }
//   ],
//   external: [
//     { href: 'https://twitter.com/example', text: 'Follow us' }
//   ],
//   anchors: [
//     { href: '#top', text: 'Back to top' }
//   ],
//   total: 4,
//   metadata: {
//     fetchedAt: '2025-12-31T12:00:00.000Z',
//     domain: 'example.com'
//   }
// }

Features

  • Automatic Categorization: Links are grouped into three categories

    • Internal: Links to the same domain
    • External: Links to different domains
    • Anchors: Same-page navigation links (fragments)
  • Link Deduplication: Automatically removes duplicate links

  • URL Normalization: Resolves relative URLs to absolute URLs

  • Metadata Extraction: Captures link text and title attributes

  • Smart Filtering: Excludes mailto:, tel:, javascript:, and data: URIs

  • Comprehensive Error Handling: Detailed error messages for network issues

API

Input

{
  url: string; // The URL to fetch and extract links from
}

Output

{
  url: string;               // The fetched URL
  internal: Link[];          // Links to the same domain
  external: Link[];          // Links to different domains
  anchors: Link[];           // Same-page anchor links
  total: number;             // Total number of links
  metadata: {
    fetchedAt: string;       // ISO timestamp of fetch
    domain: string;          // Domain name extracted from URL
  };
}

interface Link {
  href: string;              // Absolute URL
  text: string;              // Visible link text
  title?: string;            // Optional title attribute
}

Use Cases

  1. SEO Auditing: Analyze internal linking structure
  2. Broken Link Detection: Identify all links for validation
  3. Competitor Analysis: See what external sites are linked to
  4. Site Mapping: Build a map of internal pages
  5. Link Equity Analysis: Understand how link juice flows
  6. External Dependencies: Track third-party integrations
  7. Navigation Analysis: Study site navigation patterns

Example: SEO Link Analysis

const result = await linksCatalogTool.execute({
  url: 'https://blog.example.com/post'
});

console.log(`Total links: ${result.total}`);
console.log(`Internal links: ${result.internal.length}`);
console.log(`External links: ${result.external.length}`);
console.log(`Anchor links: ${result.anchors.length}`);

// Find all links to a specific domain
const twitterLinks = result.external.filter(link =>
  link.href.includes('twitter.com')
);

// Find all internal blog posts
const blogPosts = result.internal.filter(link =>
  link.href.includes('/blog/')
);

// Check for navigation links
const hasNavigation = result.internal.some(link =>
  link.text.toLowerCase().includes('home') ||
  link.text.toLowerCase().includes('about')
);

Link Categories Explained

Internal Links

Links that point to the same domain as the source page:

  • https://example.com/about (from https://example.com)
  • /products (relative URL on same domain)
  • ./services (relative URL on same domain)

External Links

Links that point to a different domain:

  • https://twitter.com/example (social media)
  • https://partner-site.com (partner website)
  • https://cdn.example.com (different subdomain)

Anchor Links

Links that navigate within the same page:

  • #top (jump to top)
  • #section-2 (jump to section)
  • #footer (jump to footer)

Note: Subdomains are treated as different domains (e.g., blog.example.com vs example.com).

Filtering Behavior

The tool automatically filters out non-navigational links:

  • mailto: links (email addresses)
  • tel: links (phone numbers)
  • javascript: links (JavaScript actions)
  • data: links (data URIs)
  • Empty or invalid hrefs

Error Handling

The tool provides detailed error messages for common issues:

  • Invalid URL: URL format is incorrect
  • Network Errors: DNS failures, connection refused, timeouts
  • SSL Errors: Invalid certificates
  • Content Type Errors: Non-HTML responses
  • Empty Responses: Server returns empty content

All errors include specific details to help diagnose the problem.

Performance Considerations

  • Large pages with thousands of links may take a few seconds to process
  • Links are deduplicated to reduce output size
  • Link text is truncated to 200 characters to prevent excessive data
  • The tool uses a 30-second timeout for fetching pages

Requirements

  • Node.js 18+ (uses native fetch API)
  • Works with both ESM and CommonJS projects

Related Tools

  • @tpmjs/tools-page-brief - Extract main content and create summaries
  • @tpmjs/tools-extract-json-ld - Extract JSON-LD structured data
  • @tpmjs/tools-table-extract - Extract HTML tables as structured data

License

MIT