napse/string-utils
Composer 安装命令:
composer require napse/string-utils
包简介
Lightweight string casing conversions and semantic versioning for PHP
README 文档
README
Lightweight string casing conversions and semantic versioning for PHP.
Installation
composer require napse/string-utils
Requires PHP 8.2 or higher.
StringUtils
Converts strings between 12 casing formats:
| Method | Example Output |
|---|---|
toFlatCase('Hello World!') |
helloworld |
toKebabCase('Hello World!') |
hello-world |
toCamelCase('Hello World!') |
helloWorld |
toPascalCase('Hello World!') |
HelloWorld |
toSnakeCase('Hello World!') |
hello_world |
toConstantCase('Hello World!') |
HELLO_WORLD |
toCobolCase('Hello World!') |
HELLO-WORLD |
toTitleCase('Hello World!') |
Hello World |
toDotCase('Hello World!') |
hello.world |
toTrainCase('Hello World!') |
Hello-World |
toSlug('Café & Co!') |
cafe-co |
toAcronym('Hello World!') |
HW |
use Napse\StringUtils\StringUtils; echo StringUtils::toKebabCase('Hello World! 123'); // Output: hello-world-123 echo StringUtils::toSlug('Über uns! 🎉'); // Output: uber-uns
Version
Immutable semantic versioning value object with parsing, comparison, and modification.
Creating Versions
use Napse\StringUtils\Version; $version = new Version(1, 2, 3, 'beta', 'build123'); echo $version; // 1.2.3-beta+build123 $version = Version::fromString('2.1.0-beta+exp.sha.5114f85'); echo $version; // 2.1.0-beta+exp.sha.5114f85
Accessing Components
$version = new Version(1, 2, 3, 'alpha', 'build123'); $version->getMajor(); // 1 $version->getMinor(); // 2 $version->getPatch(); // 3 $version->getPreRelease(); // "alpha" $version->getBuildMetadata(); // "build123"
Incrementing
$version = new Version(1, 2, 3); echo $version->incrementMajor(); // 2.0.0 echo $version->incrementMinor(); // 1.3.0 echo $version->incrementPatch(); // 1.2.4
Immutable Modifications
$version = new Version(1, 0, 0); echo $version->withMajor(2); // 2.0.0 echo $version->withMinor(5); // 1.5.0 echo $version->withPatch(9); // 1.0.9 echo $version->withPreRelease('rc1'); // 1.0.0-rc1 echo $version->withBuildMetadata('b567'); // 1.0.0+b567
Comparing
$v1 = new Version(1, 2, 3); $v2 = new Version(1, 2, 4); $v1->compare($v2); // -1 ($v1 < $v2) $v2->compare($v1); // 1 ($v2 > $v1) $v3 = new Version(1, 2, 3); $v1->compare($v3); // 0 ($v1 == $v3)
Pre-release versions have lower precedence than the associated normal version (SemVer §11):
$alpha = Version::fromString('1.0.0-alpha'); $stable = new Version(1, 0, 0); $alpha->compare($stable); // -1 (alpha < stable)
Convenience Methods
$v1 = new Version(1, 0, 0); $v2 = new Version(2, 0, 0); $v1->equals($v2); // false $v1->lessThan($v2); // true $v1->greaterThan($v2); // false $v1->lessThanOrEqual($v2); // true $v1->greaterThanOrEqual($v2); // false $v1->isStable(); // true $beta = new Version(1, 0, 0, 'beta'); $beta->isStable(); // false
Emoji
Terminal-friendly emoji constants for CLI output.
| Constant | Emoji | Purpose |
|---|---|---|
CHECKMARK_OK |
✅ | Success |
CHECKMARK_NOK |
❌ | Failure |
WARNING |
⚠️ | Warnings |
INFO |
ℹ️ | Info messages |
ARROW_RIGHT |
➜ | Lists, steps |
ROCKET |
🚀 | Start/Deploy |
HOURGLASS |
⏳ | In progress |
LOCK |
🔒 | Security/Auth |
GEAR |
⚙️ | Configuration |
SPARKLE |
✨ | Success/New |
use Napse\StringUtils\Emoji; echo Emoji::CHECKMARK_OK . ' All tests passed'; // ✅ All tests passed echo Emoji::WARNING . ' Config missing'; // ⚠️ Config missing echo Emoji::ROCKET . ' Deploying...'; // 🚀 Deploying...
Testing
composer require --dev phpunit/phpunit vendor/bin/phpunit
Static Analysis
composer require --dev phpstan/phpstan vendor/bin/phpstan analyse
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This package is licensed under the MIT License.
napse/string-utils 适用场景与选型建议
napse/string-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「version」 「semver」 「utils」 「string」 「case-conversion」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 napse/string-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 napse/string-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 napse/string-utils 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
PHP Semantic Versioning Parser and Comparator
Versioning behaviour for eloquent models
n2n test utils
Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.
A decent, standards-compliant, Semantic Versioning (SemVer) parser and library
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-13