PHPackages                             hatchyu/string-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. hatchyu/string-utils

ActiveLibrary

hatchyu/string-utils
====================

Smart PHP string utilities for slugging, casing, transliteration, and unique hash generation

v1.0.0(1mo ago)02↑2900%MITPHPPHP ^8.3

Since Mar 25Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/rajeshmk/string-utils)[ Packagist](https://packagist.org/packages/hatchyu/string-utils)[ RSS](/packages/hatchyu-string-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Hatchyu String Utils
====================

[](#hatchyu-string-utils)

A powerful PHP string manipulation library for smarter slugging, casing, and monotonic unique hash generation.

The main goal of this package is to improve code-like and identifier-like strings that Laravel's default `Str::slug()` tends to flatten too aggressively. It handles camelCase, StudlyCase, acronym boundaries, number-to-word transitions, Unicode transliteration, and optional compound-word protection.

Features
--------

[](#features)

- **Smart Slugging**: Intelligent splitting of acronyms, camelCase, and numeric boundaries.
- **Compound Words Support**: Protect specific brand names (e.g., "MySQL", "iPhone") from being split.
- **Multilingual Support**: Robust transliteration for Greek, Malayalam, Hindi, Arabic, Chinese, Japanese, and more.
- **SEO Optimized**: Handles symbols like `@` as `-at-` and respects word boundaries when limiting length.
- **Unique Hash Generation**: Monotonic time-based unique hashes with custom lengths.

Installation
------------

[](#installation)

```
composer require hatchyu/string-utils
```

Requirements
------------

[](#requirements)

- PHP `^8.3`
- `ext-intl` is optional, but recommended if you want transliteration such as `ÜberCafe -> uber-cafe` or non-Latin text converted into Latin slugs

Without `ext-intl`, the slug helpers still work, but transliteration depends only on the raw input that PHP receives.

Usage
-----

[](#usage)

```
use Hatchyu\String\StrTo;

echo StrTo::slug('DBSettings');         // db-settings
echo StrTo::slug('rajesh@example.com'); // rajesh-at-example-com
echo StrTo::headline('DBSettings');     // DB Settings
```

StrTo Helpers
-------------

[](#strto-helpers)

### Slugging helpers

[](#slugging-helpers)

```
StrTo::slug('apiV10Endpoint');              // api-v10-endpoint
StrTo::snake('apiV10Endpoint');             // api_v10_endpoint
StrTo::kebab('apiV10Endpoint');             // api-v10-endpoint
StrTo::dotted('moduleDirectory/FileName');  // module.directory.file.name
StrTo::dotPath('moduleDirectory/FileName'); // module-directory.file-name
```

- `slug(string $string, int $maxLength = 120, string $lang = 'en'): string`Produces a URL-friendly slug. Keeps `@` as `-at-`, transliterates to ASCII for English when `ext-intl` is installed, preserves word boundaries better than a plain flatten-and-replace approach, and trims to the first wrapped segment.
- `snake(string $string): string`Same smart word splitting, with `_` separators.
- `kebab(string $string): string`Same smart word splitting, with `-` separators.
- `dotted(string $string): string`Same smart word splitting, with `.` separators.
- `dotPath(string $path): string`Converts slash-separated or namespace-like paths into dot notation with kebab-cased segments.

### Casing helpers

[](#casing-helpers)

```
StrTo::title('hatchyu API EndPoint');    // Hatchyu Api End Point
StrTo::words('hatchyu API EndPoint');    // Hatchyu API End Point
StrTo::headline('hatchyu API EndPoint'); // Hatchyu API End Point
StrTo::studly('hatchyu API EndPoint');   // HatchyuApiEndPoint
StrTo::camel('hatchyu API EndPoint');    // hatchyuApiEndPoint
StrTo::upper('hatchyu API EndPoint');    // HATCHYU API ENDPOINT
StrTo::lower('hatchyu API EndPoint');    // hatchyu api endpoint
StrTo::ucfirst('hatchyu API EndPoint');  // Hatchyu API EndPoint
StrTo::lcfirst('hatchyu API EndPoint');  // hatchyu API EndPoint
```

- `title(string $string): string`Converts the string to title case after smart word splitting.
- `words(string $string): string`A smarter `ucwords()` variant that keeps fully-uppercase technical tokens like `DB`.
- `headline(string $string): string`Alias of `words()`.
- `studly(string $string): string`Converts the string to StudlyCase.
- `camel(string $string): string`Converts the string to camelCase.
- `upper(string $string): string`Converts the string to uppercase.
- `lower(string $string): string`Converts the string to lowercase.
- `ucfirst(string $string): string`Uppercases only the first character.
- `lcfirst(string $string): string`Lowercases only the first character.
- `substr(string $string, int $start, ?int $length = null): string`UTF-8 safe substring helper.

Compound Words
--------------

[](#compound-words)

Some business or technical terms are better kept intact instead of being split by the generic regex rules. For that, you can register compound words once:

```
use Hatchyu\String\StrTo;

StrTo::setCompoundWords(['B2B', 'MySQL', 'OAuth2', 'IPv6', 'i18n', 'GraphQL', 'YouTube', 'macOS', 'iPhone']);

StrTo::slug('B2BLeadAPI');        // b2b-lead-api
StrTo::slug('MySQL8Adapter');     // mysql8-adapter
StrTo::slug('OAuth2CallbackURL'); // oauth2-callback-url
StrTo::slug('IPv6Address');       // ipv6-address
StrTo::slug('i18nConfig');        // i18n-config
StrTo::slug('GraphQLAPI');        // graphql-api
StrTo::slug('YouTubeAPIClient');  // youtube-api-client
StrTo::slug('macOSConfig');       // macos-config
StrTo::slug('iPhoneCase');        // iphone-case
```

This is useful when your SEO slugs need to reflect business or domain vocabulary more precisely than generic splitting rules can infer on their own.

Important note:

- `setCompoundWords()` changes package-wide static state for the current PHP process
- if you call it, later `StrTo` calls in the same process will use that configured list until you replace or clear it

To clear the configured list:

```
StrTo::setCompoundWords([]);
```

Laravel Comparison
------------------

[](#laravel-comparison)

The table below compares Laravel's default `Str::slug()` behavior with the default `StrTo::slug()` behavior, without any configured compound words.

SeedLaravel Str::slug()Hatchyu StrTo::slug()DBSettingsdbsettingsdb-settingshasConsecutiveCAPShasconsecutivecapshas-consecutive-capsNewHDDModulenewhddmodulenew-hdd-moduleapiV2Endpointapiv2endpointapi-v2-endpointusingSHA256Hashingusingsha256hashingusing-sha256-hashingVersion2APIversion2apiversion2-apiXMLHttpRequest2Handlerxmlhttprequest2handlerxml-http-request2-handlerIPv6Addressipv6addressipv6-addressparseURL2HTMLparseurl2htmlparse-url2-htmlJSON2XMLConverterjson2xmlconverterjson2-xml-converteruserID42Profileuserid42profileuser-id42-profileMySQL8Adaptermysql8adaptermy-sql8-adapterSimpleXMLParsersimplexmlparsersimple-xml-parserCSS3Parsercss3parsercss3-parseradmin/ModuleName/File.phpadminmodulenamefilephpadmin-module-name-file-phpWebERPweberpweb-erpHDDCapacityhddcapacityhdd-capacitytestUPPERIsOKNowtestupperisoknowtest-upper-is-ok-now2GB RAMWillBe 2gb ram2gb-ramwillbe-2gb-ram2-gb-ram-will-be-2-gb-ram123number and number123 small123number-and-number123-small123-number-and-number123-smallFirstCaps and lastcapYesfirstcaps-and-lastcapyesfirst-caps-and-lastcap-yesCreatedAtcreatedatcreated-atΤάχιστη αλώπηξ βαφής ψημένη γη,takhisti-alwpiks-vafis-psimeni-ghitachiste-alopex-baphes-psemene-geδρασκελίζει υπέρ νωθρού κυνόςdraskelizei-iper-nothrou-kinosdraskelizei-yper-nothrou-kynosΤάχιστη Αλώπηξ Βαφήσ Ψημένη Γη,takhisti-alwpiks-bafis-psimeni-gitachiste-alopex-baphes-psemene-geΔρασκελίζει Υπέρ Νωθρού Κυνόσdraskelizei-yper-nothrou-kinosdraskelizei-yper-nothrou-kynosmore...Dots.... yes.moredots-yesmore-dots-yesഇതിന് മലയാളം പരിഭാഷപ്പെടുത്താനും കഴിയുംitin-malayalam-paribhasappetuttanum-kaliyumयह हिंदी का अनुवाद भी कर सकता हैyaha-hatha-ka-anavatha-bha-kara-sakata-hayaha-hindi-ka-anuvada-bhi-kara-sakata-haiஇது தமிழையும் மொழிபெயர்க்கலாம்itu-tamilaiyum-molipeyarkkalamఇది తెలుగును కూడా అనువదించగలదుidi-telugunu-kuda-anuvadincagaladuಇದು ಕನ್ನಡವನ್ನೂ ಅನುವಾದಿಸಬಹುದುidu-kannadavannu-anuvadisabahuduهذا يمكن أيضا أن يترجم العربيةhtha-ymkn-ayda-an-ytrgm-alaarbyhdha-ymkn-ayda-an-ytrjm-al-rbyt这个也可以翻译成中文zhe-ge-ye-ke-yi-fan-yi-cheng-zhong-wenこれは日本語も翻訳できますkoreha-ri-ben-yumo-fan-yidekimasu`rajesh@example.com`rajesh-at-examplecomrajesh-at-example-comDefault Slug vs Compound-Word-Aware Slug
----------------------------------------

[](#default-slug-vs-compound-word-aware-slug)

The generic slug rules already improve many technical strings, but they cannot always infer business-specific or brand-specific tokens perfectly. When you explicitly register compound words, the slug can become even more intentional.

Examples:

```
StrTo::setCompoundWords(['B2B', 'MySQL', 'i18n', 'GraphQL', 'YouTube', 'iPhone']);
```

SeedDefault StrTo::slug()With setCompoundWords(...)B2BLeadAPIb2-blead-apib2b-lead-apiMySQL8Adaptermy-sql8-adaptermysql8-adapterGraphQL APIgraph-ql-apigraphql-apiYouTube APIClientyou-tube-api-clientyoutube-api-clienti18nConfigi18-n-configi18n-configiPhoneCasei-phone-caseiphone-caseThe important idea is not that every string needs configured compounds. The default behavior should stay generic. Compound words are there when your business vocabulary deserves better-than-generic splitting.

Hash Helper
-----------

[](#hash-helper)

```
use Hatchyu\String\Hash;

echo Hash::uniqueHash(40);
```

- `uniqueHash(int $length = 40): string`Generates a monotonic unique hash with a time-derived prefix and random padding.
- minimum supported length is `24`

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/743e9d5b6f56260847460cad4084ed9c341d791eaad645f0d318f686786d72ac?d=identicon)[rajeshmk](/maintainers/rajeshmk)

---

Top Contributors

[![rajeshmk](https://avatars.githubusercontent.com/u/227696?v=4)](https://github.com/rajeshmk "rajeshmk (24 commits)")

---

Tags

laravelphpseoseo-optimizationslugstring-manipulationutilities

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hatchyu-string-utils/health.svg)

```
[![Health](https://phpackages.com/badges/hatchyu-string-utils/health.svg)](https://phpackages.com/packages/hatchyu-string-utils)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
