- Description
- Installation
- Usage
- Available inflectors
- Datetime 1. Relative
- Number 1. HumanByte 2. Ordinalize 3. Shorten 4. Textualize
- String 1. Camelize 2. Denamespace 3. Humanize 4. NamespaceOnly 5. Slugify
- Run the test
- Contributing
- Requirements
- Authors
- License
Inflexible aims to gather a collection of commonly used Inflectors into a single lib.
Using Composer, just $ composer require borisguery/inflexible package or:
{
"require": {
"borisguery/inflexible": "dev-master"
}
}Convert a DateTime object or a number of seconds into the most fitted unit:
Inflexible::relativeDatetime(86400);Returns
array(
1,
'day'
)You may also want to get the relative datetime from a given date:
Inflexible::relativeDatetime(new DateTime('2012-01-10'), new DateTime('2012-01-17'));Returns
array(
1,
'week'
)The available units are:
- second
- minute
- hour
- day
- week
- month
- year
Convert bytes to an human readable representation to the most fitted unit:
Inflexible::humanByte(1024);
// 1.00 KBInflexible::humanByte(1048576);
// 1.00 MBInflexible::humanByte(1073741824);
// 1.00 GBYou may also provided an optional precision as a second argument (default to 2)
Converts number to its ordinal English form:
Inflexible::ordinalize(1);
// 1stInflexible::ordinalize(13);
// 13thFormats a number using the SI units (k, M, G, etc.):
Inflexible::shorten(100);
// array(100, null)
// No units for number < 1000Inflexible::shorten(1523);
// 1kReturns the textual representation of a number
Inflexible::textualize(1025433);
// One Million, Twenty Five Thousand, Four Hundred and Thirty ThreeConverts a word like "foo_bar" to "FooBar". It also removes non-alphanumeric characters:
Inflexible::camelize('foo_bar');
// FooBarReturns only the class name
Inflexible::denamespace('\Foo\Bar\Baz');
// BazConverts CamelCased word and underscore to space to return a readable string:
Inflexible::humanize('foo_bar');
// Foo BarInflexible::humanize('FooBar');
// Foo BarReturns the namespace of a fully qualified class name:
Inflexible::namespaceOnly('\Foo\Bar\Baz');
// Foo\BarSlugify a string:
Inflexible::namespaceOnly('lo\rem ipsum do|or sid amet||| #\`[|\" 10 .');
// lo-rem-ipsum-do-or-sid-amet-10You may optionally set the separator, a max length or decide to whether lower the case:
Inflexible::slugify(
'LoRem ipsum do|or sid amet||| #\`[|\" 10 .',
array(
'maxlength' => 4,
'lowercase' => true,
'separator' => '_'
)
);
// loreFirst make sure you have installed all the dependencies, run:
$ composer install --dev
then, run the test from within the root directory:
$ phpunit
- Take a look at the list of issues.
- Fork
- Write a test (for either new feature or bug)
- Make a PR
- PHP 5.3+
Boris Guéry - [email protected] - http://twitter.com/borisguery - http://borisguery.com
Inflexible is licensed under the WTFPL License - see the LICENSE file for details
