index.js 591 B

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