2017 © Pedro Peláez
 

library tale-inflector

A library that can inflect strings to many formats

image

talesoft/tale-inflector

A library that can inflect strings to many formats

  • Friday, June 8, 2018
  • by TorbenKoehn
  • Repository
  • 3 Watchers
  • 0 Stars
  • 315 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 3 Versions
  • 51 % Grown

The README.md

Packagist License CI Coverage, (*1)

Tale Inflector

What is Tale Inflector?

Tale inflector bends strings into different naming styles. A common use-case would be the converting of class-names or property-names to table-names or titles to slugs for URLs., (*2)

It can also generate the plural or singular of a string or ordinalize numbers., (*3)

Installation

composer require talesoft/tale-inflector

Usage

use Tale\Inflector;

$inflector = new Inflector();

//Table generation
$inflector->inflect('ProductAttribute', ['tableize', 'pluralize']); //product_attributes
$inflector->inflect('someProperty', ['tableize']); //some_property

//Canonicalization / slugs
$inflector->inflect('Some title I inserted', ['canonicalize']); //some-title-i-inserted
$inflector->inflect('Was höre ich da?', ['canonicalize']); //was-hore-ich-da

//Or just use the static methods for quick access
Inflector::canonicalize('Some random title'); //some-random-title

Available strategies/static methods

camelize

Tale\Inflector\Strategy\CamelCaseStrategy, (*4)

some Random string = SomeRandomString

dasherize

Tale\Inflector\Strategy\DashRejoinStrategy, (*5)

some Random string = some-Random-string

canonicalize

Tale\Inflector\Strategy\KebabCaseStrategy, (*6)

some Random string = some-random-string

variableize

Tale\Inflector\Strategy\LowerCamelCaseStrategy, (*7)

some Random string = someRandomString

constantize

Tale\Inflector\Strategy\MacroCaseStrategy, (*8)

some Random string = SOME_RANDOM_STRING

tableize

Tale\Inflector\Strategy\SnakeCaseStrategy, (*9)

some Random string = some_random_string

underscorize

Tale\Inflector\Strategy\UnderscoreRejoinStrategy, (*10)

some Random string = some_Random_string

humanize

Tale\Inflector\Strategy\UppercaseWordsStrategy, (*11)

some Random string = Some Random String

ordinalize

Tale\Inflector\Strategy\NumberOrdinalStrategy, (*12)

1 = 1st
12 = 12th
23 = 23rd

pluralize

Tale\Inflector\Strategy\MacroCaseStrategy, (*13)

rabbit = rabbits
car = cars
house = houses

singularize

Tale\Inflector\Strategy\MacroCaseStrategy, (*14)

rabbits = rabbit
cars = car
houses = house

Roll your own

```php use Tale\Inflector\StrategyInterface;, (*15)

class MyInflectionStrategy implements StrategyInterface { public function inflect(string $string): string { return "!! {$string} !!"; } }, (*16)

$inflector->inflect('Test', [MyInflectionStrategy::class]); //!! Test !! ```, (*17)

You can register your own short names, (*18)

use Tale\Inflector\StrategyInterface;

class MyInflectionStrategy implements StrategyInterface
{
    public function inflect(string $string): string
    {
        return "!! {$string} !!";
    }
}

$inflector->addNamedStrategy('exlamize', MyInflectionStrategy::class);
$inflector->inflect('House', ['pluralize', 'exclamize']); //!! Houses !!

The Versions

08/06 2018

dev-master

9999999-dev http://docs.talesoft.codes/php/tale/inflector

A library that can inflect strings to many formats

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Torben Koehn

manipulation string inflection plural singular bending

10/05 2018

0.2.0

0.2.0.0 http://docs.talesoft.codes/php/tale/inflector

A library that can inflect strings to many formats

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Torben Koehn

manipulation string inflection plural singular bending

21/05 2016

0.1

0.1.0.0 http://docs.talesoft.io/tale-framework/tale/inflector

A library that can inflect strings to many formats

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Torben Koehn

manipulation string inflection bending