Simple library to handle words case transformation from array keys

Simple library to handle words case transformation from array keys

README

Build Status
Code Coverage
Code Quality
License MIT
Packagist

Simple library to handle words case transformation from array keys.

Installation

composer require deoliveiralucas/array-keys-case-transform

Usage

use ArrayKeysCaseTransformArrayKeys;

$input = [ 'first_key' => 'value' ];

print_r(ArrayKeys::toCamelCase($input));
/*
Output:
Array
(
    [firstKey] => value
)
*/

$input = [ 'firstKey' => 'value' ];

print_r(ArrayKeys::toSnakeCase($input));
/* 
Output:
Array
(
    [first_key] => value
)
*/

Custom format

use ArrayKeysCaseTransformArrayKeys;
use ArrayKeysCaseTransformTransformerAbstractTransformer;

$input = [ 'firstKey' => 'value' ];

$customTransform = new class extends AbstractTransformer {
    protected function format(string $key) : string {
        return str_replace('Key', 'CustomKey', $key);
    }
};

print_r(ArrayKeys::transform($customTransform, $input));
/* 
Output:
Array
(
    [firstCustomKey] => value
)
*/

Contributing

Please see CONTRIBUTING for details.

License

ArrayKeysCaseTransform is released under the MIT License. Please see License File for more information.

Source

Add a Comment

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *