{"id":16683462,"url":"https://github.com/ctolkien/slugify","last_synced_at":"2025-05-15T17:08:28.513Z","repository":{"id":11057003,"uuid":"62201580","full_name":"ctolkien/Slugify","owner":"ctolkien","description":"Simple Slug / Clean URL generator helper for Microsoft .NET framework / .NET Standard.","archived":false,"fork":false,"pushed_at":"2025-04-09T03:44:11.000Z","size":1068,"stargazers_count":106,"open_issues_count":5,"forks_count":14,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-15T17:08:16.269Z","etag":null,"topics":["dotnet-core","dotnet-standard","hacktoberfest","slugifier","slugify","url"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"fcingolani/Slugify","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ctolkien.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["ctolkien"]}},"created_at":"2016-06-29T06:30:47.000Z","updated_at":"2025-04-15T19:24:58.000Z","dependencies_parsed_at":"2023-11-15T07:31:24.886Z","dependency_job_id":"c363d589-ce29-41d4-a384-34c93805213b","html_url":"https://github.com/ctolkien/Slugify","commit_stats":{"total_commits":180,"total_committers":11,"mean_commits":"16.363636363636363","dds":0.5555555555555556,"last_synced_commit":"d480e12e3a1451e4b5ca5f070b7fb58db8f48b6c"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctolkien%2FSlugify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctolkien%2FSlugify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctolkien%2FSlugify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctolkien%2FSlugify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctolkien","download_url":"https://codeload.github.com/ctolkien/Slugify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384988,"owners_count":22062422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet-core","dotnet-standard","hacktoberfest","slugifier","slugify","url"],"created_at":"2024-10-12T14:24:48.344Z","updated_at":"2025-05-15T17:08:23.488Z","avatar_url":"https://github.com/ctolkien.png","language":"C#","funding_links":["https://github.com/sponsors/ctolkien"],"categories":[],"sub_categories":[],"readme":"Slugify Core\n=======\n\n\u003e This is a fork of the original project here: [https://github.com/fcingolani/Slugify](https://github.com/fcingolani/Slugify). This has been updated for .NET Standard 2.0 support (older versions support .NET Standard down to 1.3).\n\n[![Build status](https://github.com/ctolkien/Slugify/actions/workflows/main.yml/badge.svg)](https://github.com/ctolkien/Slugify/actions/workflows/dotnet.yml)\n[![Current NuGet release](https://img.shields.io/nuget/v/slugify.core.svg?maxAge=2000)](https://www.nuget.org/packages/Slugify.Core)\n[![MIT license](https://img.shields.io/github/license/ctolkien/Slugify.svg?maxAge=2592000)](https://github.com/ctolkien/Slugify/blob/master/LICENSE)\n\nSimple [Slug / Clean URL](http://en.wikipedia.org/wiki/Slug_%28web_publishing%29#Slug) generator helper for Microsoft .NET.\n\nWith default settings, you will get an **hyphenized**, **lowercase**, **alphanumeric** version of any string you please, with any [diacritics](http://en.wikipedia.org/wiki/Diacritic) removed, whitespace and dashes collapsed, and whitespace trimmed.\n\nFor example, having:\n\n\u003e a ambição cerra o coração\n\nYou'll get:\n\n\u003e a-ambicao-cerra-o-coracao\n\nInstallation\n------------\n\nYou can get the [Slugify NuGet package](https://www.nuget.org/packages/Slugify.Core/) by running the following command in the [Package Manager Console](http://docs.nuget.org/docs/start-here/using-the-package-manager-console):\n\n```\nPM\u003e Install-Package Slugify.Core\n```\n\nOr running `dotnet add package Slugify.Core` from the command line.\n\nUpgrading from 4.x to 5.x\n-----------------------------\n\n* 5.0 is significantly faster and uses less memory. 2-3x faster than version 4 and allocates about 20% less memory.\n* `DeniedCharactersRegex` is no longer a string, and it now takes in a `Regex` object. This will allow you to use Source Generated regexes on platforms that support them. Using something like:\n```csharp\n[GeneratedRegex(@\"[^a-z0-9\\-\\._]\")]\nprivate static partial Regex GeneratedRegex();\n```\n* Using a generated regex version will be ever so slightly the fastest way of generating a slug on platforms that support it. However it will use a bit more memory.\n* The way tab and new-line characters are handled has been changed. They are no longer translated to `-` by default and will instead be stripped. This will only be a noticeable change if you have disabled `CollapseDashes` (which is not the default).\n* The option to disable collapsing whitespace has been removed.\n* `AllowedChars` is renamed to `AllowedCharacters`.\n\n\nUpgrading from 2.x to 3.x\n-------------------------\n\n* 3.0 is a significantly faster and less memory intensive version of the Slugifier. Whilst effort has been made to maintain backwards compatability, there may be some breaking changes.\n* The `SlugHelper.Config` nested class has been renamed to just `SlugHelperConfiguration`.\n\nBasic Usage\n-----------\n\nIt's really simple! Just instantiate `SlugHelper` and call its `GenerateSlug` method with the **string** you want to convert; it'll return the slugified version:\n\n```csharp\nusing Slugify;\n\npublic class MyApp\n{\n    public static void Main()\n    {\n        SlugHelper helper = new SlugHelper();\n\n        String title = \"OLA ke ase!\";\n\n        String slug = helper.GenerateSlug(title);\n\n        Console.WriteLine(slug); // \"ola-ke-ase\"\n    }\n}\n```\n\nSupporting Non-ASCII Characters\n-------------------------------\n\nIf you want to support non-ASCII characters, you can use the `SlugHelperForNonAsciiLanguages` class instead of `SlugHelper`. This is a derived class which will translate the characters provided into something \"equivalent\" in ASCII. \n\n\nConfiguration\n-------------\n\nThe default configuration of `SlugHelper` will make the following changes to the passed input in order to generate a slug:\n\n- Transform all characters to lower-case, to produce a lower-case slug.\n- Trim all leading and trailing whitespace.\n- Collapse all consecutive whitespace into a single space.\n- Replace spaces with a dash.\n- Remove all non-alphanumerical ASCII characters.\n- Collapse all consecutive dashes into a single one.\n\nYou can customize most of this behavior by passing a `SlugHelperConfiguration` object to the `SlugHelper` constructor. For example, the following example will keep upper-case characters in the input and provides a custom handling for ampersands in the input:\n\n```csharp\n// Creating a configuration object\nvar config = new SlugHelperConfiguration();\n\n// Add individual replacement rules\nconfig.StringReplacements.Add(\"\u0026\", \"-\");\nconfig.StringReplacements.Add(\",\", \"-\");\n\n// Keep the casing of the input string\nconfig.ForceLowerCase = false;\n\n// Create a helper instance with our new configuration\nvar helper = new SlugHelper(config);\n\nvar result = helper.GenerateSlug(\"Simple,short\u0026quick Example\");\nConsole.WriteLine(result); // Simple-short-quick-Example\n```\n\nThe following options can be configured with the `SlugHelperConfiguration`:\n\n### `ForceLowerCase`\nThis specifies whether the output string should be converted to lower-case. If set to `false`, the original casing will be preserved. The lower-case conversion happens before any other character replacements are being made.\n\n-  Default value: `true`\n\n### `TrimWhitespace`\nThis specifies whether leading and trailing whitespace should be removed from the input string. The whitespace will be trimmed before any other character replacements are being made.\n\n- Default value: `true`\n\n### `CollapseDashes`\nThis specifies wehther consecutive dashes (`\"-\"`) should be collapsed into a single dash. This is useful to avoid scenarios like `\"foo \u0026 bar\"` becoming `\"foo--bar\"`. Dashes will be collapsed after all other string replacements have been made before the final result string is returned.\n\n- Default value: `true`\n\n### `StringReplacements`\nThis is a dictionary containing a mapping of characters that should be replaced individually before the translation happens. By default, this will replace space characters with a hyphen.\n\nString replacements are being made after whitespace has been trimmed and collapsed, after the input string has been converted to lower-case characters, but before any characters are removed, to allow replacing characters that would otherwise be just removed.\n\n-  Default value:\n\n   ```csharp\n   new Dictionary\u003cstring, string\u003e {\n      [\" \"] = \"-\", // replace space with a hyphen\n   }\n   ```\n\n-  Examples:\n\n   ```csharp\n   var config = new SlugHelperConfiguration();\n\n   // replace the dictionary completely\n   config.StringReplacements = new() {\n       [\"ä\"] = \"ae\",\n       [\"ö\"] = \"oe\",\n       [\"ü\"] = \"ue\",\n   };\n\n   // or add individual replacements to it\n   config.StringReplacements.Add(\"ß\", \"ss\");\n   ```\n\n### `AllowedCharacters`\nSet of characters that are allowed in the slug, which will be kept when the input string is being processed. By default, this contains all ASCII characters, the full stop, the dash and the underscore. This is the preferred way of controlling which characters should be replaced when generating the slug.\n\nCharacters that are not allowed will be replaced after string replacements are completed.\n\n-  Default value: Alphanumerical ASCII characters, the full stop (`.`), the dash (`-`), and the underscore (`-`).\n   `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._`)\n\n-  Examples:\n\n   ```csharp\n   var config = new SlugHelperConfiguration();\n\n   // add individual characters to the list of allowed characters\n   config.AllowedCharacters.Add('!');\n\n   // remove previously added or default characters\n   config.AllowedCharacters.Remove('.');\n   ```\n\n### `DeniedCharactersRegex`\nAlternative method of specifying which characters will be allowed in the slug, which will replace the functionality of the `AllowedChars` set. The value must be a valid regular expression that specifies which characters *are to be removed*. Every match of this regular expression in the input string will be removed. The removal happens after string replacements are completed.\n\nSpecifying the `DeniedCharactersRegex` option will disable the character removal behavior from the `AllowedChars` option.\n\n-  Default value: `null`\n\n-  Examples:\n\n   ```csharp\n   var helper = new SlugHelper(new SlugHelperConfiguration\n   {\n       // this is equivalent to the default behavior from `AllowChars`\n       DeniedCharactersRegex = new(@\"[^a-zA-Z0-9._-]\")\n   });\n   Console.WriteLine(helper.GenerateSlug(\"OLA ke ase!\")); // \"ola-ke-ase\"\n\n   helper = new SlugHelper(new SlugHelperConfiguration\n   {\n       // remove certain characters explicitly\n       DeniedCharactersRegex = new(@\"[abcdef]\")\n   });\n   Console.WriteLine(helper.GenerateSlug(\"abcdefghijk\")); // \"ghijk\"\n\n   helper = new SlugHelper(new SlugHelperConfiguration\n   {\n       // remove more complex matches\n       DeniedCharactersRegex = new(@\"foo|bar\")\n   });\n   Console.WriteLine(helper.GenerateSlug(\"this is an foo example\")); // \"this-is-an-example\"\n   ```\n\n### `MaximumLength`\n\nThis will limit the length of the generated slug to be a maximum of the number of chars given by the parameter. If the truncation happens in a way that a trailing `-` is left, it will be removed.\n\n- Default value: `null`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctolkien%2Fslugify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctolkien%2Fslugify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctolkien%2Fslugify/lists"}