2017 © Pedro Peláez
 

library inflector

Inflector Library

image

crysalead/inflector

Inflector Library

  • Sunday, October 16, 2016
  • by jails
  • Repository
  • 2 Watchers
  • 5 Stars
  • 5,013 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 9 % Grown

The README.md

Inflector - Inflector library

Build Status Code Coverage, (*1)

Inflector is a small library that can perform string transformation like singularization, pluralization, underscore to camel case, titelize words and more. Inflections can be localized., (*2)

The Inflector class is prepopulated with english inflections for singularization and pluralization to be ready to use., (*3)

Usage

Examples of usage of the inflector with the 'default' locale (i.e english):


use Lead\Inflector\Inflector; # pluralize Inflector::pluralize('post'); // "posts" Inflector::pluralize('posts'); // "posts" Inflector::pluralize('child'); // "children" Inflector::pluralize('ContactPerson'); // "ContactPeople" # singularize Inflector::singularize('posts'); // "post" Inflector::singularize('children'); // "child" Inflector::singularize('ContactPeople'); // "ContactPerson" # transliterate Inflector::transliterate('の話が出たので大丈夫かなあと'); // "no huaga chutanode da zhang fukanaato" # slug Inflector::slug('Foo:Bar & Cie'); // "Foo-Bar-Cie" Inflector::slug('Foo:Bar & Cie', '_'); // "Foo_Bar_Cie" # parameterize Inflector::parameterize('Foo:Bar & Cie'); // "foo-bar-cie" Inflector::parameterize('Foo:Bar & Cie', '_'); // "foo_bar_cie" # camelize Inflector::camelize('test_field'); // "TestField" Inflector::camelize('TEST_FIELD'); // "TestField" Inflector::camelize('my_name\space'); // "MyName\Space" # camelback Inflector::camelback('test_field'); // "testField" Inflector::camelback('TEST_FIELD'); // "testField" # underscore Inflector::underscore('TestField'); // "test_field" Inflector::underscore('MyName\Space'); // "my_name\space" Inflector::underscore('dashed-string'); // "dashed_string" # dasherize Inflector::dasherize('underscored_string'); // "underscored_string" # humanize Inflector::humanize('employee_salary'); // "Employee salary" Inflector::humanize('author_id'); // "Author" # titleize Inflector::titleize('man from the boondocks'); // "Man From The Boondocks" Inflector::titleize('x-men: the last stand'); // "X Men: The Last Stand" Inflector::titleize('TheManWithoutAPast'); // "The Man Without A Past" Inflector::titleize('raiders_of_the_lost_ark'); // "Raiders Of The Lost Ark"

 Examples of usage of custom locales:


namespace inflector\Inflector; Inflector::pluralize('child'); // "children" //Load custom definition for `'zz'` locale using a closure Inflector::singular('/x$/i', '', 'zz'); Inflector::plural('/([^x])$/i', '\1x', 'zz'); Inflector::singularize('abcdefx', 'zz'); // "abcdef" Inflector::pluralize('abcdef', 'zz'); // "abcdefx"

If you wan't to use an other language by default for inflections, you can override the 'default' rules directly., (*4)

Inflector::reset(true); // Remove all loaded inflection rules.

Inflector::singular('/x$/i', '', 'default');
Inflector::plural('/([^x])$/i', '\1x', 'default');

Inflector::singularize('abcdefx');             // "abcdef"
Inflector::pluralize('abcdef');                // "abcdefx"

Note: you can check spec/fixture for some examples of inflection rules for spanish and french languages., (*5)

Requirement

Requires PHP >= 5.4 and the PECL intl extension., (*6)

sudo apt-get install php-intl

Installation with Composer

The recommended way to install this package is through Composer. Create a composer.json file and run composer install command to install it:, (*7)

{
    "require":
    {
        "crysalead/inflector": "~1.0"
    }
}

Testing

The spec suite can be runned with:, (*8)

cd inflector
composer install
./bin/kahlan

PS: Composer need to be present on your system., (*9)

Acknowledgements

Most of the code and documentation was adapted from Ruby On Rails's Inflector., (*10)

The Versions

16/10 2016

dev-master

9999999-dev

Inflector Library

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by CrysaLEAD

inflection

17/05 2016

2.0.2

2.0.2.0

Inflector Library

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

inflection

31/12 2015

2.0.1

2.0.1.0

Inflector Library

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

inflection

06/12 2015

2.0.0

2.0.0.0

Inflector Library

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

inflection

04/06 2015

1.0.0

1.0.0.0

Inflector Library

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

inflection