neoan3 common string operations helper class

2.1.0 2021-10-19 19:17 UTC

README

Build Status Test Coverage Maintainability

Ops provides valuable string helpers for everyday use ranging from simple templating to encryption & hash generation.

This library facilitates

Templating

Templating has grown into a dedicated repository and is now available at neoan3-apps/template. For the time being, Ops will inherit functions as if it where part of Ops. However, in new projects we recommend using "Template" instead of "Ops" to trigger templating functionality.

String manipulation

serialize($any)

Serializes strings, arrays and objects (url save).

unserialize($serializedString)

Reverts serialize()

pin($length)

Returns a random integer in the requested length.

flattenArray($array)

Converts deep arrays to keyed arrays of one level to resemble JS-object selection.

$original = ['items' => ['name' => 'sam']];
$flat = Ops::flattenArray($original);
/*
* output $flat: ['items.name' => 'sam'];
* 
*/

randomString($length = 10)

Returns a random string (with or without special characters) in the requested length.

encrypt($string, $key)

Encrypts a string with a symmetric AES-256 algorithm.

decrypt($encrypted, $key)

Decrypts a string with a symmetric AES-256 algorithm.

extrude($targets,$array)

Returns selected part of $array.

$userInput = [
    'id'=>1,
    'name'=>'sam',
    'random'=>'value'
];
$clean = Ops::extrude(['id','name'],$userInput);
// Output $clean: ['id'=>1,'name'=>'sam']

toPascalCase($string)

Converts spaces, snake-, kebab- or camelCase to PascalCase

toCamelCase($string)

Converts spaces, snake-, kebab- or PascalCase to camelCase

toSnakeCase($string)

Converts spaces, camel-, kebab- or PascalCase to snake_case

toKebabCase($string)

Converts spaces, camel-, snake- or PascalCase to kebab-case