Skip to content

Commit

Permalink
Add options to header case
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Jun 27, 2021
1 parent 8c01cea commit 5120de7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ $cc->dotCase('test string');

> Transform into a dash separated string of capitalized words.
💡 Support [options](#options)

```php
$cc = new ChangeCase;
$cc->headerCase('test string');
Expand Down
5 changes: 3 additions & 2 deletions src/ChangeCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,18 @@ public function dotCase(string $string, array $opt = []): string
* Transform into a dash separated string of capitalized words.
*
* @param string $string
* @param array $opt
*
* @return string
*/
public function headerCase(string $string): string
public function headerCase(string $string, array $opt = []): string
{
return preg_replace_callback(
'/^.|-./u',
function (array $matches) {
return strtoupper($matches[0]);
},
$this->noCase($string, ['delimiter' => '-'])
$this->noCase($string, $opt += ['delimiter' => '-'])
);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/ChangeCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ public function headerCase($expected, $actual)
$this->assertSame($expected, $this->cc->headerCase($actual));
}

/** @test */
public function headerCaseWithOpt()
{
$options = ['separateNumber' => true];

$this->assertSame(
'Test-V-2',
$this->cc->headerCase('TestV2', $options)
);
$this->assertSame(
'Foo-123-Bar',
$this->cc->headerCase('Foo123Bar', $options)
);
}

/**
* @test
* @dataProvider pascalCaseProvider
Expand Down

0 comments on commit 5120de7

Please sign in to comment.