Skip to content

enricodias/Nameize

Repository files navigation

Nameize

Build Status Codacy Badge Codacy Badge Latest version Downloads total License

A simple class to correctly capitalize full names.

Installation

Require this package with Composer in the root directory of your project

composer require enricodias/nameize

and include the composer's autoloader in your code

include 'vendor/autoload.php';

Usage

Simple usage

echo \enricodias\Nameize::create()->name("Carlo D'ippoliti"); // Carlo D'Ippoliti

or

$nameize = new \enricodias\Nameize();

echo $nameize->name("Matteo Dell'aqcua");  // Matteo Dell'Aqcua
echo $nameize->name("john o'grady-smith"); // John O'Grady-Smith

Specifying special characters

The method setAllowedCharacters() receives an array of special characters. Those characters signalizes that the next letter should be in upper case. If no character is specified, the default array("'", '-') is used. If you pass a string, it will be consider a single character.

$nameize = new \enricodias\Nameize();

$nameize->setAllowedCharacters("'");

echo $nameize->name("Matteo Dell'aqcua");  // Matteo Dell'Aqcua
echo $nameize->name("john o'grady-smith"); // John O'Grady-smith

or with method chaining:

echo \enricodias\Nameize::create()
    ->setAllowedCharacters("-")
    ->name("john o'grady-smith"); // John O'grady-Smith

Minimum length

Some languages require capitalization on the first letter of every word regardless of their size. The setMinLength() method sets the minimum length of which words will be capitalized (min: 1, max: 5, default: 4).

$nameize = new \enricodias\Nameize();

$nameize->setMinLength(1);

echo $nameize->name("Tri vu phu");    // Tri Vu Phu
echo $nameize->name("Shuanping dai"); // Shuanping Dai

or with method chaining:

echo \enricodias\Nameize::create()
    ->setMinLength(1)
    ->name("Tri vu phu"); // Tri Vu Phu

Your application may detect the user's country and use the appropriate minLength value.

Additional features

If you need more features I recommend using a name parser such as https://github.com/theiconic/name-parser

About

Correctly capitalize full names

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages