Skip to content

Commit b9d31cf

Browse files
committed
toCamelCase function added
1 parent c384936 commit b9d31cf

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/Ease/Functions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,4 +589,14 @@ public static function isJson(?string $json, int $depth = 512, int $flags = 0):
589589

590590
return $isJson;
591591
}
592+
593+
/**
594+
* Convert a string to camelCase.
595+
*
596+
* @param string $string The string to convert
597+
*/
598+
public static function toCamelCase(string $string): string
599+
{
600+
return lcfirst(str_replace(' ', '', ucwords(str_replace(['-', '_', ':'], ' ', $string))));
601+
}
592602
}

tests/src/Ease/FunctionsTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,13 @@ public function testisJson(): void
317317
$this->assertFalse(Functions::isJson('{"key":value}'));
318318
$this->assertFalse(Functions::isJson('{"key":1.2.3}'));
319319
}
320+
321+
public function testtoCamelCase(): void
322+
{
323+
$this->assertEquals('testTest', Functions::toCamelCase('test_test'));
324+
$this->assertEquals('testTest', Functions::toCamelCase('test-test'));
325+
$this->assertEquals('testTest', Functions::toCamelCase('test test'));
326+
$this->assertEquals('testTestTest', Functions::toCamelCase('test test test'));
327+
$this->assertEquals('testTestTest', Functions::toCamelCase('test test-test'));
328+
}
320329
}

0 commit comments

Comments
 (0)