Skip to main content
Version: 2.2.0

Class: NameBuilder

An on-the-fly name builder.

The builder uses a lazy-building method while capturing all necessary Names to finally construct a complete Namefully instance.

Example

const builder = NameBuilder.of([Name.first('Thomas'), Name.last('Edison')]);
builder.add(Name.middle('Alva'));
console.log(builder.build()); // 'Thomas Alva Edison'

Extends

Properties

instance

protected instance: Namefully

Inherited from

Builder.instance


postbuild?

protected readonly optional postbuild?: Callback<Namefully, void>

Inherited from

Builder.postbuild


postclear?

protected readonly optional postclear?: VoidCallback

Inherited from

Builder.postclear


prebuild?

protected readonly optional prebuild?: VoidCallback

Inherited from

Builder.prebuild


preclear?

protected readonly optional preclear?: Callback<Namefully, void>

Inherited from

Builder.preclear


queue

protected queue: Name[]

Inherited from

Builder.queue

Accessors

size

Get Signature

get size(): number

Gets the current size of the builder.

Returns

number

Inherited from

Builder.size

Methods

add()

add(...values): void

Adds a value at the end of the queue.

Parameters

values

...Name[]

Returns

void

Inherited from

Builder.add


addFirst()

addFirst(value): void

Adds a value at the beginning of the queue.

Parameters

value

Name

Returns

void

Inherited from

Builder.addFirst


addLast()

addLast(value): void

Adds a value at the end of the queue.

Parameters

value

Name

Returns

void

Inherited from

Builder.addLast


build()

build(options?): Namefully

Builds an instance of Namefully from the previously collected names.

Regardless of how the names are added, both first and last names must exist to complete a fine build. Otherwise, it throws a NameError.

Parameters

options?

NameOptions

Returns

Namefully

Overrides

Builder.build


clear()

clear(): void

Removes all elements in the queue.

Returns

void

Inherited from

Builder.clear


remove()

remove(value): boolean

Removes a single instance of a value from the queue.

Parameters

value

Name

Returns

boolean

Inherited from

Builder.remove


removeFirst()

removeFirst(): Name

Removes and returns the first element of the queue.

Returns

Name

Inherited from

Builder.removeFirst


removeLast()

removeLast(): Name

Removes and returns the last element of the queue.

Returns

Name

Inherited from

Builder.removeLast


removeWhere()

removeWhere(callback): void

Removes all elements matched by the test function from the queue.

Parameters

callback

Callback<Name, boolean>

Returns

void

Inherited from

Builder.removeWhere


retainWhere()

retainWhere(callback): void

Removes all elements not matched by the test function from the queue.

Parameters

callback

Callback<Name, boolean>

Returns

void

Inherited from

Builder.retainWhere


create()

static create(name?): NameBuilder

Creates a base builder from one Name to construct Namefully later.

Parameters

name?

Name

Returns

NameBuilder


of()

static of(...initialNames): NameBuilder

Creates a base builder from many Names to construct Namefully later.

Parameters

initialNames

...Name[]

Returns

NameBuilder


use()

static use(__namedParameters): NameBuilder

Creates a base builder from many Names with lifecycle hooks.

Parameters

__namedParameters
names?

Name[]

postbuild?

Callback<Namefully, void>

postclear?

VoidCallback

prebuild?

VoidCallback

preclear?

Callback<Namefully, void>

Returns

NameBuilder