Class BaseFormatter

The class from which to create a BaseFormatter instance for encoding to a string format from specified digits.

Hierarchy

  • BaseFormatter

Constructors

  • The constructor of the BaseFormatter class.

    Parameters

    • digits: string | string[]

      A string of symbols for representing the digits, the length of which determining the base number.

    • options: BaseFormatterOptions = {}

      Optional parameters, for adjusting conversion rules and the encoding output string formatting.

    Returns BaseFormatter

Properties

base: number

The base number

digits: string[]

The digits to use.

properties: Required<BaseFormatterOnlyOptions>

The properties of the class, set by the options of the constructor

Instance Methods

  • Decode an en encoded number according to the instance base and specified digits and properties.

    Throws

    DigitNotFound when the specified string contains unknown characters.

    Parameters

    • encodedValue: string

      An encoded number as a string in the instance base.

    • Optional options: BaseFormatterOptions

      The options to use if, for example, alternative characters were specified during encoding.

    Returns number

    The decoded number.

  • Encodes the specified number according to the instance base and specified digits and properties.

    Parameters

    • numberValue: string | number | Decimal

      The number to encode, as a number, string or Decimal type.

    • Optional options: BaseFormatterOptions

      The options to use for formatting.

    Returns string

    the encoded number as a string.

  • Check if the specified value is a number according to the instance base and specified digits and properties.

    Parameters

    • value: string

      A string to check.

    Returns boolean

    Whether the specified string is a number.

Static Methods

  • This method will take the base number, slice a string of digits 0-9A-Za-z to a length equal to the base number and return an instance of the BaseFormatter class with the sliced string as the digits.

    Throws

    MaximumBaseExceeded when the base number exceeds the maximum amount of this method.

    Parameters

    • base: number

      The base number to use, a maximum of 62.

    • Optional options: BaseFormatterOptions

      The options to use.

    Returns BaseFormatter

    An instance of the BaseFormatter class.

  • This method returns an instance of the BaseFormatter class in base 12 with the digits '0123456789↊↋' and the radix character of ';'. The digits ↊ and ↋ as used by the Dozenal Societies of America and Great Britain.

    Parameters

    Returns BaseFormatter

    An instance of the BaseFormatter class.

  • This method returns an instance of the BaseFormatter class in base 12 with the digits '0123456789TE' and the radix character of ';'. The digits T and E are the ASCII variations of the digits ↊ and ↋ used by the BaseFormatter.dozenal method in case a font doesn't have them.

    Parameters

    Returns BaseFormatter

    An instance of the BaseFormatter class.

  • This method returns an instance of the BaseFormatter class in base 12 with the digits '0123456789XE' and the radix character of ';'. Uses a variant of the digit for 10 using the Roman numeral X.

    Parameters

    Returns BaseFormatter

    An instance of the BaseFormatter class.

  • This method returns an instance of the BaseFormatter class in base 20 with the digits '0123456789ABCDEFGHJK', skipping over I in order to avoid confusion between I and 1.

    Parameters

    Returns BaseFormatter

    An instance of the BaseFormatter class.

Generated using TypeDoc