An open API service indexing awesome lists of open source software.

https://github.com/teariot/beautyslug

Lightweight PHP library for generating random readable slugs.
https://github.com/teariot/beautyslug

cms-friendly-slug composer friendly-url laravel-slug php php-slug random-slug seo seo-friendly-slug seo-url slug-generator slugify unique-slug url-identifier url-slug

Last synced: 5 months ago
JSON representation

Lightweight PHP library for generating random readable slugs.

Awesome Lists containing this project

README

          

# BeautySlug

[![PHP Version](https://img.shields.io/badge/PHP-8.0%2B-blue.svg)](https://www.php.net/)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)

**BeautySlug** is a lightweight, flexible PHP library for generating beautiful, readable slugs.

---

## 🚀 Installation

Install via Composer:

```bash
composer require teariot/beautyslug
```

---

## ⚡ Quick Usage

```php
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:

```php
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`](examples/usage.php) file for more examples.

To run:

```bash
php examples/usage.php
```

---

## 📄 License

Released under the [MIT License](LICENSE).

---

> Built with ❤️ by [Teariot](https://github.com/teariot)