mattketmo/camel

处理单词大小写转换的小型库

v1.1.0 2015-05-13 13:51 UTC

This package is auto-updated.

Last update: 2024-09-05 19:37:22 UTC


README

Build status... Code quality... License MIT Packagist

处理单词大小写转换的小型库。

主要思路是将给定的单词拆分为多个单词,并以另一种格式组装它们。

示例: camelCase => [camel, Case] => camel_case

安装

composer require mattketmo/camel

使用

<?php

require __DIR__.'/vendor/autoload.php';

use Camel\CaseTransformer;
use Camel\Format;

$transformer1 = new CaseTransformer(new Format\SnakeCase, new Format\CamelCase);
$transformer2 = new CaseTransformer(new Format\CamelCase, new Format\ScreamingSnakeCase);

echo $transformer1->transform('hello_world'); // helloWorld
echo $transformer2->transform('helloWorld');  // HELLO_WORLD

支持的格式

  • camelCase
  • StudlyCaps
  • snake_case
  • SCREAMING_SNAKE_CASE
  • spinal-case

单元测试

通过 Composer 安装 phpunit

composer install

安装完成后,运行以下命令

vendor/bin/phpunit

许可证

Camel 采用 MIT 许可证发布。有关详细信息,请参阅附带许可证文件