Class: Path

Path(prevopt, lastopt)

A Path is a leaf tree node Scope with additional three properties:

It can be instatiated either from its properties or from a list of items:

Its methods:

create new Paths without modifying the source Path

As a Scope the Path can be iterated only backward, through the method:

To iterate forward, the Path must before be converted into an array, through the method:

More offered methods are:

Constructor

new Path(prevopt, lastopt)

Create a new Path from its properties

Parameters:
Name Type Attributes Description
prev Path <optional>

previous path

last * <optional>

latest step

Classes

Path

Members

last

Latest item

length

The length of this Path

prev

The previous Path

Methods

across(items) → {Iterable.<Path>}

Create as many new Paths as the given items by appending each item to this Path

Parameters:
Name Type Description
items *

variety of steps which can prolong this path

Returns:

iteration dinamically generating each Path

Type
Iterable.<Path>

add(item) → {Path}

Create a new Path by appending the given item to this Path

Parameters:
Name Type Description
item *

a further step

Returns:

a new Path

Type
Path

along(items) → {Path}

Create a new Path by appending all the given item to this Path

Parameters:
Name Type Description
items *

further steps

Returns:

a new Path

Type
Path

forget(key)

Attempts to remove a key binding from this Path.

Parameters:
Name Type Description
key *

The key to forget/remove.

Throws:

Always throws because Path is immutable.

Type
Error

isEmpty() → {Boolean}

Check if this {@Path} is empty

Returns:
Type
Boolean

let(key, value)

Attempts to bind a value to a key in this Path.

Parameters:
Name Type Description
key *

The key to bind.

value *

The value to associate with the key.

Throws:

Always throws because Path is immutable.

Type
Error

letChild(name, child)

Attempts to bind a child Scope or Path to this Path under a given name.

Parameters:
Name Type Description
name string

The name under which to bind the child.

child *

The child Scope or Path to bind.

Throws:

Always throws because Path is immutable.

Type
Error

toArray(n, fopt) → {Array.<*>}

Copy latest n steps of this Path into an array

Parameters:
Name Type Attributes Default Description
n number

number of steps to copy

f function <optional>
item=>item

function to apply to each step

Returns:

array of transformed steps

Type
Array.<*>

(static) of(…steps) → {Path}

Create a new Path from its items

Parameters:
Name Type Attributes Description
steps Iterable.<*> <repeatable>

the items of the Path

Returns:

the Path of the given items

Type
Path

(static) ofProperties(obj, keys, creatoropt) → {Path}

Builds the path of values specified by the given keys. The traversal stops at the first undefined key.

If a creator function is passed, undefined properties along the path are created.

Parameters:
Name Type Attributes Description
obj Object

The root object

keys Array

An array of keys representing the path

creator function <optional>

A function with two arguments (obj, key) that creates the property if it's undefined

Returns:
  • The path of values
Type
Path