2017 © Pedro PelĂĄez
 

library inflexible

Collection of Inflectors for string, date, numbers, etc.

image

borisguery/inflexible

Collection of Inflectors for string, date, numbers, etc.

  • Monday, June 17, 2013
  • by borisguery
  • Repository
  • 2 Watchers
  • 19 Stars
  • 1,297 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 4 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Inflexible Build Status

Table of contents

  1. Description
  2. Installation
  3. Usage
    1. Available inflectors
    2. Datetime
      1. Relative
    3. Number
      1. HumanByte
      2. Ordinalize
      3. Shorten
      4. Textualize
    4. String
      1. Camelize
      2. Denamespace
      3. Humanize
      4. NamespaceOnly
      5. Slugify
  4. Run the test
  5. Contributing
  6. Requirements
  7. Authors
  8. License

Description

Inflexible aims to gather a collection of commonly used Inflectors into a single lib., (*1)

Installation

Using Composer, just $ composer require borisguery/inflexible package or:, (*2)

``` javascript { "require": { "borisguery/inflexible": "dev-master" } }, (*3)


Usage ----- ### Available inflectors #### Datetime ##### Relative Convert a `DateTime` object or a number of seconds into the most fitted unit: ```php Inflexible::relativeDatetime(86400);

Returns, (*4)

array(
    1,
    'day'
)

You may also want to get the relative datetime from a given date:, (*5)

Inflexible::relativeDatetime(new DateTime('2012-01-10'), new DateTime('2012-01-17'));

Returns, (*6)

array(
    1,
    'week'
)

The available units are:, (*7)

  • second
  • minute
  • hour
  • day
  • week
  • month
  • year

Number

HumanByte

Convert bytes to an human readable representation to the most fitted unit:, (*8)

Inflexible::humanByte(1024);
// 1.00 KB
Inflexible::humanByte(1048576);
// 1.00 MB
Inflexible::humanByte(1073741824);
// 1.00 GB

You may also provided an optional precision as a second argument (default to 2), (*9)

Ordinalize

Converts number to its ordinal English form:, (*10)

Inflexible::ordinalize(1);
// 1st
Inflexible::ordinalize(13);
// 13th
Shorten

Formats a number using the SI units (k, M, G, etc.):, (*11)

Inflexible::shorten(100);
// array(100, null)
// No units for number < 1000
Inflexible::shorten(1523);
// 1k
Textualize

Returns the textual representation of a number, (*12)

Inflexible::textualize(1025433);
// One Million, Twenty Five Thousand, Four Hundred and Thirty Three

String

Camelize

Converts a word like "foo_bar" to "FooBar". It also removes non-alphanumeric characters:, (*13)

Inflexible::camelize('foo_bar');
// FooBar
Denamespace

Returns only the class name, (*14)

Inflexible::denamespace('\Foo\Bar\Baz');
// Baz
Humanize

Converts CamelCased word and underscore to space to return a readable string:, (*15)

Inflexible::humanize('foo_bar');
// Foo Bar
Inflexible::humanize('FooBar');
// Foo Bar
NamespaceOnly

Returns the namespace of a fully qualified class name:, (*16)

Inflexible::namespaceOnly('\Foo\Bar\Baz');
// Foo\Bar
Slugify

Slugify a string:, (*17)

Inflexible::namespaceOnly('lo\rem ipsum do|or sid amet||| #\`[|\" 10 .');
// lo-rem-ipsum-do-or-sid-amet-10

You may optionally set the separator, a max length or decide to whether lower the case:, (*18)

Inflexible::slugify(
    'LoRem ipsum do|or sid amet||| #\`[|\" 10 .',
    array(
        'maxlength' => 4,
        'lowercase' => true,
        'separator' => '_'
    )
);
// lore

Run the test

First make sure you have installed all the dependencies, run:, (*19)

$ composer install --dev, (*20)

then, run the test from within the root directory:, (*21)

$ phpunit, (*22)

Contributing

  1. Take a look at the list of issues.
  2. Fork
  3. Write a test (for either new feature or bug)
  4. Make a PR

Requirements

  • PHP 5.3+

Authors

Boris Guéry - guery.b@gmail.com - http://twitter.com/borisguery - http://borisguery.com, (*23)

License

Inflexible is licensed under the WTFPL License - see the LICENSE file for details, (*24)

The Versions

17/06 2013

dev-master

9999999-dev http://github.com/borisguery/Inflexible

Collection of Inflectors for string, date, numbers, etc.

  Sources   Download

WTFL

The Requires

 

The Development Requires

date utility inflector string number inflection