anekdotes/support

Utility classes meant to facilitate object manipulation.

2.0.0 2021-11-23 21:36 UTC

This package is auto-updated.

Last update: 2024-10-24 03:37:38 UTC


README

Latest Stable Version Build Status License Total Downloads

Utility classes meant to facilitate object manipulation

Installation

Install via composer into your project:

composer require anekdotes/support

Usage

Use the class where ever you need it:

use Anekdotes\Support\Arr;

or

use Anekdotes\Support\Str;

or

use Anekdotes\Support\UUID;

or

use Anekdotes\Support\I18n;

Arr

Helper class which facilitates array manipulation.

Method sortByKey (*array, *string, enum)

Arr::sortByKey([['id' => 2],['id' => 1],['id' => 3]], 'id');
// [['id' => 1],['id' => 2],['id' => 3]]

Arr::sortByKey([['id' => 2],['id' => 1],['id' => 3]], 'id', SORT_DESC);
// [['id' => 3],['id' => 2],['id' => 1]]

Method get (*array, *string, string)

Arr::get(['id'=>1, 'title'=>'foo'], 'title');
// foo

//With default param if non is found
Arr::get(['id'=>1, 'title'=>'foo'], 'bar', 'toaster');
// toaster

Method getWhere (*array, *string, *string, string)

$dummy = [
    ['id' => 1, 'name' => 'Bell'],
    ['id' => 2, 'name' => 'Lani']
];
Arr::getWhere($dummy, 'name', 'Lani');
// ['id' => 2, 'name' => 'Lani']

Method exists (*string, *array)

Arr::exists('title', ['id'=>1, 'title'=>'foo']);
// true

Arr::exists('bar', ['id'=>1, 'title'=>'foo']);
// false

Method remove (*string, *array)

$dummy = ['id'=>1, 'title'=>'foo'];
Arr::remove('title', $dummy);
$dummy // ['id'=>1]

$dummy = ['id'=>1, 'title'=>'foo'];
Arr::remove('foo', $dummy);
$dummy // ['id'=>1, 'title'=>'foo']

Str

Contains helper functions used to manipulate strings.

Method startsWith (*string, *string)

Str::startsWith('foo', 'f');
// true

Method endsWith (*string, *string)

Str::endsWith('foo', 'o');
// true

Method split (*string, *string)

Str::split(',', '1,2,3,4,5');
// [1, 2, 3, 4, 5]

Method capitalize (*string)

Str::capitalize('foo');
// Foo

Method upper (*string)

Str::upper('foo');
// FOO

Method lower (*string)

Str::lower('FOO');
// foo

Method snakeCase (*string)

Str::snakeCase('étoile filante');
// etoile_filante

Method camelCase (*string)

Str::camelCase('foo bar');
// fooBar

Method contains (*string, *string)

Str::contains('foo', 'oo');
// true

Method studly (*string)

Str::studly('foo bar');
// FooBar

Method ascii (*string)

Str::ascii('étoile');
// etoile

Method slug (*string, string)

Str::slug('foo bar');
// foo-bar

Method random (*integer)

Str::random();
// random 16 characters string

Str::random(20);
// random 20 characters string

Method quickRandom (*integer)

Str::quickRandom();
// random quick 16 characters string

Str::quickRandom(20);
// random quick 20 characters string

Method replace (*string, *string, *string)

Str::replace('foo', 'oo', 'yy');
// fyy

Method regexResult ()

Str::regexResult('/([\w]+)/', 'foo bar', 0);
// ['foo', 'bar']