teariot / beautyslug
Lightweight PHP library for generating random readable slugs.
1.0.0
2025-04-28 22:59 UTC
Requires
- php: ^8.2
README
BeautySlug is a lightweight, flexible PHP library for generating beautiful, readable slugs.
🚀 Installation
Install via Composer:
composer require teariot/beautyslug
⚡ Quick Usage
use BeautySlug\BeautySlug; use BeautySlug\SlugWords; // Basic random slug echo BeautySlug::slug(); // Example: wonderful-tree // Slug with a color and an animal echo BeautySlug::slug([ SlugWords::color(1), SlugWords::animal(1), ]); // Example: blue-lion // Slug with digits appended echo BeautySlug::slug([ SlugWords::adjective(1), SlugWords::noun(1), ], [ 'appendDigits' => true, 'digitsCount' => 5, ]); // Example: fancy-robot-48291
⚙️ Options
Option | Type | Description | Default |
---|---|---|---|
separator |
string |
Separator between words | - |
appendDigits |
bool |
Append random digits at the end | false |
digitsCount |
int |
Number of digits to append if enabled | 4 |
You can override options by passing an array as the second parameter to slug()
.
🧩 Available Word Categories
BeautySlug uses predefined word lists:
adjective
noun
color
season
emoji
verb
animal
cosmos
You can directly access random words:
SlugWords::adjective(2); // Get 2 random adjectives SlugWords::noun(1); // Get 1 random noun SlugWords::color(1); // Get 1 random color
📂 Example Script
See the examples/usage.php
file for more examples.
To run:
php examples/usage.php
📄 License
Released under the MIT License.
Built with ❤️ by Teariot