to-decimal.js 392 B

12345678910111213141516
  1. const decimalRegex = /\d/
  2. /**
  3. * Configurable ways to encode characters as decimal references.
  4. *
  5. * @param {number} code
  6. * @param {number} next
  7. * @param {boolean|undefined} omit
  8. * @returns {string}
  9. */
  10. export function toDecimal(code, next, omit) {
  11. const value = '&#' + String(code)
  12. return omit && next && !decimalRegex.test(String.fromCharCode(next))
  13. ? value
  14. : value + ';'
  15. }