Skip to content

A port of Basecamp's Ruby library "Name of Person" for Elixir

License

Notifications You must be signed in to change notification settings

acoustep/name_of_person

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Name of Person

This is a port of Basecamp's Ruby library Name of Person to Elixir. From their description:

Presenting names for English-language applications where a basic model of first and last name(s) combined is sufficient. This approach is not meant to cover all possible naming cases, deal with other languages, or even titulations. Just the basics.

This library also accepts middle names and uses them where appropriate.

Example usage

alias NameOfPerson.PersonName
iex> PersonName.full("Ned Flanders")
"Ned Flanders"
iex> PersonName.familiar("Frodo", "Baggins")
"Frodo B."
iex> PersonName.abbreviated(%PersonName{first_name: "Kaladin", last_name: "Stormblessed"})
"K. Stormblessed"
iex> PersonName.possessive(["Dirk", "Gentley"])
"Dirk Gentley's"

Using with Phoenix

This library can be used with Phoenix without any extra configuration. Optionally, import the module into the relevant views for more convenience.

# views/page_view.ex
defmodule AppNameWeb.PageView do
  use AppNameWeb, :view
  import NameOfPerson.PersonName, only: [familiar: 1]
end

# templates/page/index.html.eex
<%= familiar("Eiji Niizuma") %>

Available Arguments

Most functions accept from one to three string parameters, e.g. full/1, full/2, full/3. Additionally, you can pass a List of names or a %NameOfPerson.PersonName{} struct. The struct can take 3 arguments, first_name, middle_name, and last_name.

full/1 will look for spaces and split the names up appropriately. full/2 will assume the first parameter is the first name and the second parameter is the last name. full/3 takes a first, middle, and last name. In some cases, e.g. initials, the middlename is checked for multiple names within itself.

Available methods

  • abbreviated
  • familiar
  • first
  • full
  • initials
  • last
  • last!
  • has_last?
  • mentionable
  • possessive
  • sorted

Installation

If available in Hex, the package can be installed by adding name_of_person to your list of dependencies in mix.exs:

def deps do
  [
    {:name_of_person, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/name_of_person.

About

A port of Basecamp's Ruby library "Name of Person" for Elixir

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages