to-hexadecimal.js 436 B

12345678910111213141516
  1. const hexadecimalRegex = /[\dA-Fa-f]/
  2. /**
  3. * Configurable ways to encode characters as hexadecimal references.
  4. *
  5. * @param {number} code
  6. * @param {number} next
  7. * @param {boolean|undefined} omit
  8. * @returns {string}
  9. */
  10. export function toHexadecimal(code, next, omit) {
  11. const value = '&#x' + code.toString(16).toUpperCase()
  12. return omit && next && !hexadecimalRegex.test(String.fromCharCode(next))
  13. ? value
  14. : value + ';'
  15. }