mirror of
https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git
synced 2025-12-17 14:05:12 +00:00
17 lines
436 B
JavaScript
17 lines
436 B
JavaScript
const hexadecimalRegex = /[\dA-Fa-f]/
|
|
|
|
/**
|
|
* 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 && !hexadecimalRegex.test(String.fromCharCode(next))
|
|
? value
|
|
: value + ';'
|
|
}
|