Skip to main content
Version: 2.2.0

Class: Config

The Configuration to use across the other components.

The multiton pattern is used to handle configurations across the namefully setup. This adds consistency when building other components such as FirstName, LastName, or Name of distinct types that may be of particular shapes.

For example, a person's FullName may appear by:

  • NameOrder.FIRST_NAME: Jon Snow or
  • NameOrder.LAST_NAME: Snow Jon.

Config makes it easy to set up a specific configuration for Namefully and reuse it through other instances or components along the way. If a new Config is needed, a named configuration may be created. It is actually advised to use named Config.create(name) instead as it may help mitigate issues and avoid confusion and ambiguity in the future. Plus, a named configuration explains its purpose.

const defaultConfig = Config.create();
const mergedConfig = Config.merge({ name: 'other', title: Title.US });
const copyConfig = mergedConfig.copyWith({ ending: true });

Additionally, a configuration may be merged with or copied from an existing configuration, prioritizing the new one's values, as shown in the example above.

Accessors​

bypass​

Get Signature​

get bypass(): boolean

A bypass of the validation rules with this option. This option is ideal to avoid checking their validity.

Returns​

boolean


ending​

Get Signature​

get ending(): boolean

The option indicating if an ending suffix is used in a formal way.

Returns​

boolean


mono​

Get Signature​

get mono(): boolean | Namon

Whether to parse a single word name as a mononym.

Returns​

boolean | Namon


name​

Get Signature​

get name(): string

The name of the cached configuration.

Returns​

string


orderedBy​

Get Signature​

get orderedBy(): NameOrder

The order of appearance of a full name.

Returns​

NameOrder


separator​

Get Signature​

get separator(): Separator

The token used to indicate how to split string values.

Returns​

Separator


surname​

Get Signature​

get surname(): Surname

An option indicating how to format a surname.

The supported formats are:

  • FATHER name only
  • MOTHER name only
  • HYPHENATED, joining both father and mother names with a hyphen
  • ALL, joining both father and mother names with a space.

Note that this option can be set when creating a LastName. As this can become ambiguous at the time of handling it, the value set in this is prioritized and viewed as the source of truth for future considerations.

Returns​

Surname


title​

Get Signature​

get title(): Title

The abbreviation type to indicate whether or not to add period to a prefix using the American or British way.

Returns​

Title

Methods​

clone()​

clone(): Config

Makes an exact copy of the current configuration.

Returns​

Config


copyWith()​

copyWith(options?): Config

Returns a copy of this configuration merged with the provided values.

The word _copy is added to the existing config's name to create the new config's name if the name already exists for previous configurations. This is useful to maintain the uniqueness of each configuration. For example, if the new copy is made from the default configuration, this new copy will be named default_copy.

Parameters​

options?​

Partial<Config>

Returns​

Config


reset()​

reset(): void

Resets the configuration by setting it back to its default values.

Returns​

void


update()​

update(__namedParameters): void

Allows the possibility to alter behavior-related options after creating a name set.

Parameters​

__namedParameters​

Partial<Pick<Config, "orderedBy" | "title" | "ending">>

Returns​

void


create()​

static create(name?): Config

Returns a named configuration with default values.

Parameters​

name?​

string

describing its purpose.

Returns​

Config


merge()​

static merge(other?): Config

Returns a combined version of the existing values of the default configuration and the provided optional values of another configuration.

Parameters​

other?​

Partial<Config>

partial config to be combined with.

Returns​

Config