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

affilinker

v0.1.1

Published

CLI tool for managing affiliate and outbound links in content files

Downloads

177

Readme

Affilinker

A CLI tool for managing affiliate and outbound links in content files (MDX, Markdown, HTML).

Features

  • Scan - Find all outbound links in your content files
  • Convert - Convert affiliate links to clean URLs with proper tracking tags
  • Report - Generate reports in JSON, CSV, SQL, or Markdown format
  • Transform - Replace outbound links with tracking URLs (/link/slug)
  • Sync - Sync links to a database (Supabase or JSON file)

Installation

npm install affilinker

Or run directly with npx:

npx affilinker scan

Quick Start

  1. Create a config file (affilinker.config.mjs):
export default {
  content: {
    include: ['content/**/*.mdx'],
    exclude: ['**/node_modules/**'],
  },
  siteUrl: 'https://yoursite.com',
  tracking: {
    baseUrl: '/link/',
    slugStrategy: 'auto',
  },
  networks: {
    amazon: {
      enabled: true,
      tag: 'your-amazon-tag-20',
      cleanParams: true,
    },
  },
};
  1. Scan your content:
affilinker scan
  1. Generate a report:
affilinker report --format sql -o links.sql
  1. Transform your content to use tracking URLs:
affilinker transform --dry-run  # Preview changes
affilinker transform             # Apply changes

Commands

affilinker scan

Scan content files for outbound links.

affilinker scan [options]

Options:
  -c, --config <path>   Path to config file
  -p, --pattern <glob>  Override content include pattern
  --json                Output results as JSON
  --affiliate-only      Only show affiliate links
  --external-only       Only show external links

affilinker convert

Convert affiliate links to clean format with proper tags.

affilinker convert [options]

Options:
  -c, --config <path>   Path to config file
  -p, --pattern <glob>  Override content include pattern
  --json                Output results as JSON
  --network <name>      Only convert links from specific network

affilinker report

Generate reports of scanned links.

affilinker report [options]

Options:
  -c, --config <path>    Path to config file
  -p, --pattern <glob>   Override content include pattern
  -f, --format <type>    Output format: json, csv, sql, markdown (default: json)
  -o, --output <path>    Output file path (prints to stdout if not specified)
  -t, --table <name>     Table name for SQL output (default: affiliate_links)
  --affiliate-only       Only include affiliate links
  --external-only        Only include external links

affilinker transform

Transform links in content files to use tracking URLs.

affilinker transform [options]

Options:
  -c, --config <path>   Path to config file
  -p, --pattern <glob>  Override content include pattern
  --dry-run             Show changes without applying them
  --json                Output results as JSON

affilinker sync

Sync links with a database.

affilinker sync [options]

Options:
  -c, --config <path>   Path to config file
  -p, --pattern <glob>  Override content include pattern
  --dry-run             Show what would be synced without syncing
  --json                Output results as JSON

Configuration

Full Configuration Example

export default {
  content: {
    include: ['content/**/*.mdx', 'content/**/*.md'],
    exclude: ['**/node_modules/**', '**/dist/**'],
  },
  siteUrl: 'https://yoursite.com',
  tracking: {
    baseUrl: '/link/',
    slugStrategy: 'auto', // or 'manual'
  },
  networks: {
    amazon: {
      enabled: true,
      tag: 'your-amazon-tag-20',
      cleanParams: true, // Remove tracking parameters from URLs
    },
  },
  storage: {
    adapter: 'supabase', // or 'json'
    supabase: {
      url: process.env.SUPABASE_URL,
      serviceKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
      table: 'affiliate_links',
    },
    // Or for JSON file storage:
    // json: {
    //   path: './links.json',
    // },
  },
};

Supported Networks

  • Amazon Associates - Detects and converts Amazon product links

More networks coming soon.

Database Schema

If using the sync command with Supabase, create a table with this schema:

CREATE TABLE affiliate_links (
  id SERIAL PRIMARY KEY,
  slug TEXT UNIQUE NOT NULL,
  name TEXT NOT NULL,
  url TEXT NOT NULL,
  is_affiliate BOOLEAN DEFAULT false,
  network TEXT,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
  updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

How It Works

  1. Scanning: Affilinker parses your MDX/Markdown files using unified/remark and extracts all links.

  2. Detection: For each link, it checks if it matches a known affiliate network pattern (e.g., Amazon product links).

  3. Conversion: Affiliate links are converted to clean URLs with proper tracking tags. For example:

    • Before: http://www.amazon.com/gp/product/B000A6PPOK/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=B000A6PPOK&linkCode=as2&tag=donkitchencom-20
    • After: https://www.amazon.com/dp/B000A6PPOK?tag=donkitchencom-20
  4. Slug Generation: Each unique URL gets a slug generated from its link text. Duplicates are handled by appending domain names or numeric suffixes.

  5. Transformation: Original URLs in your content are replaced with tracking URLs (/link/slug-name).

License

MIT