API Specifications
The API specifications are the verbs namefully
speaks.
getPrefix()
Alias: px()
Gets the prefix part of the full name, if any. If no prefix was set as part of the
full name at the time of instantiating Namefully
, the return value is an empty
string.
Example:
getFirstname(includeAll)
Alias: fn(includeAll)
Gets the first name part of the full name.
tip
Recalling that namefully
provides ready-made classes that help you to manipulate
unusual use cases for a full name, you may want to use Firstname
to treat multiple
pieces of name as firstname
, assuming they are not middle names.
includeAll
: a boolean argument set to true
by default that decides whether or not to include
all the pieces of the first name as a given name may be composed of one or more
pieces of name.
Example:
getMiddlenames()
Alias: mn()
Gets the middle name part of the full name.
Example:
tip
You may want to handle subparts of the middle name separately. To do so, use the
class Name
along with the Namon
enum to set the name type as MIDDLE_NAME
for each name part.
Example:
getLastname(format)
Alias: ln(format)
Gets the last name part of the full name.
format
: this string argument overrides the how-to format of a surname output (previously
set in config), considering its subparts. The last name format can be of the
following:
father
(by default): father name onlymother
: mother name onlyhyphenated
: joining both father and mother names with a hyphenall
: joining both father and mother names with a space.
This parameter can be set either by an instance of a last name or during the
creation of a Namefully
instance. To avoid ambiguity, I prioritize as source of
truth the value set as optional parameter when instantiating Namefully
.
Example:
getSuffix()
Alias: sx()
Gets the suffix part of the full name, if any. If no suffix was set as part of the
full name at the time of instantiating Namefully
, the return value is an empty
string.
Example:
getFullname(orderedBy)
Alias: full(orderedBy)
Gets the full name (the five name parts, if set).
orderedBy
: this string argument overrides the preset order of appearance of a full name: by
first name or last name. If none was set initially, Namefully
assumes a default
order, which by first name.
Example:
getBirthname(orderedBy)
Alias: birth(orderedBy)
Gets the birth name ordered as configured. No prefix or suffix are included.
orderedBy
: this string argument overrides the preset order of appearance of a full name: by
first name or last name. If none was set initially, Namefully
assumes a default
order, which by first name.
Example:
getInitials(orderedBy, withMid)
Alias: inits(orderedBy, withMid)
Gets the initials of the full name.
orderedBy
: this string argument overrides the preset order of appearance of a full name: by first name or last name. If none was set initially,Namefully
assumes a default order, which is by first name.withMid
: this boolean argument indicates whether to include the initials of the middle names, if that name part was set. Otherwise, by setting this parameter totrue
when no middle name was set in the beginning, this argument will only give a warning. By default, it'sfalse
.
Example:
describe(nameType)
Alias: stats(nameType)
Gives some descriptive statistics that summarize the central tendency, dispersion and shape of the characters' distribution.
Treated as a categorical dataset, the summary of a name contains the following info:
- count : the number of unrestricted characters of the name;
- frequency : the highest frequency within the characters;
- top : the character with the highest frequency;
- unique : the count of unique characters of the name;
- distribution : the characters' distribution.
nameType
: this string argument indicates which name type to use when describing a full name.
By default, the full name is described.
Example:
shorten(orderedBy)
Shortens a full name to a simpler typical name, a combination of first name and last name.
orderedBy
: this string argument overrides the preset order of appearance of a full name: by
first name or last name. If none was set initially, Namefully
assumes a default
order, which is by first name.
Example:
For a given name such as Mr Keanu Charles Reeves, shortening this name is equivalent to making it Keanu Reeves.
important
As a shortened name, the namon of the first name is favored over the other names
forming part of the entire first names, if any. Meanwhile, for the last name, the
configured lastnameFormat
is prioritized.
For a given Firstname Fathername Mothername
, shortening this name when the
lastnameFormat
is set as mother
is equivalent to making it: Firstname Mothername
.
compress(limit, by, warning)
Compresses a name, using different forms of variants. A name is compressed (or shortened using its initials) when the length of the name's characters surpasses the indicated limit. If after compressing the name, the new length of the compressed name still surpasses the limit, the user receives a warning about it.
limit
: this number argument sets the threshold to limit the number of characters. The default value is 20.by
: this string argument specifies which variant to use when compressing a long birth name. These variants are:- firstname or fn
- middlename or mn
- lastname or ln
- firstmid or fm (combination of first name and middle name)
- lastmid or lm (combination of middle name and last name)
By default, this method compresses the birth name using the middlename variant.
warning
: this boolean argument indicates whether an end-user should be warned when the set limit is violated.
tip
You may want to always compress the birth names. A good tip to run this effect
silently is to use the method as follows: compress(0, 'firstmid', false)
. Or,
you can simply use the zip method.
Example:
zip(by)
Shortens or abbreviates parts of a birth name, using its initials. This method is a silent wrapper of the compress method.
by
: this string argument specifies which variant to use when compressing a long birth
name. These variants are:
- firstname or fn
- middlename or mn
- lastname or ln
- firstmid or fm (combination of first name and middle name)
- lastmid or lm (combination of middle name and last name)
Example:
Using the same classic examples used in the previous examples:
username()
Suggests 10 possible (randomly) usernames closest to the typical name. These usernames are formed, obeying the following rules:
- first name + last name
- last name + first name
- first letter of first name + last name
- first letter of last name + first name
- first letter of first name + period + last name
- first letter of last name + period + first name
- first 2 letters of first name + last name
- first 2 letters of last name + first name
- first 2 letters of first name + period + last name
- first 2 letters of last name + period + first name
important
The validity of these usernames are not checked against any social media or web apps online.
Example:
format(how)
Formats the name as desired.
how
: this string argument defines how to format the name:
string format
short
: typical first name and last namelong
: birth name without prefix and suffixofficial
: official document format
char format
b
: birth nameB
: capitalized birth namef
: first nameF
: capitalized first namel
: last nameL
: capitalized last namem
: middle namesM
: capitalized middle nameso
: official document formatO
: official document format in capital lettersp
: prefixP
: capitalized prefixs
: suffixS
: capitalized suffix
punctuations
.
: period,
: comma' '
: space-
: hyphen_
: underscore
Example:
size()
Returns the count of characters of the birth name, while excluding the punctuations. Keep in mind that more statistical information can be found when using the describe method.
Example:
ascii({nameType, exceptions})
Returns an ascii representation of each characters of a name as specified.
nameType
: this string argument indicates which name type to use when representing
that name in ascii. By default, the full name is represented.
exceptions
: list of restricted characters that are skipped during the conversion.
Example:
to(case)
Transforms a birth name to a specific title case.
case
: this string argument defines the case for the conversion:
upper
lower
camel
pascal
snake
hyphen
dot
toggle
Example:
passwd(nameType)
Returns a password-like representation of a name.
nameType
: this string argument indicates which name type to use as a basis
to generate a password-like string content. If none is provided, the full name
is used as a basis.
Example:
More examples on how to use these methods can be found in Examples and Use Cases.