lacus / utils
Reusable utilities library for Lacus Solutions' packages (type description, HTML escaping, random sequences)
1.0.0
2026-03-11 18:10 UTC
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^10.5
- spatie/phpunit-watcher: ~1.24
README
A PHP reusable utilities library for Lacus Solutions' packages.
| Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ |
Features
- Type description: Human-readable type strings for error messages (primitives, arrays,
NaN,Infinity) - HTML escaping: Escape
&,<,>,",'for safe output and XSS mitigation - Random sequences: Generate numeric, alphabetic, or alphanumeric sequences of any length
- URI encoding: Percent-encode/decode URI components (path, query, fragment) per RFC 3986
- Zero dependencies: No production dependencies
Installation
composer require lacus/utils
Quick Start
<?php use Lacus\Utils\HtmlUtils; use Lacus\Utils\SequenceGenerator; use Lacus\Utils\SequenceType; use Lacus\Utils\TypeDescriber; use Lacus\Utils\UrlUtils; TypeDescriber::describe(null); // 'null' TypeDescriber::describe('hello'); // 'string' TypeDescriber::describe(42); // 'integer number' TypeDescriber::describe([1, 2, 3]); // 'number[]' HtmlUtils::escape('Tom & Jerry'); // 'Tom & Jerry' HtmlUtils::unescape('Tom & Jerry'); // 'Tom & Jerry' SequenceGenerator::generate(10, SequenceType::Numeric); // e.g. '9956000611' SequenceGenerator::generate(6, SequenceType::Alphabetic); // e.g. 'AXQMZB' UrlUtils::encodeUriComponent('a b'); // 'a%20b' UrlUtils::decodeUriComponent('a%20b'); // 'a b'
API
All classes live under the Lacus\Utils namespace.
| Class | Method | Description |
|---|---|---|
TypeDescriber |
describe(mixed $value): string |
Type description for error messages |
HtmlUtils |
escape, unescape |
HTML entity escaping and decoding |
SequenceGenerator |
generate(int $size, SequenceType $type): string |
Random sequence generation |
SequenceType |
enum: Numeric, Alphabetic, Alphanumeric |
Sequence kind |
UrlUtils |
encodeUriComponent, decodeUriComponent |
URI component percent-encoding (RFC 3986) |
TypeDescriber::describe()
Same behaviour as JS describeType: null, string, boolean, integer number, float number, NaN, Infinity, Array (empty), number[], (number | string)[], object, resource, etc.
HtmlUtils
- escape(string $value): string — Escapes HTML special characters:
&→&,<→<,>→>,"→",'→'. Use for safe output and XSS mitigation. - unescape(string $value): string — Decodes those entities (reverse of
escape). Use only on previously escaped or trusted content; decoded output is not safe for direct insertion into HTML.
SequenceGenerator::generate()
- Numeric: digits
0-9 - Alphabetic: uppercase
A-Z - Alphanumeric:
0-9andA-Z
UrlUtils (URI encoding)
- encodeUriComponent(string $value): string — Percent-encode a string for use as any URI component (path segment, query name/value, or fragment). E.g.
a/b→a%2Fb,a b→a%20b. - decodeUriComponent(string $value): string — Decode a percent-encoded URI component (reverse of
encodeUriComponent).