@s-libs/js-core
    Preparing search index...

    Class Encoding

    Convert arbitrary data to and from a compact string representation. Push data into the encoding one field at a time and convert it to a string. Later you can pull it back out in reverse order. The string is as compact as possible because it memorizes only your data, and does not need to capture field names.

    const hexAlphabet = '0123456789abcdef';
    const options = ['disagree', 'neutral', 'agree'];

    // encode some survey answers into a hex string
    encoding = new Encoding();
    encoding.pushInteger(5, 1, 5); // encode 5, where it could be between 1-5
    encoding.pushBoolean(true);
    encoding.pushOption('agree', options);
    const hexString = encoding.popStringEncoding(hexAlphabet);
    expect(hexString).toBe('1d');

    // later decode the string back into the survey answers
    encoding = new Encoding();
    encoding.setStringEncoding(hexString, hexAlphabet);
    expect(encoding.popOption(options)).toBe('agree');
    expect(encoding.popBoolean()).toBe(true);
    expect(encoding.popInteger(1, 5)).toBe(5);
    Index

    Constructors

    Methods

    • Returns an indication whether data has been push to this encoding but not popped. It is possible for this to return true even after pushing data. This happens when the only things that have been pushed are represented internally as 0 (such as the flag false, or an option at index 0).

      Returns boolean

    • The bounds can be specified in either order (min, max or max, min).

      Parameters

      • bound1: number
      • bound2: number = 0

      Returns number

    • Parameters

      • length: number
      • alphabet: string

      Returns string

    • Parameters

      • alphabet: string

      Returns string

    • Push a number between the given bounds (inclusive). The bounds can be specified in either order (min, max or max, min).

      Parameters

      • value: number
      • bound1: number
      • bound2: number = 0

      Returns void

    • allows 0

      Parameters

      • value: number

      Returns void

    • Type Parameters

      • T

      Parameters

      • value: T
      • options: readonly T[]

      Returns void

    • Parameters

      • value: string
      • alphabet: string

      Returns void

    • Parameters

      • value: string
      • alphabet: string

      Returns void