Use Number.parseInt() for hexadecimal/decimal conversions (#11902)

This commit is contained in:
uncenter 2024-09-30 16:40:54 -04:00 committed by GitHub
parent 15a821e895
commit 14ccea31a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -140,22 +140,6 @@ const getTitleTextIndex = (svgFileContent) => {
return svgFileContent.indexOf(titleStart) + titleStart.length;
};
/**
* Convert a hexadecimal number passed as string to decimal number as integer.
* @param {string} hex The hexadecimal number representation to convert.
* @returns {number} The decimal number representation.
*/
const hexadecimalToDecimal = (hex) => {
let result = 0;
let digitValue;
for (const digit of hex.toLowerCase()) {
digitValue = '0123456789abcdefgh'.indexOf(digit);
result = result * 16 + digitValue;
}
return result;
};
/**
* Shorten a string with ellipsis if it exceeds 20 characters.
* @param {string} string_ The string to shorten.
@ -300,7 +284,7 @@ const config = {
for (const match of hexadecimalCodepoints) {
const charHexReprIndex =
getTitleTextIndex(ast.source) + match.index + 1;
const charDec = hexadecimalToDecimal(match[1]);
const charDec = Number.parseInt(match[1], 16);
let charRepr;
if (xmlNamedEntitiesCodepoints.includes(charDec)) {