artisan/name-of-person

This package is abandoned and no longer maintained. The author suggests using the humans/name-of-person package instead.

A wrappr for parsing people's names.

2.1.0 2019-10-22 04:40 UTC

This package is auto-updated.

Last update: 2020-02-07 23:16:15 UTC


README

A port of Basecamp's name of person library.

A library to make an much more expressive breakdown of a user's name.

This is a pretty simplified library without accounting for any of the edge cases of how names are handled, just something usable where everything after the first name is treated as the last name.

Installation

composer require artisan/name-of-person

Upgrade Notes

The API now returns an instance of the PersonName class instead of the string to allow for method chaining. This should not affect most of the use cases.

Usage

use Artisan\NameOfPerson\PersonName;

$name = new PersonName('Terry Crews');

$name->full;              // => "Terry Crews"
$name->first;             // => "Terry"
$name->last;              // => "Crews"
$name->initials;          // => "TC"
$name->familiar;          // => "Terry C."
$name->abbreviated;       // => "T. Crews"
$name->sorted;            // => "Crews, Terry"
$name->mentionable;       // => "terryc"
$name->possessive;        // => "Terry Crews'"
$name->first->possessive  // => Terry's
$name->last->possessive   // => Crews'

The Laravel Trait has been removed!

I ended up not using the trait since there are projects that I wanted to use a different key for the name. Instead, if you want to use the library, I highly suggest using a different attribute to avoid conflicts when building JSON APIs.

use Artisan\NameOfPerson\PersonName;

class User
{
    public function getNameAttribute()
    {
        return new PersonName($this->attributes['full_name']);
    }
}