Resources
namefully
provides some ready-made recipes with extra functionality. They
work independently. That is, you don't need an instance of Namefully
to
work with a specific name part like a first name, for example.
They are 3 basic classes:
Name
FirstName
LastName
Name
This class represents a piece of name in a string format with
some extra capabilities, compared to a simple string utils provided by JavaScript.
This class helps to define the role of a name part (e.g., prefix
) before anything.
Example:
Alternatively:
As you can see, the 5 types of name can be created from that class. Additionally, you can specify which kind of capitalizations to use when manipulating that piece of name.
API:
Properties | Type | Modifier | Description |
---|---|---|---|
value | string | read/write | The piece of string treated as a name. |
length | number | read-only | The length of the name. |
isPrefix | boolean | read-only | Whether the name is a prefix. |
isFirstName | boolean | read-only | Whether the name is a first name. |
isMiddleName | boolean | read-only | Whether the name is a middle name. |
isLastName | boolean | read-only | Whether the name is a last name. |
isSuffix | boolean | read-only | Whether the name is a suffix. |
Methods | Returns | Description |
---|---|---|
toString() | string | Returns a string representation of the namon. |
initials() | string[] | Gets the initials (first character) of this name. |
equal(Name) | boolean | Returns true if the other is equal to this name. |
caps(CapsRange) | Name | Capitalizes a name. |
decaps(CapsRange) | Name | De-capitalizes a name. |
FirstName
This class is an extension of Name
and represents a given name. It can work
with more than one name part.
Example:
An instance of this class handles separately the required name piece along with the optional other given names a person might have.
API:
Properties | Type | Modifier | Description |
---|---|---|---|
hasMore | boolean | read-only | Determines whether a first name has more name parts. |
more | string[] | read-only | The additional name parts of the first name. |
asNames | Name[] | read-only | The combined version of the value and more if any. |
Methods | Returns | Description |
---|---|---|
toString(boolean) | string | Returns a string representation of the namon. |
initials(boolean) | string[] | Gets the initials (first character) of this name. |
copyWith({ first?: string; more?: string[] }) | FirstName | Makes a copy of the current name. |
LastName
This class is an extended arm of Name
and represents a surname. It handles
two types of surname: a father's and a mother's.
Pay attention to the third argument (optional): format. It defines how the surname per se should be output. By default, the father's name is considered.
Example:
API:
Properties | Type | Modifier | Description |
---|---|---|---|
hasMother | boolean | read-only | Returns true if the mother's surname is defined. |
father | string[] | read-only | The surname inherited from a father side. |
mother | string[] | read-only | The surname inherited from a mother side. |
asNames | Name[] | read-only | The combined version of the father and mother if any. |
Methods | Returns | Description |
---|---|---|
toString(Surname) | string | Returns a string representation of the namon. |
initials(Surname) | string[] | Gets the initials (first character) of this name. |
copyWith({ father?: string; mother?: string; format?: Surname }) | LastName | Makes a copy of the current name. |
Not sure to know how to use these classes? See some examples.