Staquia API
    Preparing search index...

    Class NumberSystem

    Creates a number system using the composition pattern.

    Implements

    Index

    Constructors

    Properties

    after: (
        this: INumberSystem & IAlgorithms,
        value: IDigits,
        trim?: boolean,
    ) => IDigits = after

    Resolves the following value of the given number.

    Type Declaration

    The input number

    If set to true trims the input value before resolve

    The resolved next number

    base: number

    The number of digits, including the zero: (last - first) + 2.

    before: (
        this: INumberSystem & IAlgorithms,
        value: IDigits,
        trim?: boolean,
    ) => IDigits = before

    Resolves the previous value of the given number.

    Type Declaration

    between: (
        this: INumberSystem & IAlgorithms & ICrafter,
        before: IDigits,
        after: IDigits,
        round: boolean,
    ) => IDigits = between

    Gets the mid position for any number with the equation q = (nf + n0) / 2, where:

    • n0 represents the start string converted from the nth base to the 10th base
    • n1 represents the end string converted from the nth base to the 10th base

    Type Declaration

      • (
            this: INumberSystem & IAlgorithms & ICrafter,
            before: IDigits,
            after: IDigits,
            round: boolean,
        ): IDigits
      • Because an odd base is being used, to get the mid position for any number the equation q = (nf + n0) / 2, where:

        • n0 represents the start string converted from the nth base to the 10th base
        • n1 represents the end string converted from the nth base to the 10th base

        Parameters

        Returns IDigits

        q - ( q mod 2 ), should be used as the result.

        When q mod 2 is different from 0 then the mid character from the set of the nth base, should be placed at the end of the output.

    In the evaluation of two strings n1 < n2 must be n1

    In the evaluation of two strings n1 < n2 must be n2

    Rounds the result to the nearest upper integer if set to true

    The value q - ( q mod 2 ) When q mod 2 is different from 0 then the mid character from the set of the nth base, should be placed at the end of the output.

    clean: (
        this: IAlgorithms & ICrafter,
        value: IDigits,
        before: IDigits,
        after: IDigits,
    ) => IDigits = clean

    Checks that a value is between two numbers such that: before < value < after

    Type Declaration

    The value that will be checked to be beween the numbers

    The lower bound number

    The upper bound number

    the cleaned number

    compactNumbers: (
        this: INumberSystem,
        number1: IDigits,
        number2: IDigits,
        repeated: IDigits,
        mode: HalfMode,
    ) => void = compactNumbers

    Ignores the zero values from the left until a number is found, then pass any repeated values to the repeated number and finally stores the different values as code

    Type Declaration

      • (
            this: INumberSystem,
            number1: IDigits,
            number2: IDigits,
            repeated: IDigits,
            mode: HalfMode,
        ): void
      • These arrays will parse the string representing a nth base number where the numbers will have the same size including zeroes (to the right for diverge or left for between) to the one that needs it i.e. yz ~ zzy --> yz! ~ zzy

        Parameters

        Returns void

    The first Number generated

    The second Number generated

    The recovered repeated values

    How the shorter number is padded with zeroes, see HalfMode Both of the numbers will contain a Number.LowerBound value of -1 with a value of 0.

    compose: (this: ILexicon & ICrafter, string: string) => IDigits = compose

    Converts a string to a number: the last character is the key 0, the one before it the key 1, and so on.

    Type Declaration

    core: (
        this: INumberSystem & ICrafter & IAlgorithms & IForger & IComposer,
        previous: IPosition | IPositionResult,
        next: IPosition | IPositionResult,
    ) => IPositionResult = core

    Creates a position between two others, to move or insert an item between its neighbors.

    The room left in the N section is used first. When the positions are adjacent, the Z section takes the middle value, making the position one digit longer. Moving items again and again into the same gap makes positions grow until the threshold (ThresholdReachedError) and the overflow (OverflowError).

    Type Declaration

    import Staquia from "staquia";

    const system = Staquia.create("!", "a", "z", 5, 15, 0.15);
    const start = system.start(); // "mmmmm!"
    const next = system.next(start); // "mmmmn!"

    // Adjacent positions: Z takes the middle value
    const core = system.core(start, next);
    if (core.ok) console.log(core.value.toString()); // "mmmmmn"

    // There is room in N between "a!!!!!" and "b!!!!!"
    const room = system.core(system.forge("a"), system.forge("b"));
    if (room.ok) console.log(room.value.toString()); // "ammmn!"
    diverge: (
        this: INumberSystem & IAlgorithms & ICrafter,
        value1: IDigits,
        value2: IDigits,
    ) => IDigits = diverge

    This system function will equalize the length of value1 and value2 adding zeroes to the right of the shorter number if needed, then will find the point where CharacterBefore &lt;&gt; CharacterAfter. Upon the room between these:

    • If the room > 1 will only find the value between them
    • If room <= 1 will use and optimized version of the Between function

    Type Declaration

      • (
            this: INumberSystem & IAlgorithms & ICrafter,
            value1: IDigits,
            value2: IDigits,
        ): IDigits
      • system function will equalize the length of Value1 and Value2 adding the zero character to the left of the shorter string if needed, then will find the point where CharacterBefore <> CharacterAfter. Upon the room between these:

        • If the room > 1 will only find the value between them
        • If room <= 1 will use and optimized version of the Between function

        Parameters

        Returns IDigits

    Must be any value such that value1 &lt; value2 or value2 &lt; value1

    Must be any value such that value1 &lt; value2 or value2 &lt; value1

    The string that represents the diverged value

    first: string

    The character of the first digit (1).

    firstUnicodeNumber: number

    The unicode character number that represents the first character value in the set

    forge: (
        this: INumberSystem & IComposer & ILexicon & ICrafter & IUnicodes,
        string: string,
    ) => IPositionResult = forge

    Creates a position from its string, for example one stored in a database.

    When the string is shorter than the N section (ln characters), N is completed with zeroes to the right, which keeps the string order ("xy" becomes "xy!!!!").

    Type Declaration

    import Staquia, { InvalidCharacterError } from "staquia";

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

    const xy = system.forge("xy");
    if (xy.ok) console.log(xy.value.toString()); // "xy!!!!"

    // Every character must be a digit of the system: the zero or a character from first to last
    const invalid = system.forge("abC");
    if (!invalid.ok && invalid.error instanceof InvalidCharacterError) {
    console.log(invalid.error.index); // 2
    }
    from: (
        this: INumberSystem & IComposer & ICrafter,
        number: IDigits,
    ) => IPositionResult = _from

    Creates a position from its digits, the inverse of position.digits().

    The digits are split in the N and Z sections of the system: N takes the ln most significant digits.

    Type Declaration

    import Staquia from "staquia";

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

    if (start.ok) {
    // Rebuilds the same position from its digits
    const copy = system.from(start.value.digits());
    if (copy.ok) console.log(copy.value.toString()); // "mmmmm!"
    }
    getCharacter: (
        this: { firstUnicodeNumber: number; set?: string; zero: string },
        code: number,
    ) => string = getCharacter

    Gets the character of a digit value.

    Type Declaration

      • (
            this: { firstUnicodeNumber: number; set?: string; zero: string },
            code: number,
        ): string
      • A code is returned as a character from the system

        Parameters

        • this: { firstUnicodeNumber: number; set?: string; zero: string }
        • code: number

        Returns string

    The digit value (0 is the zero).

    getCode: (this: INumberSystem & IUnicodes & ILexicon, char: string) => number = getCode

    Gets the digit value of a character.

    Type Declaration

    The character.

    getMiddle: (this: INumberSystem & IUnicodes) => string = getMiddle

    Gets the middle digit of the system: ceil((first + last - 1) / 2), the digit of start().

    half: (
        this: INumberSystem & IAlgorithms & ICrafter,
        beforeCodes: IDigits,
        afterCodes: IDigits,
        round: boolean,
    ) => IDigits = half

    Evaluates two values to check which one goes before, gets the repeated values and after and then transforms them to code.

    Type Declaration

    last: string

    The character of the last digit (base - 1).

    lastUnicodeNumber: number

    The unicode character number that represents the last character value in the set

    lmax: number

    The max length of a position: ln + lz. Longer positions are an OverflowError.

    ln: number

    The fixed length of the N section.

    lz: number

    The max length of the Z section.

    "lϰ": number

    The threshold length: ceil((1 - ϰ) * lmax). Positions that reach it are returned inside a ThresholdReachedError, an early warning before the overflow.

    next: (
        this: INumberSystem & ICrafter & IForger & IAlgorithms,
        reference: IPosition | IPositionResult,
    ) => IPositionResult = next

    Creates the position right after another, to stack an item at the end of a list.

    It adds 1 to the N section, so the position never gets longer. When N is already its last value (every digit is last) it fails with an OverflowError.

    Type Declaration

    import Staquia from "staquia";

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

    const next = system.next(system.start());
    if (next.ok) console.log(next.value.toString()); // "mmmmn!"

    // Results can be chained, an error is passed along
    const third = system.next(system.next(system.start()));
    if (third.ok) console.log(third.value.toString()); // "mmmmo!"

    // "zzzzz" is the last value of N
    const overflow = system.next(system.forge("zzzzz"));
    console.log(overflow.ok); // false, an OverflowError
    number: new () => IDigits

    The class of the numbers (Digits by default). The system creates its instances with new and then initializes their digits, bounds and map.

    position: new () => IPosition

    The class of the positions (Position by default). The system creates its instances with new and then sets their n, z and length.

    previous: (
        this: INumberSystem & ICrafter & IForger & IAlgorithms,
        reference: IPosition | IPositionResult,
    ) => IPositionResult = previous

    Creates the position right before another, to stack an item at the start of a list.

    It subtracts 1 from the N section, so the position never gets longer. When N is already its first value (every digit is zero) it fails with an OverflowError.

    Type Declaration

    import Staquia from "staquia";

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

    const previous = system.previous(system.start());
    if (previous.ok) console.log(previous.value.toString()); // "mmmml!"

    // "!!!!!" is the first value of N
    const overflow = system.previous(system.forge("!!!!!"));
    console.log(overflow.ok); // false, an OverflowError
    raw: (
        this: ICrafter & INumberSystem,
        position: IPosition,
        upperBound: number,
    ) => IDigits = raw

    Converts a position to a single number (N followed by Z).

    Type Declaration

    reduce: (
        this: { getCharacter: (code: number) => string },
        number: IDigits,
    ) => string = reduce

    Converts a number to its string with the system characters.

    Type Declaration

      • (this: { getCharacter: (code: number) => string }, number: IDigits): string
      • Parameters

        • this: { getCharacter: (code: number) => string }
          • getCharacter: (code: number) => string
        • number: IDigits

          The number to convert.

        Returns string

    resolveOverflow: (this: INumberSystem, number: IDigits) => void = resolveOverflow

    If the number has overflows it will resolve them

    Type Declaration

    set?: string

    The characters of a system whose digits are not a range: the zero followed by every digit, sorted by their code (undefined for a range from first to last).

    start: (this: INumberSystem & IForger & ILexicon) => IPositionResult = start

    Creates the recommended first position of a list: the middle digit repeated in the whole N section, so there is the same room to stack items before and after it.

    Type Declaration

    import Staquia from "staquia";

    // The middle digit of "a" to "z" (with the zero "!") is "m"
    const system = Staquia.create("!", "a", "z", 5, 15, 0.15);

    const start = system.start();
    if (start.ok) console.log(start.value.toString()); // "mmmmm!"
    substract: (
        this: INumberSystem & ICrafter,
        left: IDigits,
        right: IDigits,
    ) => ISignedDigits = substract

    It will subtract two numbers and return the result and if it is negative.

    Type Declaration

    The left side of the subtraction

    The right side of the subtraction

    A number containing the subtraction information.

    zero: string

    The character of the zero digit.

    zeroUnicodeNumber: number

    The unicode character number that represents the zero character value in the set

    "ϰ": number

    The factor fϰ (0 to 1) that sets the threshold length lϰ.

    Methods

    • Parameters

      • crafter: ICrafter
      • zero: string
      • first: string
      • last: string
      • n: number
      • z: number
      • ϰ: number
      • Optionalset: string

        The characters when the digits are not a range: the zero followed by every digit, sorted by their code. A set whose digits are consecutive is stored as that range (zero, first and last come from it).

      Returns NumberSystem