ykw/cruet
Composer 安装命令:
composer require ykw/cruet
包简介
PHP port of the Rust cruet library case conversion functions. Provides camelCase, snake_case, kebab-case, PascalCase and other case transformations.
关键字:
README 文档
README
A fast, lightweight PHP library for string case conversions, based on the Rust cruet library.
Provides clean, efficient case conversions with a simple API.
Features
- 5 Case Conversions: camelCase, PascalCase, snake_case, SCREAMING_SNAKE_CASE, kebab-case
- Format Detection: Identify string formats programmatically
- Fluent Interface: Chain operations for complex transformations
- High Performance: Character-by-character processing with intelligent boundary detection
- No Dependencies: Pure PHP implementation, no external libraries required
Installation
composer require ykw/cruet
Or add to your composer.json:
{
"require": {
"ykw/cruet": "^1.0"
}
}
Quick Start
use Ykw\Cruet\Inflector; // Case conversions echo Inflector::toCamelCase('user_account'); // userAccount echo Inflector::toPascalCase('user_account'); // UserAccount echo Inflector::toSnakeCase('UserAccount'); // user_account echo Inflector::toScreamingSnakeCase('UserAccount'); // USER_ACCOUNT echo Inflector::toKebabCase('UserAccount'); // user-account // Format detection var_dump(Inflector::isCamelCase('userAccount')); // true var_dump(Inflector::isPascalCase('UserAccount')); // true var_dump(Inflector::isSnakeCase('user_account')); // true // Fluent interface $result = Inflector::convert('user_account') ->pascalCase() // UserAccount ->snakeCase() // user_account ->screamingSnakeCase() // USER_ACCOUNT ->get(); echo $result; // USER_ACCOUNT
Usage Examples
Case Conversions
use Ykw\Cruet\Inflector; $input = 'user_profile_settings'; // All available case conversions echo Inflector::toCamelCase($input); // userProfileSettings echo Inflector::toPascalCase($input); // UserProfileSettings echo Inflector::toSnakeCase($input); // user_profile_settings echo Inflector::toScreamingSnakeCase($input); // USER_PROFILE_SETTINGS echo Inflector::toKebabCase($input); // user-profile-settings
Format Detection
// Check string formats var_dump(Inflector::isCamelCase('userAccount')); // true var_dump(Inflector::isPascalCase('UserAccount')); // true var_dump(Inflector::isSnakeCase('user_account')); // true var_dump(Inflector::isScreamingSnakeCase('USER_ACCOUNT')); // true var_dump(Inflector::isKebabCase('user-account')); // true
Fluent Interface
Chain multiple operations together:
use Ykw\Cruet\Inflector; // Complex transformation chains $result = Inflector::convert('user_account') ->pascalCase() // UserAccount ->snakeCase() // user_account ->screamingSnakeCase() // USER_ACCOUNT ->get(); echo $result; // USER_ACCOUNT // Another example $result = Inflector::convert('AdminUser') ->snakeCase() // admin_user ->kebabCase() // admin-user ->get(); echo $result; // admin-user
API Reference
Static Case Conversion Methods
Inflector::toCamelCase(string $input): stringInflector::toPascalCase(string $input): stringInflector::toSnakeCase(string $input): stringInflector::toScreamingSnakeCase(string $input): stringInflector::toKebabCase(string $input): string
Static Format Detection Methods
Inflector::isCamelCase(string $input): boolInflector::isPascalCase(string $input): boolInflector::isSnakeCase(string $input): boolInflector::isScreamingSnakeCase(string $input): boolInflector::isKebabCase(string $input): bool
Fluent Interface
Inflector::convert(string $input): Inflector- Create fluent chain->camelCase(): Inflector- Convert to camelCase->pascalCase(): Inflector- Convert to PascalCase->snakeCase(): Inflector- Convert to snake_case->screamingSnakeCase(): Inflector- Convert to SCREAMING_SNAKE_CASE->kebabCase(): Inflector- Convert to kebab-case->get(): string- Get final result
Requirements
- PHP 8.4 or higher
- No external dependencies
Testing
Run the test suite:
composer test
Or run PHPUnit directly:
vendor/bin/phpunit
Generate test coverage:
composer run test-coverage
Code Quality
This project uses Mago for code formatting, linting, and static analysis:
# Format code mago format # Run linter mago lint # Static analysis mago analyze # All quality checks mago format && mago lint && mago analyze
Code quality checks run automatically via GitHub Actions on every push and pull request.
Contributing
Contributions are welcome! Please ensure:
- Test Coverage: Add tests for new functionality
- Documentation: Update README for new features
- Code Style: Follow PSR-12 coding standards
License
MIT License - see LICENSE file for details.
Credits
Based on the Rust cruet library by Chris Learn.
ykw/cruet 适用场景与选型建议
ykw/cruet 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「conversion」 「string」 「case」 「camelcase」 「snake_case」 「kebab-case」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ykw/cruet 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ykw/cruet 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ykw/cruet 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
A library that provides a simple infrastructure to create your own converters and to perform any conversion you want
Class to store and access data in a case-insensitive fashion, while maintaining the integrity and functionality of a regular array.
Encode integer IDs using a preset or customized symbol set
base62 encoder and decoder also for big numbers with Laravel integration
Compatibility layer for emulating enumerations in PHP < 8.1 and native enumerations in PHP >= 8.1
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-06