2017 © Pedro Peláez
 

library manipulator

An OOP approach to string manipulation.

image

thestringler/manipulator

An OOP approach to string manipulation.

  • Friday, July 20, 2018
  • by SparksCoding
  • Repository
  • 3 Watchers
  • 33 Stars
  • 1,047 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 20 Versions
  • 14 % Grown

The README.md

The Stringler

A simple class to manipulate strings in an OO way. Inspired by Spatie's String. Just built this for fun. Hope you like it., (*1)

Install

Via composer:, (*2)

composer require thestringler/manipulator

Using Laravel? Checkout The Stringler Laravel Package., (*3)

Methods

append($string)

Manipulator::make('Freak')->append(' Out!');
// Freak Out!

camelToSnake

Manipulator::make('camelCase')->camelToSnake();
// camel_case

camelToClass

Manipulator::make('className')->camelToClass();
// ClassName

capitalize

Manipulator::make('hello')->capitalize();
// Hello

capitalizeEach

Manipulator::make('i like toast!')->capitalizeEach();
// I Like Toast!

custom

Manipulator::make('Some String')->custom(function ($string) {
    // This is just a sample, this can be achieved with existing methods,
    // But you can do whatever string manipulation you want here.
    return ucfirst(strtolower($string));
});
// Some string

eachCharacter($closure)

Manipulator::make('hello')->eachCharacter(function($char) {
    return strtoupper($char);
});
// HELLO

eachWord($closure, $preserveSpaces = false)

Manipulator::make('hello moto')->eachWord(function($word) {
    return strrev($word);
});
// ollehotom

Manipulator::make('hello moto')->eachWord(function($word) {
    return strrev($word);
}, true);
// olleh otom

getPossessive

Manipulator::make('Bob')->getPossessive();
// Bob's
Manipulator::make('Silas')->getPossessive();
// Silas'

htmlEntities($flags = ENT_HTML5, $encoding = 'UTF-8', $doubleEncode = true)

Manipulator::make('&')->htmlEntities();
// &

htmlEntitiesDecode($flags = ENT_HTML5, $encoding = 'UTF-8')

Manipulator::make('&')->htmlEntitiesDecode();
// &

htmlSpecialCharacters($flags = ENT_HTML5, $encoding = 'UTF-8', $doubleEncode = true)

Manipulator::make('&<>')->htmlSpecialCharacters();
// &amp;&lt;&gt;

lowercaseFirst

Manipulator::make('HELLO')->lowercaseFirst();
// hELLO

make($string)

// Named constructor
Manipulator::make('string');

pad($length, $string, $type = null)

Manipulator::make('Hello')->pad(2, '!!', STR_PAD_RIGHT);
// Hello!!

prepend($string)

Manipulator::make('is the one.')->prepend('Neo ');
// Neo is the one.

pluralize($items = null)

Manipulator::make('Potato')->pluralize();
// Potatoes

You can optionally pass an array or numeric value to pluaralize to determine if the given string should be pluaralized., (*4)

$dogs = ['Zoe', 'Spot', 'Pickles'];
Manipulator::make('Dog')->pluralize($dogs);
// Dogs

$cats = ['Whiskers'];
Manipulator::make('Cat')->pluralize($cats);
// Cat

nthCharacter($nth, $closure)

Manipulator::make('Wordpress')->nthCharacter(5, function($character) {
    return mb_strtoupper($character);
});
// WordPress

nthWord($nth, $closure, $preserveSpaces = true)

Manipulator::make('Oh hello there!')->nthWord(2, function($word) {
    return mb_strtoupper($word);
});
// Oh HELLO there!

remove($string, $caseSensitive = true)

Manipulator::make('Dog Gone')->remove('Gone');
// Dog

removeSpecialCharacters($exceptions = [])

Manipulator::make('Hello!!')->removeSpecialCharacters();
// Hello
Manipulator::make('Hello!!')->removeSpecialCharacters(['!']);
// Hello!!

repeat($multiplier = 1)

Manipulator::make('la')->repeat(3);
// lalala

replace($find, $replace = '', $caseSensitive = true)

Manipulator::make('Pickles are good.')->replace('good', 'terrible');
// Pickles are terrible.

reverse

Manipulator::make('Whoa!')->reverse();
// !aohW

snakeToCamel

Manipulator::make('snake_case')->snakeToCamel();
// snakeCase

snakeToClass

Manipulator::make('class_name')->snakeToClass();
// ClassName

stripTags($allowed = '')

Manipulator::make('<i>Hello</i>')->stripTags();
// Hello

toCamelCase

Manipulator::make('camel case')->toCamelCase();
// camelCase

toL33t

Manipulator::make('Hack The Planet!')->toL33t();
// (-)@{|< +/-/€ |O7@|\|€][!

toLower

Manipulator::make('LOWER')->toLower();
// lower

toSlug

Manipulator::make('This is a slug!')->toSlug();
// this-is-a-slug

toSnakeCase

Manipulator::make('snake case')->toSnakeCase();
// snake_case

toString

This method just returns the string., (*5)

toUpper

Manipulator::make('upper')->toUpper();
// UPPER

trim

Manipulator::make('  trimmed  ')->trim();
// trimmed

trimBeginning

Manipulator::make('  trimmed')->trimBeginning();
// trimmed

trimEnd

Manipulator::make('trimmed  ')->trimEnd();
// trimmed

truncate($length = 100, $append = '...')

Manipulator::make('This is a sentence and will be truncated.')->truncate(10, '...');
// This is a ...

urlDecode

Manipulator::make('hello%21')->urlDecode();
// hello!

urlEncode

Manipulator::make('hello!')->urlEncode();
// hello%21

Chainable

All of these methods (minus toString) can be chained., (*6)

Manipulator::make('hello')->toUpper()->reverse();
// OLLEH

Contribute

Contributions are very welcome!, (*7)

  1. Follow the PSR-2 Standard
  2. Send a pull request.

That's pretty much it!, (*8)

The Versions

20/07 2018

dev-master

9999999-dev

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

20/07 2018

v2.2.0

2.2.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

29/07 2017

v2.1.0

2.1.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

30/01 2017

v2.0.0

2.0.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

11/01 2017

dev-l33t

dev-l33t

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

11/01 2017

v1.3.0

1.3.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

10/01 2017

v1.2.0

1.2.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

08/08 2016

v1.1.0

1.1.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

07/08 2016

v1.0.1

1.0.1.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

07/08 2016

v1.0.0

1.0.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

03/08 2016

v0.8.0

0.8.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

01/08 2016

v0.7.0

0.7.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

31/07 2016

v0.6.0

0.6.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

24/07 2016

v0.5.1

0.5.1.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

07/07 2016

v0.5.0

0.5.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Sparks

06/07 2016

v0.4.0

0.4.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

by Matt Sparks

06/07 2016

v0.3.0

0.3.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

by Matt Sparks

03/07 2016

v0.2.0

0.2.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

by Matt Sparks

01/07 2016

v0.1.0

0.1.0.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

by Matt Sparks

30/06 2016

v0.0.1

0.0.1.0

An OOP approach to string manipulation.

  Sources   Download

MIT

The Requires

 

by Matt Sparks