Staquia API
    Preparing search index...

    Class LexicalItem<K, T>

    An object stored in a LexicalList, with its position and the ids of its neighbors.

    Setting its position also updates the position string of the wrapped object, so your object is always ready to be saved.

    import Staquia, { LexicalList } from "staquia";

    const list = new LexicalList(Staquia.create("!", "a", "z", 5, 15, 0.15));
    list.push({ id: 1, position: "" });
    list.push({ id: 2, position: "" });

    const item = list.find(2);
    if (item) {
    console.log(item.position.toString()); // "mmmmn!"
    console.log(item.previous, item.next); // 1 undefined
    }

    Type Parameters

    • K

      The type of the id.

    • T extends Item<K>

      The type of the wrapped object.

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    • Wraps an object with a position, writing it to the object's position field. The list creates its items: use LexicalItem.from to create one from a stored position.

      Type Parameters

      • K

        The type of the id.

      • T extends Item<K>

        The type of the wrapped object.

      Parameters

      • value: T

        The object to wrap.

      • position: IPosition

        Its position.

      Returns LexicalItem<K, T>

    Properties

    next?: K

    The id of the next item in the list, or undefined if this is the last one.

    previous?: K

    The id of the previous item in the list, or undefined if this is the first one.

    Accessors

    Methods

    • Creates an item from an object whose position string is already set, forging it with the system.

      Type Parameters

      • K

        The type of the id.

      • T extends Item<K>

        The type of the wrapped object.

      Parameters

      • system: Staquia

        The system that created the position.

      • value: T

        The object, with its stored position string.

      Returns Result<LexicalItem<K, T>, IPositionError>

      The item, or the error of system.forge (e.g. an InvalidCharacterError).

      import Staquia, { LexicalItem } from "staquia";

      const system = Staquia.create("!", "a", "z", 5, 15, 0.15);

      const item = LexicalItem.from(system, { id: 7, position: "mmmmm!" });
      if (item.ok) console.log(item.value.position.toString()); // "mmmmm!"