All Projects → mattsparks → the-stringler

mattsparks / the-stringler

Licence: MIT license
An OOP approach to string manipulation.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to the-stringler

python-string-utils
A handy Python library to validate, manipulate and generate strings
Stars: ✭ 47 (+30.56%)
Mutual labels:  strings, string-manipulation, manipulating-strings
Cuerdas
String manipulation library for Clojure(Script)
Stars: ✭ 272 (+655.56%)
Mutual labels:  strings, string-manipulation
Twine
String manipulation, leveled up!
Stars: ✭ 496 (+1277.78%)
Mutual labels:  strings, string-manipulation
Mightystring
Making Ruby Strings Powerful
Stars: ✭ 28 (-22.22%)
Mutual labels:  strings, string-manipulation
bigint
bigint is a C++ library which can handle Very very Big Integers. It can calculate factorial of 1000000... it can go any big. It may be useful in Competitive Coding and Scientific Calculations which deals with very very large Integers. It can also be used in Decryption process. It has many inbuilt functions which can be very useful.
Stars: ✭ 34 (-5.56%)
Mutual labels:  strings, string-manipulation
string theory
Flexible modern C++ string library with type-safe formatting
Stars: ✭ 32 (-11.11%)
Mutual labels:  strings, string-manipulation
Chr
🔤 Lightweight R package for manipulating [string] characters
Stars: ✭ 18 (-50%)
Mutual labels:  strings, string-manipulation
Cracking The Coding Interview
Solutions for Cracking the Coding Interview - 6th Edition
Stars: ✭ 35 (-2.78%)
Mutual labels:  strings, string-manipulation
Str
str: yet another string library for C language.
Stars: ✭ 159 (+341.67%)
Mutual labels:  strings, string-manipulation
Stringz
💯 Super fast unicode-aware string manipulation Javascript library
Stars: ✭ 181 (+402.78%)
Mutual labels:  strings, string-manipulation
Libft
42 library of basic C functions - queues, lists, memory operations and more 😄
Stars: ✭ 21 (-41.67%)
Mutual labels:  strings, string-manipulation
Util
A collection of useful utility functions
Stars: ✭ 201 (+458.33%)
Mutual labels:  strings, string-manipulation
Java-Programs
Java Practiced Problems including concepts of OOPS, Interface, String , Collection.
Stars: ✭ 51 (+41.67%)
Mutual labels:  oop, string-manipulation
concat
Demo repository for habr.com article about faster Go string concatenation.
Stars: ✭ 16 (-55.56%)
Mutual labels:  strings
python-pyfields
Define fields in python classes. Easily.
Stars: ✭ 39 (+8.33%)
Mutual labels:  oop
sublimetext-stringutilities
Sublime Text 2/3 plugin for string manipulations
Stars: ✭ 81 (+125%)
Mutual labels:  string-manipulation
ResourcesPoet
Kotlin API for generating Android XML Resources
Stars: ✭ 102 (+183.33%)
Mutual labels:  strings
simplehstore
🏪 Easy way to use a PostgreSQL database (and the HSTORE feature) from Go
Stars: ✭ 54 (+50%)
Mutual labels:  strings
express-mvc-pattern
Example nodejs using express implementation design pattern using mvc architecture.
Stars: ✭ 52 (+44.44%)
Mutual labels:  oop
ooop
OOP has never been sooo professionally over engineered before.
Stars: ✭ 20 (-44.44%)
Mutual labels:  oop

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.

Install

Via composer:

composer require thestringler/manipulator

Using Laravel? Checkout The Stringler Laravel Package.

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.

$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.

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.

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

Contribute

Contributions are very welcome!

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

That's pretty much it!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].