{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "slugify", "description": "A utility function to convert a string into a URL-friendly slug.", "files": [ { "path": "src/registry/new-york/lib/slugify.ts", "content": "/**\n * Convert a string to a URL-friendly slug.\n * @param text - The text to slugify.\n * @param options - Configuration options for slugification.\n * @param options.separator - Character to use as separator (default: '-').\n * @param options.lowercase - Whether to convert to lowercase (default: true).\n * @param options.strict - Whether to use strict mode (default: false).\n * @returns A URL-friendly slug.\n */\n\nexport function slugify(\n text: string,\n options: {\n separator?: string;\n lowercase?: boolean;\n strict?: boolean;\n } = {},\n): string {\n const { separator = \"-\", lowercase = true, strict = false } = options;\n\n if (!text || typeof text !== \"string\") {\n return \"\";\n }\n\n let slug = text.toString();\n\n // Convert to lowercase if specified\n if (lowercase) {\n slug = slug.toLowerCase();\n }\n\n // Replace accented characters with their base equivalents\n slug = slug.normalize(\"NFD\").replace(/\\p{M}/gu, \"\");\n\n if (strict) {\n // Strict mode: only keep alphanumeric characters and separators\n slug = slug.replace(/[^a-zA-Z0-9]/g, separator);\n } else {\n // Standard mode: replace spaces and special characters\n slug = slug\n .replace(/[^\\w\\s-]/g, \"\") // Remove special characters except word chars, spaces, and hyphens\n .replace(/[\\s_-]+/g, separator); // Replace spaces, underscores, and multiple hyphens with separator\n }\n\n // Remove leading/trailing separators and collapse multiple separators\n slug = slug\n .replace(new RegExp(`^${separator}+|${separator}+$`, \"g\"), \"\") // Remove leading/trailing separators\n .replace(new RegExp(`${separator}+`, \"g\"), separator); // Collapse multiple separators\n\n return slug;\n}\n", "type": "registry:lib" } ], "type": "registry:lib" }