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-url-normalize

v0.2.0

Published

Normalize URLs with configurable options for consistent URL handling

Readme

@tpmjs/tools-url-normalize

Normalize URLs with configurable options for consistent URL handling.

Installation

npm install @tpmjs/tools-url-normalize

Usage

import { urlNormalizeTool } from '@tpmjs/tools-url-normalize';

// Use with AI SDK
const result = await urlNormalizeTool.execute({
  url: 'HTTPS://WWW.Example.COM:443/path/?z=1&a=2#section',
  options: {
    sortParams: true,
    removeHash: true,
    lowercase: true,
    removeTrailingSlash: true,
    removeDefaultPort: true,
    removeWWW: true,
  },
});

console.log(result.normalized);
// 'https://example.com/path?a=2&z=1'

console.log(result.changes);
// [
//   { type: 'lowercase', description: '...', before: 'HTTPS:', after: 'https:' },
//   { type: 'lowercase', description: '...', before: 'WWW.Example.COM', after: 'www.example.com' },
//   { type: 'removeWWW', description: '...', before: 'www.example.com', after: 'example.com' },
//   { type: 'removeDefaultPort', description: '...', before: '443', after: '' },
//   { type: 'sortParams', description: '...', before: '?z=1&a=2', after: '?a=2&z=1' },
//   { type: 'removeHash', description: '...', before: '#section', after: '' },
// ]

Features

  • Lowercase conversion: Converts protocol and hostname to lowercase
  • Trailing slash removal: Removes trailing slashes from pathnames
  • Query parameter sorting: Sorts query parameters alphabetically
  • Hash removal: Optionally removes URL fragments
  • Default port removal: Removes standard ports (80, 443, 21)
  • WWW removal: Optionally removes www subdomain
  • Change tracking: Reports all transformations applied

Parameters

  • url (string, required): The URL to normalize
  • options (object, optional): Normalization options
    • sortParams (boolean, default: true): Sort query parameters alphabetically
    • removeHash (boolean, default: false): Remove URL fragment/hash
    • lowercase (boolean, default: true): Convert protocol and hostname to lowercase
    • removeTrailingSlash (boolean, default: true): Remove trailing slash from pathname
    • removeDefaultPort (boolean, default: true): Remove default ports
    • removeWWW (boolean, default: false): Remove www subdomain

Returns

{
  normalized: string;
  original: string;
  changes: Array<{
    type: string;
    description: string;
    before: string;
    after: string;
  }>;
  metadata: {
    protocol: string;
    hostname: string;
    pathname: string;
    hasQueryParams: boolean;
    hasHash: boolean;
  };
}

Use Cases

  • URL deduplication in web crawlers
  • Canonical URL generation for SEO
  • Link comparison and matching
  • Database indexing of URLs
  • Analytics tracking consistency

Example with AI Agent

import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
import { urlNormalizeTool } from '@tpmjs/tools-url-normalize';

const result = await generateText({
  model: openai('gpt-4'),
  tools: {
    urlNormalize: urlNormalizeTool,
  },
  prompt: 'Normalize this URL and remove the hash: https://Example.com/PATH/?b=2&a=1#top',
});

License

MIT