index.js 634 B

12345678910111213141516171819
  1. import {characterEntities} from 'character-entities'
  2. // To do: next major: use `Object.hasOwn`.
  3. const own = {}.hasOwnProperty
  4. /**
  5. * Decode a single character reference (without the `&` or `;`).
  6. * You probably only need this when you’re building parsers yourself that follow
  7. * different rules compared to HTML.
  8. * This is optimized to be tiny in browsers.
  9. *
  10. * @param {string} value
  11. * `notin` (named), `#123` (deci), `#x123` (hexa).
  12. * @returns {string|false}
  13. * Decoded reference.
  14. */
  15. export function decodeNamedCharacterReference(value) {
  16. return own.call(characterEntities, value) ? characterEntities[value] : false
  17. }