Package Data | |
---|---|
Maintainer Username: | SparksCoding |
Maintainer Contact: | matt@sparkscoding.com (Matt Sparks) |
Package Create Date: | 2016-07-15 |
Package Last Update: | 2017-08-01 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:03:06 |
Package Statistics | |
---|---|
Total Downloads: | 4,888 |
Monthly Downloads: | 16 |
Daily Downloads: | 0 |
Total Stars: | 31 |
Total Watchers: | 4 |
Total Forks: | 8 |
Total Open Issues: | 1 |
A Laravel package for The Stringler, a string manipulation class.
Compsoser:
composer require thestringler-laravel/manipulator
After composer has done its thing, add the package service provider to the array in /config/app.php
:
TheStringlerLaravel\Manipulator\ManipulatorServiceProvider::class
Then add the facade to the aliases array, also in config/app.php
:
'Manipulator' => TheStringlerLaravel\Manipulator\ManipulatorFacade::class,
Helper function:
$string = manipulate('hello')->toUpper();
manipulate('Freak')->append(' Out!');
// Freak Out!
manipulate('camelCase')->camelToSnake();
// camel_case
manipulate('className')->camelToClass();
// ClassName
manipulate('hello')->capitalize();
// Hello
manipulate('i like toast!')->capitalizeEach();
// I Like Toast!
manipulate('hello')->eachCharacter(function($char) {
return strtoupper($char);
});
// HELLO
manipulate('hello moto')->eachWord(function($word) {
return strrev($word);
});
// ollehotom
manipulate('hello moto')->eachWord(function($word) {
return strrev($word);
}, true);
// olleh otom
manipulate('Bob')->getPossessive();
// Bob's
manipulate('Silas')->getPossessive();
// Silas'
manipulate('&')->htmlEntities();
// &
manipulate('&')->htmlEntitiesDecode();
// &
manipulate('&<>')->htmlSpecialCharacters();
// &<>
manipulate('HELLO')->lowercaseFirst();
// hELLO
manipulate('Hello')->pad(2, '!!', STR_PAD_RIGHT);
// Hello!!
manipulate('is the one.')->prepend('Neo ');
// Neo is the one.
manipulate('Potato')->pluralize();
// Potatoes
You can optionally pass an array or numeric value to pluaralize
to determine if the given string should be pluaralized.
$dogs = ['Zoe', 'Spot', 'Pickles'];
manipulate('Dog')->pluralize($dogs);
// Dogs
$cats = ['Whiskers'];
manipulate('Cat')->pluralize($cats);
// Cat
manipulate('Wordpress')->nthCharacter(5, function($character) {
return mb_strtoupper($character);
});
// WordPress
manipulate('Oh hello there!')->nthWord(2, function($word) {
return mb_strtoupper($word);
});
// Oh HELLO there!
manipulate('Dog Gone')->remove('Gone');
// Dog
manipulate('Hello!!')->removeSpecialCharacters();
// Hello
manipulate('Hello!!')->removeSpecialCharacters(['!']);
// Hello!!
manipulate('la')->repeat(3);
// lalala
manipulate('Pickles are good.')->replace('good', 'terrible');
// Pickles are terrible.
manipulate('Whoa!')->reverse();
// !aohW
manipulate('snake_case')->snakeToCamel();
// snakeCase
manipulate('class_name')->snakeToClass();
// ClassName
manipulate('<i>Hello</i>')->stripTags();
// Hello
manipulate('camel case')->toCamelCase();
// camelCase
manipulate('Hack The Planet!')->toL33t();
// (-)@{|< +/-/€ |O7@|\|€][!
manipulate('LOWER')->toLower();
// lower
manipulate('This is a slug!')->toSlug();
// this-is-a-slug
manipulate('snake case')->toSnakeCase();
// snake_case
This method just returns the string.
manipulate('upper')->toUpper();
// UPPER
manipulate(' trimmed ')->trim();
// trimmed
manipulate(' trimmed')->trimBeginning();
// trimmed
manipulate('trimmed ')->trimEnd();
// trimmed
manipulate('This is a sentence and will be truncated.')->truncate(10, '...');
// This is a ...
manipulate('hello%21')->urlDecode();
// hello!
manipulate('hello!')->urlEncode();
// hello%21
All of these methods (minus toString
) can be chained.
manipulate('hello')->toUpper()->reverse();
// OLLEH