Utility functions to normalize text and compute similarity for duplicate detection.
// Source: https://github.com/f/prompts.chat | License: CC0-1.0
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Content similarity utilities for duplicate detection
*/
/**
* Normalize content for comparison by:
* - Removing variables (${...} patterns)
* - Converting to lowercase
* - Removing extra whitespace
* - Removing punctuation
*/
export function normalizeContent(content: string): string {
return content
// Remove variables like ${variable} or ${variable:default}
.replace(/\$\{[^}]+\}/g, "")
// Remove common placeholder patterns like [placeholder] or <placeholder>
.replace(/\[[^\]]+\]/g, "")
.replace(/<[^>]+>/g, "")
// Convert to lowercase
.toLowerCase()
// Remove punctuation
.replace(/[^\w\s]/g, "")
// Normaliz
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key