imliam/php-name-of-person

Present names for English-language applications.

v1.2.0 2022-04-28 15:20 UTC

This package is auto-updated.

Last update: 2024-10-28 20:16:45 UTC


README

Latest Version on Packagist Build Status Code Quality Code Coverage Total Downloads License

Present names for English-language applications where a first and last name combined is sufficient. This approach does not cover all possible naming cases, deal with other languages or titles.

This is a rough port of the Ruby package of the same name from Basecamp.

💾 Installation

You can install the package with Composer using the following command:

composer require imliam/php-name-of-person:^1.1

📝 Usage

The package supplies a single class that can be instantiated with a string containing the original name of a person.

The class has a handful of methods that can be called to return different variations of the supplied name.

use ImLiam\NameOfPerson\Name;

$name = new Name('David Heinemeier Hansson');

$name->getFullName();       // "David Heinemeier Hansson"
$name->getFirstName();      // "David"
$name->getLastName();       // "Heinemeier Hansson"
$name->getInitials();       // "DHH"
$name->getInitials(true);   // "D.H.H."
$name->getFamiliar();       // "David H."
$name->getAbbreviated();    // "D. Heinemeier Hansson"
$name->getSorted();         // "Heinemeier Hansson, David"
$name->getMentionable();    // "davidh"
$name->getPossessive();     // "David Heinemeier Hansson's"
$name->getProperName();     // "David Heinemeier Hansson"

These methods take care to handle some of the situations that are often awkward to process and missed when handling names that come from user-input so aren't always reliable.

One such example is that names with particles can be capitalised properly with the getProperName() method.

(new Name("lucas l'amour"))->getProperName(); // "Lucas l'Amour"
(new Name('t. von lieres und wilkau'))->getProperName(); // "T. von Lieres und Wilkau"

✅ Testing

composer test

🔖 Changelog

Please see the changelog file for more information on what has changed recently.

⬆️ Upgrading

Please see the upgrading file for details on upgrading from previous versions.

🎉 Contributing

Please see the contributing file and code of conduct for details on contributing to the project.

🔒 Security

If you discover any security related issues, please email liam@liamhammett.com instead of using the issue tracker.

👷 Credits

♻️ License

The MIT License (MIT). Please see the license file for more information.