Staquia API
    Preparing search index...

    Class Position

    The default class of the positions: data plus the comparison functions.

    You never create positions with new: a Staquia system creates them (forge, start, next, previous, core) as instances of its own subclass of this class (or of the class passed in its options), so position instanceof Position is true. Extend it to add your own methods to every position, see IStaquiaOptions.

    import Staquia, { Position } from "staquia";

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

    const start = system.start();
    if (start.ok) {
    console.log(start.value instanceof Position); // true
    console.log(start.value.toString()); // "mmmmm!"
    }

    Implements

    Index

    Constructors

    Properties

    length: number

    The length measured when the position was created (N plus Z), the one the threshold and the max length are compared with. It doesn't count the zeroes that complete the string: "mmmmm!" created by start has 5, "ab!!!!" forged from "ab" has 2.

    The digits of the N section.

    The digits of the Z section.

    Methods

    • Compares this with other, like a sort comparator.

      Parameters

      Returns Ordering

      "less" if this goes before other, "equal" if they have the same value, "greater" if it goes after.

      import Staquia from "staquia";

      const system = Staquia.create("!", "a", "z", 5, 15, 0.15);
      const a = system.forge("mmmmm!m");
      const b = system.forge("mmmmn");

      if (a.ok && b.ok) console.log(a.value.compare(b.value)); // "less"
    • Gets all the digits of the position in a single number: N as the integer part and Z below it. It is used to compare positions, and system.from creates a position back from it.

      Returns IDigits

    • Checks if this and other have the same value.

      Parameters

      Returns boolean

      true if both have the same value.

      import Staquia from "staquia";

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

      // Zeroes to the right don't change the value
      if (a.ok && b.ok) console.log(a.value.equal(b.value)); // true
    • Checks if this goes before other.

      Parameters

      • other: IPosition

        The right side of the comparison.

      Returns boolean

      true if this < other.

      import Staquia from "staquia";

      const system = Staquia.create("!", "a", "z", 5, 15, 0.15);
      const a = system.forge("mmmmm!m");
      const b = system.forge("mmmmn");

      if (a.ok && b.ok) {
      console.log(a.value.less(b.value)); // true
      console.log(a.value.greater(b.value)); // false
      }