texttonumber-npm-package
Version:
This package is useful for convert given text to their corresponding digit.
19 lines (17 loc) • 478 B
JavaScript
const textToNum = (text) => {
if (!text) return;
if (typeof text != "string") return;
const lower_text = text.toUpperCase().trim();
let str_code = "";
let count = 0;
for (let i = 0; i < lower_text.length; i++) {
let diff = lower_text.charCodeAt(i) - 64;
if (diff > 0 && diff <= 26) {
count++;
str_code = str_code + diff;
}
}
str_code = str_code + "00" + count;
return parseInt(str_code);
};
export default textToNum;