Files
site/node_modules/stringify-entities/lib/util/to-hexadecimal.js
T
site-admin 3ac81d5a52
deploy / build-and-publish (push) Successful in 1m37s
the editable site (validation-lab)
2026-11-21 08:03:55 +01:00

21 lines
590 B
JavaScript

const hexadecimalRegex = /[\dA-Fa-f]/
/**
* Configurable ways to encode characters as hexadecimal references.
*
* @param {number} code
* Code point.
* @param {number} next
* Code point of the next character (or `NaN`).
* @param {boolean | null | undefined} omit
* Whether to omit the semicolon when possible.
* @returns {string}
* Hexadecimal reference.
*/
export function toHexadecimal(code, next, omit) {
const value = '&#x' + code.toString(16).toUpperCase()
return omit && next && !hexadecimalRegex.test(String.fromCharCode(next))
? value
: value + ';'
}