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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4