2017 © Pedro Peláez
 

sclr

image

gilbitron/sclr

  • by gilbitron
  • Repository
  • 0 Watchers
  • 0 Stars
  • 0 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 0 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

Sclr

Sclr is a library that adds useful Ruby-style methods to scalar types in PHP. It uses a wrapper function (much like jQuery's $()) to make using Sclr as easy as possible, and even supports method chaining., (*2)

Requirements

  • PHP 5.4+

Install

Install via composer:, (*3)

{
    "require": {
        "gilbitron/sclr": "~1.0"
    }
}

Run composer install then use as normal:, (*4)

require 'vendor/autoload.php';

$string = s('hello world')->capitalize();

Usage

Using Sclr is as simple as passing your value into the s($value) function. You can then use any of the API methods below as you wish., (*5)

Strings

capitalize()

Uppercase the first character of each word in a string., (*6)

s('hello world')->capitalize()
=> "Hello World"

Chainable: Yes, (*7)

capitalizeFirst()

Make a string's first character uppercase., (*8)

s('hello world')->capitalizeFirst()
=> "Hello world"

Chainable: Yes, (*9)

chars()

Convert a string to an array., (*10)

s('hello world')->chars()
=> ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']

Chainable: No, (*11)

chop()

Remove the last character from a string., (*12)

s('hello world')->chop()
=> "hello worl"

Chainable: Yes, (*13)

contains()

Test if the value contains a given string., (*14)

s('hello world')->contains('ello')
=> true

Chainable: No, (*15)

endsWith()

Test if the value ends with a given string., (*16)

s('hello world')->endsWith('rld')
=> true

Chainable: No, (*17)

length()

Return the length of a string., (*18)

s('hello world')->length()
=> 11

Chainable: No, (*19)

lowercase()

Make a string lowercase., (*20)

s('HeLlO WoRlD')->lowercase()
=> "hello world"

Chainable: Yes, (*21)

reverse()

Reverse a string., (*22)

s('hello world')->reverse()
=> "dlrow olleh"

Chainable: Yes, (*23)

startsWith()

Test if the value starts with a given string., (*24)

s('hello world')->startsWith('hel')
=> true

Chainable: No, (*25)

uppercase()

Make a string uppercase., (*26)

s('HeLlO WoRlD')->uppercase()
=> "HELLO WORLD"

Chainable: Yes, (*27)

Chainable example:

$string = s('hello world')->capitalize()->chop()->reverse();
// $string = "lroW olleH"

Arrays

For array methods you need to use the value() method to retrieve the value from chainable methods (e.g. $array = s(['a'])->append('b')->value())., (*28)

Coming soon..., (*29)

Credits

Sclr was created by Gilbert Pellegrom from Dev7studios. Released under the MIT license., (*30)

The Versions