Pathfinder

Pathfinder is a class to find a path to an object.

Import
the javascript logo
import { Pathfinder } from "@schukai/monster/source/data/pathfinder.mjs";
Source
the git logo
Package
the npm logo
Since
1.4.0

Example 1

import {Pathfinder} from '@schukai/monster/source/data/pathfinder.mjs';

let value = new Pathfinder({
    a: {
        b: {
            f: [
                {
                    g: false,
                }
            ],
        }
    }
}).getVia("a.b.f.0.g");

console.log(value);
// ↦ false

try {
    new Pathfinder({}).getVia("a.b.f.0.g");
} catch (e) {
    console.log(e.toString());
    // ↦ Error: the journey is not at its end (b.f.0.g)
}

Example 2

import {Pathfinder} from '@schukai/monster/source/data/pathfinder.mjs';

let p = new Pathfinder({
    a: {
        x: [
            {c: 1}, {c: 2}
        ],
        y: true
    },
    b: {
        x: [
            {c: 1, d: false}, {c: 2}
        ],
        y: true
    },
});

let r = p.getVia("*.x.*.c");
console.log(r);

Exported

Pathfinder, DELIMITER, WILDCARD

Derived from

Base

Options

The Options listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the Base.

Option
Type
Default
Description
-/-

Properties

The Properties listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Properties from these parent classes. If you cannot find a specific Properties in this list, we recommend consulting the documentation of the Base.

Methods

The methods listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the Base.

Constructor

constructor(object)
Parameters
  • object {object}: - The object parameter for the constructor.
Throws
  • {Error} Throws an error if the provided object parameter is a simple type.
Creates a new instance of the constructor.

Structural methods

getVia(path)1.4.0
Parameters
  • path {string|array}: path
Returns
  • {*}
Throws
  • {TypeError} unsupported type
  • {Error} the journey is not at its end
  • {TypeError} value is not a string
  • {TypeError} value is not an integer
  • {Error} unsupported action for this data type
setVia(path,value)1.4.0
Parameters
  • path {string|array}: path
  • value {*}: value
Returns
  • {Pathfinder}
Throws
  • {TypeError} unsupported type
  • {TypeError} value is not a string
  • {TypeError} value is not an integer
  • {Error} unsupported action for this data type
setWildCard(wildcard)1.7.0
Parameters
  • wildcard {string}: wildcard
Returns
  • {Pathfinder}
set wildcard

Other methods

deleteVia(path)1.6.0
Parameters
  • path {string|array}: path
Returns
  • {Pathfinder}
Throws
  • {TypeError} unsupported type
  • {TypeError} value is not a string
  • {TypeError} value is not an integer
  • {Error} unsupported action for this data type
Delete Via Path
exists(path)1.4.0
Parameters
  • path {string|array}: path
Returns
  • {bool}
Throws
  • {TypeError} unsupported type
  • {TypeError} value is not a string
  • {TypeError} value is not an integer

Events

This component does not fire any public events. It may fire events that are inherited from its parent classes.

The current width of the area is too small to display the content correctly.