@tpmjs/tools-url-normalize
Normalize URLs with configurable options including lowercase conversion, trailing slash removal, query parameter sorting, hash removal, default port removal, and www removal. Useful for URL deduplication, comparison, and canonicalization.
Test @tpmjs/tools-url-normalize (urlNormalizeTool) with AI-powered execution
0/2000 characters
Install this tool and use it with the AI SDK
npm install @tpmjs/tools-url-normalizepnpm add @tpmjs/tools-url-normalizeyarn add @tpmjs/tools-url-normalizebun add @tpmjs/tools-url-normalizedeno add npm:@tpmjs/tools-url-normalizeimport { urlNormalizeTool } from '@tpmjs/tools-url-normalize';import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { urlNormalizeTool } from '@tpmjs/tools-url-normalize';
const result = await generateText({
model: openai('gpt-4o'),
tools: { urlNormalizeTool },
prompt: 'Your prompt here...',
});
console.log(result.text);Available configuration options
urlstringThe URL to normalize (must be a valid absolute URL)
optionsobjectNormalization options
Schema extracted: 1/1/2026, 8:18:06 AM
Normalize URLs with configurable options for consistent URL handling.
npm install @tpmjs/tools-url-normalize
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: '' }, // ]
url (string, required): The URL to normalizeoptions (object, optional): Normalization options
sortParams (boolean, default: true): Sort query parameters alphabeticallyremoveHash (boolean, default: false): Remove URL fragment/hashlowercase (boolean, default: true): Convert protocol and hostname to lowercaseremoveTrailingSlash (boolean, default: true): Remove trailing slash from pathnameremoveDefaultPort (boolean, default: true): Remove default portsremoveWWW (boolean, default: false): Remove www subdomain{ 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; }; }
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', });
MIT
Downloads/month
0
Quality Score