2017 © Pedro Peláez
 

library strings

Strings library

image

vantoozz/strings

Strings library

  • Thursday, November 9, 2017
  • by vantoozz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • Shell
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Strings

True OOP library for strings manipulation, (*1)

Build Status Coverage Status Codacy Badge Packagist, (*2)

The goal of the library is providing an OOP way for strings manipulations. It works with any object implementing Stringable interface. https://wiki.php.net/rfc/stringable., (*3)

Setup

Just run, (*4)

composer require vantoozz/strings

Transformations

<?php declare(strict_types=1);

use Vantoozz\Strings\Transforms\Acronym;
use Vantoozz\Strings\Transforms\CaseToggled;
use Vantoozz\Strings\Transforms\Reversed;
use Vantoozz\Strings\Transforms\SnakeCased;

use function Vantoozz\Strings\str;

require_once __DIR__ . '/vendor/autoload.php';

$string = str('PHP: Hypertext Preprocessor');

echo new Acronym($string) . PHP_EOL;
echo new CaseToggled($string) . PHP_EOL;
echo new Reversed($string) . PHP_EOL;
echo new SnakeCased($string) . PHP_EOL;

Will output, (*5)

PHP
php: hYPERTEXT pREPROCESSOR
rossecorperP txetrepyH :PHP
p_h_p:_hypertext_preprocessor

Available transformations

  • Acronym
  • CamelCased
  • CaseToggled
  • KebabCased
  • LowerCased
  • PascalCased
  • Reversed
  • SentenceCased
  • SnakeCased
  • TitleCased
  • UpperCased

Joins

<?php declare(strict_types=1);

use Vantoozz\Strings\Joins\EndingWith;
use Vantoozz\Strings\Joins\Joined;
use Vantoozz\Strings\Joins\StartingWith;

use function Vantoozz\Strings\str;

require_once __DIR__ . '/vendor/autoload.php';

$one = str('aabbc');
$two = str('ccddaa');

echo new Joined($one, $two) . PHP_EOL;
echo new EndingWith($one, $two) . PHP_EOL;
echo new StartingWith($one, $two) . PHP_EOL;

Will output, (*6)

aabbcccddaa
aabbccddaa
ccddaabbc

Available joins

  • Joined
  • StartingWith
  • EndingWith

Formats

<?php declare(strict_types=1);

use Vantoozz\Strings\Exceptions\InvalidFormatException;
use Vantoozz\Strings\Formats\Email;

use function Vantoozz\Strings\str;

require_once __DIR__ . '/vendor/autoload.php';


try {
    echo new Email(str('user@example.com')) . PHP_EOL;
} catch (InvalidFormatException $e) {
    echo $e->getMessage() . PHP_EOL;
}

try {
    echo new Email(str('user%example.com')) . PHP_EOL;
} catch (InvalidFormatException $e) {
    echo $e->getMessage() . PHP_EOL;
}

Will output, (*7)

user@example.com
Invalid format

Available formats

  • Email
  • Hostname
  • Ipv4
  • Ipv6
  • Mac
  • Sha1
  • Sha256
  • Url

Composition

<?php declare(strict_types=1);

use Vantoozz\Strings\Formats\Email;
use Vantoozz\Strings\Joins\EndingWith;
use Vantoozz\Strings\Transforms\CaseToggled;

use function Vantoozz\Strings\str;


require_once __DIR__ . '/vendor/autoload.php';

$username = str('User@');
$domain = str('@Example.Com');

echo new CaseToggled(new Email(new EndingWith($username, $domain))) . PHP_EOL;

Will output, (*8)

uSER@eXAMPLE.cOM

Testing

./vendor/bin/phpunit

The Versions