site/node_modules/stringify-entities/lib/util/to-hexadecimal.js
2024-10-14 08:09:33 +02:00

15 lines
393 B
JavaScript

/**
* Configurable ways to encode characters as hexadecimal references.
*
* @param {number} code
* @param {number} next
* @param {boolean|undefined} omit
* @returns {string}
*/
export function toHexadecimal(code, next, omit) {
const value = '&#x' + code.toString(16).toUpperCase()
return omit && next && !/[\dA-Fa-f]/.test(String.fromCharCode(next))
? value
: value + ';'
}