Skip to content

Commit

Permalink
Simplify method name
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Jun 27, 2021
1 parent 91f1536 commit 75b898f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 88 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ use Realodix\ChangeCase\ChangeCase;
```php
$cc = new ChangeCase;

$cc->camelCase('test string');
$cc->camel('test string');
// 'testString'

$cc->camelCase('1twoThree');
$cc->camel('1twoThree');
// '1twoThree'
$cc->camelCase('1twoThree', ['separateNumber' => true]);
$cc->camel('1twoThree', ['separateNumber' => true]);
// '1TwoThree'
```

Expand All @@ -68,7 +68,7 @@ $cc->camelCase('1twoThree', ['separateNumber' => true]);
```php
$cc = new ChangeCase;
$cc->capitalCase('test string');
$cc->capital('test string');
// 'Test String'
```

Expand All @@ -78,7 +78,7 @@ $cc->capitalCase('test string');
```php
$cc = new ChangeCase;
$cc->constantCase('test string');
$cc->constant('test string');
// 'TEST_STRING'
```

Expand All @@ -90,7 +90,7 @@ $cc->constantCase('test string');

```php
$cc = new ChangeCase;
$cc->dotCase('test string');
$cc->dot('test string');
// 'test.string'
```

Expand All @@ -100,7 +100,7 @@ $cc->dotCase('test string');
```php
$cc = new ChangeCase;
$cc->headerCase('test string');
$cc->header('test string');
// 'Test-String'
```

Expand All @@ -113,15 +113,15 @@ $cc->headerCase('test string');
```php
$cc = new ChangeCase;

$cc->noCase('testString');
$cc->no('testString');
// 'test string'

$cc->noCase('minifyURLs', ['delimiter' => '-']);
$cc->no('minifyURLs', ['delimiter' => '-']);
// 'minify-urls'

$cc->noCase('Foo123Bar')
$cc->no('Foo123Bar')
// foo123 bar
$cc->noCase('Foo123Bar', ['separateNumber' => true])
$cc->no('Foo123Bar', ['separateNumber' => true])
// foo 123 bar
```

Expand All @@ -133,7 +133,7 @@ $cc->noCase('Foo123Bar', ['separateNumber' => true])

```php
$cc = new ChangeCase;
$cc->pascalCase('test string');
$cc->pascal('test string');
// 'TestString'
```

Expand All @@ -143,7 +143,7 @@ $cc->pascalCase('test string');
```php
$cc = new ChangeCase;
$cc->pathCase('test string');
$cc->path('test string');
// 'test/string'
```

Expand All @@ -153,7 +153,7 @@ $cc->pathCase('test string');
```php
$cc = new ChangeCase;
$cc->sentenceCase('testString');
$cc->sentence('testString');
// 'Test string'
```

Expand All @@ -166,12 +166,12 @@ $cc->sentenceCase('testString');
```php
$cc = new ChangeCase;

$cc->snakeCase('test string');
$cc->snake('test string');
// 'test_string'

$cc->snakeCase('Foo123Bar');
$cc->snake('Foo123Bar');
// 'foo123_bar'
$cc->snakeCase('Foo123Bar', ['separateNumber' => true]);
$cc->snake('Foo123Bar', ['separateNumber' => true]);
// 'foo_123_bar'
```

Expand All @@ -184,12 +184,12 @@ $cc->snakeCase('Foo123Bar', ['separateNumber' => true]);
```php
$cc = new ChangeCase;

$cc->spinalCase('test string');
$cc->spinal('test string');
// 'test-string'

$cc->spinalCase('Foo123Bar');
$cc->spinal('Foo123Bar');
// 'foo123-bar'
$cc->spinalCase('Foo123Bar', ['separateNumber' => true]);
$cc->spinal('Foo123Bar', ['separateNumber' => true]);
// 'foo-123-bar'
```

Expand All @@ -200,19 +200,19 @@ $cc->spinalCase('Foo123Bar', ['separateNumber' => true]);
```php
$cc = new ChangeCase;
$cc->swapCase('Test String');
$cc->swap('Test String');
// 'tEST sTRING'
```

#### titleCase

> Transform a string into title case following English rules.
`titleCase(string $string, array $ignore = [])`
`title(string $string, array $ignore = [])`

```php
$cc = new ChangeCase;
$cc->titleCase('a simple test');
$cc->title('a simple test');
// 'A Simple Test'
```

