All files / roosterjs-content-model-plugins/lib/autoFormat/list convertAlphaToDecimals.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20            1x 49x 49x 46x 46x 58x 58x     46x   3x    
/**
 * @internal
 * Convert english alphabet numbers into decimal numbers
 * @param letter The letter that needs to be converted
 * @returns
 */
export function convertAlphaToDecimals(letter: string): number | undefined {
    const alpha = letter.toUpperCase();
    if (alpha) {
        let result = 0;
        for (let i = 0; i < alpha.length; i++) {
            const charCode = alpha.charCodeAt(i) - 65 + 1;
            result = result * 26 + charCode;
        }
 
        return result;
    }
    return undefined;
}