UNPKG

emmet.sdk

Version:
40 lines 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hexToDecimalString = void 0; function hexToDecimalString(s) { const hexToDecimalMap = { '0': '0', '1': '1', '2': '2', '3': '3', '4': '4', '5': '5', '6': '6', '7': '7', '8': '8', '9': '9', 'a': '10', 'b': '11', 'c': '12', 'd': '13', 'e': '14', 'f': '15', }; let hexString = s.startsWith('0x') ? s.slice(2) : s; let decimalValue = '0'; for (let i = hexString.length - 1; i >= 0; i--) { const hexDigit = hexString[i].toLowerCase(); const decimalDigit = hexToDecimalMap[hexDigit]; if (decimalDigit === undefined) { throw new Error(`Invalid hexadecimal character: ${hexDigit}`); } const powerOf16 = BigInt(hexString.length - 1 - i); const digitValue = BigInt(decimalDigit); decimalValue = (BigInt(decimalValue) + digitValue * (16n ** powerOf16)).toString(); } return decimalValue; } exports.hexToDecimalString = hexToDecimalString; //# sourceMappingURL=hexToDecimalString.js.map