Version: 1.0.9

Resources

namefully provides some ready-made recipes with some extra functionalities. They work independently. That is to say, 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:

  1. Name
  2. Firstname
  3. Lastname
note

Some of the APIs that are available in Namefully are also available in these classes. But these classes contain certain functionalities that are native.

Name

This class represents a namon (i.e., 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.

constructor
/**
* Constructs a `Name`
* @param namon a piece of string that will be defined as a namon
* @param type which namon that is
* @param capitalized which kind of capitalizations
*/
constructor(
public namon: string,
public type: Namon,
capitalized?: 'initial' | 'all'
);

Example:

import { Name, Namon } from 'namefully'
const prefix = new Name('Dr', Namon.PREFIX)
const firstname = new Name('Nick', Namon.FIRST_NAME)
const middlename = new Name('Ariana', Namon.MIDDLE_NAME)
const lastname = new Name('Clinton', Namon.LAST_NAME)
const suffix = new Name('MSc', Namon.SUFFIX)
const name = new Name('John', Namon.FIRST_NAME, 'all')
console.log(name.namon) // => JOHN

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:

MethodsArgumentsDefaultReturnsDescription
getInitialsnonenonestring[]Gets the initials of the name
describenonenoneSummaryGives some descriptive statistics of the characters' distribution
uppernonenonestringReturns a lowercase string representation of the namon
lowernonenonestringReturns a lowercase string representation of the namon

Aliases:

None

Firstname

This class is an extended arm of Name and represents a given name. It can work with more than one name part.

constructor
/**
* Constructs a `Firstname`
* @param namon a piece of string that will be defined as a namon
* @param more additional pieces considered as a given name
*/
constructor(public namon: string, public more?: string[]);

Example:

import { Firstname } from 'namefully'
const firstname = new Firstname('Ronald')
// with more than one name part
const firstnames = new Firstname('Emilia', ['Isobel', 'Euphemia', 'Rose'])
firstnames.tostring() // => Emilia
// include all the names
firstnames.tostring(true) // => Emilia Isobel Euphemia Rose

An instance of this class handles separately the required namon along with the optional other given names a person might have.

API:

MethodsArgumentsDefaultReturnsDescription
tostringincludeAllfalsestringReturns a string representation of the first name
getInitialsincludeAllfalsestring[]Gets the initials of the first name
describeincludeAllfalseSummaryGives some descriptive statistics of the characters' distribution

Aliases:

None

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.

constructor
/**
* Constructs a `Lastname`
* @param father a piece of string that will be defined as a namon
* @param mother additional pieces considered as a last name
* @param format how to output a surname considering its subparts
*/
constructor(
public father: string,
public mother?: string,
private format: LastnameFormat = 'father'
);

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:

import { Lastname } from 'namefully'
const lastname = new Lastname('Pitt')
lastname.tostring() // => Pitt
lastname.tostring('father') // => Pitt
lastname.tostring('mother') // => '' (empty string)
lastname.tostring('hyphenated') // => Pitt
// with the mother's name
const lastnames = new Lastname('Pitt', 'Jolie')
lastnames.tostring() // => Pitt Jolie
lastnames.tostring('father') // => Pitt
lastnames.tostring('mother') // => Jolie
lastnames.tostring('hyphenated') // => Pitt-Jolie
// with the mother's name and format
const format = new Lastname('Pitt', 'Jolie', 'mother')
format.tostring() // => Jolie
format.tostring('father') // => Pitt
format.tostring('mother') // => Jolie
format.tostring('hyphenated') // => Pitt-Jolie

API:

MethodsArgumentsDefaultReturnsDescription
tostringformatnullstringReturns a string representation of the last name
getInitialsformatnullstring[]Gets the initials of the last name
describeformatnullSummaryGives some descriptive statistics of the characters' distribution

Aliases:

None

Not sure to know how to use these classes? See some examples.

Summary

Another class, which does not seem to be very useful but is provided anyway, is: Summary. It represents the statistical summary of a string representation or a namon. The derived categorical statistics is:

  • count: number of characters in the namon
  • top: which character appears more frequently
  • frequency: how many times this frequent character appears
  • unique: how many unique characters

This is actually what the describe() method is doing.

Example:

import { Summary, Firstname } from 'namefully'
const martha = new Firstname('Martha').describe()
martha.count // => 6
martha.top // => A
martha.frequency // => 2
martha.unique // => 5
const spell = new Summary('abracadabra') // Avada Kedavra
spell.count // => 11
spell.top // => A
spell.frequency // => 5
spell.unique // => 5

Back to Top