Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Case Converter Laravel Package

jawira/case-converter

Convert strings between common case styles (camelCase, snake_case, kebab-case, PascalCase, etc.) with a simple PHP API. Handy for slugs, variable naming, and text normalization, supporting robust Unicode-aware conversions and formatting options.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via Composer:

composer require jawira/case-converter

Start by converting simple strings using the CaseConverter facade or class. The most common first use case is normalizing user input or API payloads into snake_case or camelCase for consistent internal handling:

use Jawira\CaseConverter\CaseConverter;

$converter = new CaseConverter();
$camel = $converter->toCamelCase('user_first_name');     // 'userFirstName'
$snake = $converter->toSnakeCase('UserName');            // 'user_name'
$kebab = $converter->toKebabCase('fileNameWithNumbers'); // 'file-name-with-numbers'

Check the README (even without a public repo link, the package docs are typically embedded or linked in Packagist).

Implementation Patterns

  • Input Sanitization: Wrap form or API input with conversion to a canonical format (e.g., toSnakeCase()) before processing to unify data structures across services.
  • Dynamic Property Mapping: When hydrating objects from external data (e.g., JSON responses with inconsistent casing), use toCamelCase() or toPascalCase() to match PHP property naming standards.
  • Language/Adapter Interoperability: Normalize strings when interfacing with systems expecting specific conventions (e.g., toSnakeCase() for database columns, toKebabCase() for URL slugs).
  • Middleware for Header Keys: In HTTP middleware, convert header keys to a consistent convention like toKebabCase() if downstream services require it.
  • Testing Helpers: Use CaseConverter in test fixtures to generate predictable variable names or identifiers across multiple conventions.

Gotchas and Tips

  • Acronym Handling: The package handles acronyms intelligently in most cases (e.g., toSnakeCase('HTTPRequest')'http_request'), but Cobol case and Ada case may behave unexpectedly with irregular inputs—always validate edge cases like 'APIV2'.
  • Performance: Avoid excessive conversions in tight loops; cache intermediate results when反复 processing the same strings.
  • Case Insensitivity: All methods are case-insensitive for input but output strictly follows the target convention. Use toLower() or toUpper() to pre-normalize input if needed.
  • Extension Points: Though the package doesn’t support custom converters directly, you can wrap it in a service class to enforce project-specific rules (e.g., force 'uuid''UUID' after conversion).
  • Debugging Tips: If conversion fails or returns empty strings, verify input is non-empty and UTF-8 compliant. Invalid multibyte sequences can cause silent failures.
  • Release Stability: The last release date (2025-06-13) suggests future-dated—verify actual repo status; if real, this indicates active maintenance. Check for breaking changes in patch versions by pinning minor versions (~4.0).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope