Interface CdigitAlgo

The common interface for check digit algorithm implementations.

interface CdigitAlgo {
    longName: string;
    name: string;
    compute(strWithoutCheckChars): string;
    computeFromNumVals(numValsWithoutCheckChars): number[];
    generate(strWithoutCheckChars): string;
    parse(strWithCheckChars): [string, string];
    validate(strWithCheckChars): boolean;
}

Properties

longName: string

A human-readable name of the algorithm.

name: string

The cdigit name of the algorithm.

Methods

  • Generates the check characters from the argument using the algorithm. Unlike generate(), this method returns the check characters only.

    Parameters

    • strWithoutCheckChars: string

      A string without check characters.

    Returns string

    The check characters.

    Throws

    SyntaxError if an algorithm-specific syntax error occurs. Note that the bundled algorithm objects do not generally throw errors because they ignore the unknown letters in the string to be protected.

  • Generates the check characters from the argument using the algorithm. This method is an alphabet-independent equivalent of compute(), where the return value and argument are both represented as arrays of each digit's numerical value.

    Parameters

    • numValsWithoutCheckChars: number[]

      A string without check characters decoded to an array of numerical values.

    Returns number[]

    The check characters decoded to an array of numerical values.

    Throws

    SyntaxError if the argument contains an invalid numerical value or any other algorithm-specific syntax error occurs.

  • Generates the protected string from the argument using the algorithm. The generated string consists of the original bare string and computed check characters, which are combined in accordance with the algorithm.

    Parameters

    • strWithoutCheckChars: string

      A string without check characters.

    Returns string

    The string with check characters.

    Throws

    SyntaxError if an algorithm-specific syntax error occurs. Note that the bundled algorithm objects do not generally throw errors because they ignore the unknown letters in the string to be protected.

  • Splits a protected string into the pair of original bare string and check characters.

    Parameters

    • strWithCheckChars: string

      A string with check characters.

    Returns [string, string]

    The tuple of [string without check characters, check characters].

    Throws

    SyntaxError if the argument does not contain check characters or any other algorithm-specific syntax error occurs. Note that the bundled algorithm objects do not generally throw errors because they ignore the unknown letters in the string to be protected.

  • Checks if a protected string is valid per the algorithm.

    Parameters

    • strWithCheckChars: string

      A string with check characters.

    Returns boolean

    True if the argument is valid.

    Throws

    SyntaxError if the argument does not contain check characters or any other algorithm-specific syntax error occurs. Note that the bundled algorithm objects do not generally throw errors because they ignore the unknown letters in the string to be protected.