{"id":13409364,"url":"https://github.com/ausi/slug-generator","last_synced_at":"2025-05-15T03:05:54.889Z","repository":{"id":39748777,"uuid":"98630693","full_name":"ausi/slug-generator","owner":"ausi","description":"Slug Generator Library for PHP, based on Unicode’s CLDR data","archived":false,"fork":false,"pushed_at":"2023-09-08T16:07:51.000Z","size":62,"stargazers_count":801,"open_issues_count":12,"forks_count":54,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-04-21T03:50:42.846Z","etag":null,"topics":["ascii","cldr","library","pretty-url","slug","slugify","transliteration","unicode"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ausi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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},"funding":{"github":["ausi"]}},"created_at":"2017-07-28T08:59:47.000Z","updated_at":"2025-03-30T13:38:26.000Z","dependencies_parsed_at":"2024-01-15T13:35:32.160Z","dependency_job_id":null,"html_url":"https://github.com/ausi/slug-generator","commit_stats":{"total_commits":58,"total_committers":4,"mean_commits":14.5,"dds":"0.051724137931034475","last_synced_commit":"98b3cc91197614b3e1a5488ee3d33cb1a868cfad"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ausi%2Fslug-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ausi%2Fslug-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ausi%2Fslug-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ausi%2Fslug-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ausi","download_url":"https://codeload.github.com/ausi/slug-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264765,"owners_count":22041793,"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":["ascii","cldr","library","pretty-url","slug","slugify","transliteration","unicode"],"created_at":"2024-07-30T20:01:00.179Z","updated_at":"2025-05-15T03:05:54.867Z","avatar_url":"https://github.com/ausi.png","language":"PHP","funding_links":["https://github.com/sponsors/ausi"],"categories":["PHP"],"sub_categories":[],"readme":"Slug Generator Library\n======================\n\n[![Build Status](https://img.shields.io/github/workflow/status/ausi/slug-generator/CI/master.svg?style=flat-square)](https://github.com/ausi/slug-generator/actions?query=branch%3Amaster)\n[![Coverage](https://img.shields.io/codecov/c/github/ausi/slug-generator/master.svg?style=flat-square)](https://codecov.io/gh/ausi/slug-generator)\n[![Packagist Version](https://img.shields.io/packagist/v/ausi/slug-generator.svg?style=flat-square)](https://packagist.org/packages/ausi/slug-generator)\n[![Downloads](https://img.shields.io/packagist/dt/ausi/slug-generator.svg?style=flat-square)](https://packagist.org/packages/ausi/slug-generator)\n[![MIT License](https://img.shields.io/github/license/ausi/slug-generator.svg?style=flat-square)](https://github.com/ausi/slug-generator/blob/master/LICENSE)\n\nThis library provides methods to generate slugs\nfor URLs, filenames or any other target that has a limited character set.\nIt’s based on PHPs Transliterator class which uses the data of the [CLDR][]\nto transform characters between different scripts (e.g. Cyrillic to Latin)\nor types (e.g. upper- to lower-case or from special characters to ASCII).\n\nUsage\n-----\n\n```php\n\u003c?php\nuse Ausi\\SlugGenerator\\SlugGenerator;\n\n$generator = new SlugGenerator;\n\n$generator-\u003egenerate('Hello Wörld!');  // Output: hello-world\n$generator-\u003egenerate('Καλημέρα');      // Output: kalemera\n$generator-\u003egenerate('фильм');         // Output: film\n$generator-\u003egenerate('富士山');         // Output: fu-shi-shan\n$generator-\u003egenerate('國語');           // Output: guo-yu\n\n// Different valid character set, a specified locale and a delimiter\n$generator = new SlugGenerator((new SlugOptions)\n    -\u003esetValidChars('a-zA-Z0-9')\n    -\u003esetLocale('de')\n    -\u003esetDelimiter('_')\n);\n$generator-\u003egenerate('Äpfel und Bäume');  // Aepfel_und_Baeume\n```\n\nInstallation\n------------\n\nTo install the library use [Composer][] or download the source files from GitHub.\n\n```sh\ncomposer require ausi/slug-generator\n```\n\nWhy create another slug library, aren’t there enough already?\n-------------------------------------------------------------\n\nThere are many code snippets and some good libraries out there that create slugs,\nbut I didn’t find anything that met my requirements.\nOptions are often very limited which makes it hard to customize for different use cases.\nSome libs carry large rulesets with them that try to convert characters to ASCII,\nno one uses Unicode’s [CLDR][]\nwhich is the standard for transliteration rules and many other transforms.\n\nBut most importantly no library was able to do the “correct” conversions,\nlike `Ö-Äpfel` to `OE-Aepfel` for German or `İNATÇI` to `inatçı` for Turkish.\nBecause the CLDR transliteration rules are context sensitive\nthey know how to correctly convert to `OE-Aepfel`\ninstead of `Oe-Aepfel` or `OE-AEpfel`.\nCLDR also takes the language into account\nand knows that the turkish uppercase letter `I`\nhas the lowercase form `ı` instead of `i`.\n\nOptions\n-------\n\nAll options can be set for the generator object itself `new SlugGenerator($options)`\nor overwritten when calling `generate($text, $options)`.\nOptions can by passed as array or as `SlugOptions` object.\n\n### `delimiter`, default `\"-\"`\n\nThe delimiter can be any string, it is used to separate words.\nIt gets stripped from the beginning and the end of the slug.\n\n```php\n$generator-\u003egenerate('Hello World!');                         // Result: hello-world\n$generator-\u003egenerate('Hello World!', ['delimiter' =\u003e '_']);   // Result: hello_world\n$generator-\u003egenerate('Hello World!', ['delimiter' =\u003e '%20']); // Result: hello%20world\n```\n\n### `validChars`, default `\"a-z0-9\"`\n\nValid characters that are allowed in the slug.\nThe [range syntax][] is the same as in character classes of regular expressions.\nFor example `abc`, `a-z0-9äöüß` or `\\p{Ll}\\-_`.\n\n```php\n$generator-\u003egenerate('Hello World!');                             // Result: hello-world\n$generator-\u003egenerate('Hello World!', ['validChars' =\u003e 'A-Z']);    // Result: HELLO-WORLD\n$generator-\u003egenerate('Hello World!', ['validChars' =\u003e 'A-Za-z']); // Result: Hello-World\n```\n\n### `ignoreChars`, default `\"\\p{Mn}\\p{Lm}\"`\n\nCharacters that should be completely removed and not replaced with a delimiter.\nIt uses the same syntax as the `validChars` option.\n\n```php\n$generator-\u003egenerate(\"don't remove\");                         // Result: don-t-remove\n$generator-\u003egenerate(\"don't remove\", ['ignoreChars' =\u003e \"'\"]); // Result: dont-remove\n```\n\n### `locale`, default `\"\"`\n\nThe locale that should be used for the Unicode transformations.\n\n```php\n$generator-\u003egenerate('Hello Wörld!');                        // Result: hello-world\n$generator-\u003egenerate('Hello Wörld!', ['locale' =\u003e 'de']);    // Result: hello-woerld\n$generator-\u003egenerate('Hello Wörld!', ['locale' =\u003e 'en_US']); // Result: hello-world\n```\n\n### `transforms`, default `Upper, Lower, Latn, ASCII, Upper, Lower`\n\nInternally the slug generator uses [Transform Rules][]\nto convert invalid characters to valid ones.\nThese rules can be customized\nby setting the `transforms`, `preTransforms` or `postTransforms` options.\nUsually setting `preTransforms` is desired\nas it applies the custom transforms\nprior to the default ones.\n\nHow [Transform Rules][] (like `Lower` or `ASCII`)\nand [rule sets][] (like `a \u003e b; c \u003e d;`) work\nis documented on the ICU website:\n\u003chttp://userguide.icu-project.org/transforms\u003e\n\n```php\n$generator-\u003egenerate('Damn 💩!!');                                           // Result: damn\n$generator-\u003egenerate('Damn 💩!!', ['preTransforms' =\u003e ['💩 \u003e Ice-Cream']]);  // Result: damn-ice-cream\n\n$generator-\u003egenerate('©');                                          // Result: c\n$generator-\u003egenerate('©', ['preTransforms' =\u003e ['© \u003e Copyright']]);  // Result: copyright\n$generator-\u003egenerate('©', ['preTransforms' =\u003e ['Hex']]);            // Result: u00a9\n$generator-\u003egenerate('©', ['preTransforms' =\u003e ['Name']]);           // Result: n-copyright-sign\n```\n\n[CLDR]: http://cldr.unicode.org/ \"Unicode Common Locale Data Repository\"\n[Composer]: https://getcomposer.org/\n[range syntax]: http://www.regular-expressions.info/charclass.html\n[Transform Rules]: http://userguide.icu-project.org/transforms/general\n[rule sets]: http://userguide.icu-project.org/transforms/general/rules\n\nSponsors\n--------\n\nThanks to [Blackfire](https://www.blackfire.io/) for sponsoring performance profiling tools for this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fausi%2Fslug-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fausi%2Fslug-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fausi%2Fslug-generator/lists"}