Class Position

This objects represents a postion instace that can be divided in:

  • n as the part that helps the position to move up and down
  • z as the part that helps to expand on reinsertions

Each instance contains functions that helps to get the next, previous or even between positions values. Plus validation and comparation logic.

By default this position will be generated using the defined staquia number sytem as reference.

Example

import { staquia } from "staquia";

// Create an instance directly from the global staquia instance,
const position = staquia.position();

Hierarchy

  • Position

Constructors

Properties

#n: string = ""

Left number for after and before operations

#system: NumberSystem

Reference number sytem

#z: string = ""

Right number for diverge and between operations

Accessors

  • get symbol(): symbol
  • Unique symbol attached to every position instance, helps to validate that an object is a pure position and it was not instanciated with another seemingly class or prototype

    Returns symbol

Methods

  • Transforms a string to a position object

    Parameters

    • string: string

      Is the value to be parsed

    Returns void

  • Returns the value that lies between the current postion and another

    Example

    import { staquia } from "staquia";

    // Given a system like this
    let zero = "!"; // Would be like 0
    let first = "a"; // Would be like 1
    let middle = "n"; // Would be like 14
    let last = "z"; // Would be like 26

    // The middle character between two positions
    // can be seen as Math.ceil((first + last) / 2);
    let n = staquia.position(first).core(last); // Will result in "n"

    // When there is no room between 2 positions, the "middle" value
    // from the system will be attached to the last position.
    // This is where the "threshold" and "overflow" handling
    // logic will be applied
    let am = staquia.position("a").core("b"); // Will result in "am"

    Parameters

    Returns Position

  • Gets the relative next position from another position

    Example

    // The character "a" is followed by "b" in the unicode standard
    const nnnb = staquia.position("nnna").next();

    Returns Position

  • Gets the relative next position from another position

    Example

    // The character "b" is followed by "a" in the unicode standard
    const nnna = staquia.position("nnnb").next();

    Returns Position

  • Compares an object or a string to see if it is equals to the current instance

    Example

    const original = staquia.position("nnnnnz");

    // Can be compared with another instance
    const instance = staquia.position("nnnnnz");
    original.toEquals(instance);

    // Can be compared with a valid position string
    const string = "nnnnnz";
    original.toEquals(string);

    // Can be compared with a valid position object
    const object = { n: "nnnnn", z: "z"};
    original.toEquals(object);

    Parameters

    Returns boolean

  • Gets the n and z values

    Example

    // Asuming the "n" segment length is like below
    let ln = 5;

    // Create it as a string
    const position = staquia.position("n");
    postion.toObject

    // Will look like this
    let object = {
    n: "!!!!n",
    z: "!"
    }

    Returns PositionObject

  • Concatenates the n value with the z

    Example

    // Asuming the "n" segment length is like below
    let ln = 5;

    // Create it as an object
    const position = staquia.position({
    n: "n",
    z: "zzzz",
    });

    // Will print "!!!!nzzzz" as will attach leading zeroes
    const string = position.toString();

    Returns string

  • With this function the position instances can be compared as plain strings with the less than < and greater than > operators

    Example

    // Create your positions
    const a = staquia.position("a");
    const b = staquia.position("b");

    // Just compare them as plain objects
    a < b // Will return false
    a > b // Will return true

    Returns string

  • Determines if an object is a position instance

    Parameters

    • Optional value: any

    Returns value is Position

Generated using TypeDoc