Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seyfahni/haikunator
Generate random words or phrases usable as IDs.
https://github.com/seyfahni/haikunator
Last synced: 13 minutes ago
JSON representation
Generate random words or phrases usable as IDs.
- Host: GitHub
- URL: https://github.com/seyfahni/haikunator
- Owner: seyfahni
- License: mit
- Created: 2023-01-19T17:13:38.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-23T16:40:21.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T03:44:00.262Z (28 days ago)
- Language: PHP
- Size: 42 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Haikunator
This project was inspired by [HaikunatorPHP](https://github.com/Atrox/haikunatorphp) and [Jitsi](https://jitsi.org/).
It allows generation of human-friendly IDs.
## Installation
```bash
composer require seyfahni/haikunator
```## Usage
As a consumer you can expect an `Haikunator` instance to be injected into your class.
To generate an id just call the `haikunate()` method:
```php
use seyfahni\Haikunator\Haikunator;/** @var Haikunator $haikunator */
$haikunator->haikunate();
```### Creating an instance via `Haikunators`
The `Haikunators` helper class contains methods for easy creation of common `Haikunator`s:
```php
use seyfahni\Haikunator\Haikunators;$atroxHaikunator = Haikunators::atroxHaikunator();
$jitsiHaikunator = Haikunators::jitsiHaikunator();
```### Creating a `Haikunator` by hand
There are multiple implementation of the `Haikunator` interface provided.
Usually you want to put a combination of `WordListHaikunator`s and `CharactersHaikunator` into one `AppendingHaikunator`.```php
use seyfahni\Haikunator\AppendingHaikunator;
use seyfahni\Haikunator\CharactersHaikunator;
use seyfahni\Haikunator\ConstantHaikunator;
use seyfahni\Haikunator\MtRandIntegerGenerator;
use seyfahni\Haikunator\WordListHaikunator;$numberGenerator = new MtRandIntegerGenerator();
# Generate IDs like my-useful-aHt
$haikunator = new AppendingHaikunator([
new ConstantHaikunator('my'),
new WordListHaikunator($numberGenerator, ['fancy', 'useful', 'modular']),
new CharactersHaikunator($numberGenerator, 'Haikunator', 3),
], '-'
);
```The `IntegerGenerator` interface is used by some `Haikunator` implementations so that
any kind of number generation can be used via adapter implementation.### Extension
Use your own generation logic by implementing the `Haikunator` interface and using an instance of it via "creation by hand".