@technobuddha/library
Version:
A large library of useful functions
25 lines (18 loc) • 574 B
text/typescript
import { empty } from '../constants';
import floor from '../floor';
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
type Options = {
/** The alphabet to use */
alphabet?: string;
};
export function numberToLetter(n: number, { alphabet = ALPHABET }: Options = {}): string {
const base = alphabet.length;
const letters: string[] = [];
do {
--n;
letters.unshift(alphabet[n % base]);
n = floor(n / base, { tolerance: 0.005 });
} while(n > 0);
return letters.join(empty);
}
export default numberToLetter;