Expand Down
46 changes: 23 additions & 23 deletions src/ChangeCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ChangeCase
*
* @return string
*/
public function noCase(string $value, array $opt = []): string
public function no(string $value, array $opt = []): string
{
// Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case")
$splitRegexp = ['/([a-z0-9])([A-Z])/', '/([A-Z])([A-Z][a-z])/'];
Expand Down Expand Up @@ -72,9 +72,9 @@ public function noCase(string $value, array $opt = []): string
*
* @return string
*/
public function camelCase(string $string, array $opt = []): string
public function camel(string $string, array $opt = []): string
{
return UTF8::lcfirst($this->pascalCase($string, $opt));
return UTF8::lcfirst($this->pascal($string, $opt));
}

/**
Expand All @@ -84,14 +84,14 @@ public function camelCase(string $string, array $opt = []): string
*
* @return string
*/
public function capitalCase(string $string): string
public function capital(string $string): string
{
return preg_replace_callback(
'/^.| ./u',
function (array $matches) {
return strtoupper($matches[0]);
},
$this->noCase($string)
$this->no($string)
);
}

Expand All @@ -102,9 +102,9 @@ function (array $matches) {
*
* @return string
*/
public function constantCase(string $string): string
public function constant(string $string): string
{
return strtoupper($this->snakeCase($string));
return strtoupper($this->snake($string));
}

/**
Expand All @@ -115,9 +115,9 @@ public function constantCase(string $string): string
*
* @return string
*/
public function dotCase(string $string, array $opt = []): string
public function dot(string $string, array $opt = []): string
{
return $this->noCase($string, $opt += ['delimiter' => '.']);
return $this->no($string, $opt += ['delimiter' => '.']);
}

/**
Expand All @@ -127,14 +127,14 @@ public function dotCase(string $string, array $opt = []): string
*
* @return string
*/
public function headerCase(string $string): string
public function header(string $string): string
{
return preg_replace_callback(
'/^.|-./u',
function (array $matches) {
return strtoupper($matches[0]);
},
$this->noCase($string, ['delimiter' => '-'])
$this->no($string, ['delimiter' => '-'])
);
}

Expand All @@ -146,9 +146,9 @@ function (array $matches) {
*
* @return string
*/
public function pascalCase(string $string, array $opt = []): string
public function pascal(string $string, array $opt = []): string
{
$value = UTF8::ucwords($this->noCase($string, $opt));
$value = UTF8::ucwords($this->no($string, $opt));

return UTF8::str_ireplace(' ', '', $value);
}
Expand All @@ -160,9 +160,9 @@ public function pascalCase(string $string, array $opt = []): string
*
* @return string
*/
public function pathCase(string $string): string
public function path(string $string): string
{
return $this->noCase($string, ['delimiter' => '/']);
return $this->no($string, ['delimiter' => '/']);
}

/**
Expand All @@ -172,9 +172,9 @@ public function pathCase(string $string): string
*
* @return string
*/
public function sentenceCase(string $string): string
public function sentence(string $string): string
{
return UTF8::ucfirst($this->noCase($string));
return UTF8::ucfirst($this->no($string));
}

/**
Expand All @@ -185,11 +185,11 @@ public function sentenceCase(string $string): string
*
* @return string
*/
public function snakeCase(string $string, array $opt = []): string
public function snake(string $string, array $opt = []): string
{
$stripRegexp = '/(?!^_*)[^a-zA-Z0-9]+/i';

return $this->noCase(
return $this->no(
$string,
$opt += ['delimiter' => '_', 'stripRegexp' => $stripRegexp]
);
Expand All @@ -203,9 +203,9 @@ public function snakeCase(string $string, array $opt = []): string
*
* @return string
*/
public function spinalCase(string $string, array $opt = []): string
public function spinal(string $string, array $opt = []): string
{
return $this->noCase($string, $opt += ['delimiter' => '-']);
return $this->no($string, $opt += ['delimiter' => '-']);
}

/**
Expand All @@ -216,7 +216,7 @@ public function spinalCase(string $string, array $opt = []): string
*
* @return string
*/
public function swapCase(string $string): string
public function swap(string $string): string
{
return strtolower($string) ^ strtoupper($string) ^ $string;
}
Expand All @@ -229,7 +229,7 @@ public function swapCase(string $string): string
*
* @return string
*/
public function titleCase(string $string, array $ignore = []): string
public function title(string $string, array $ignore = []): string
{
$smallWords = ['nor', 'over', 'upon'];

Expand Down
Loading

0 comments on commit 75b898f

Please sign in to comment.