mirror of
https://github.com/Funkoala14/knowledgebase_law.git
synced 2025-06-08 10:48:15 +08:00
20 lines
634 B
JavaScript
20 lines
634 B
JavaScript
import {characterEntities} from 'character-entities'
|
||
|
||
// To do: next major: use `Object.hasOwn`.
|
||
const own = {}.hasOwnProperty
|
||
|
||
/**
|
||
* Decode a single character reference (without the `&` or `;`).
|
||
* You probably only need this when you’re building parsers yourself that follow
|
||
* different rules compared to HTML.
|
||
* This is optimized to be tiny in browsers.
|
||
*
|
||
* @param {string} value
|
||
* `notin` (named), `#123` (deci), `#x123` (hexa).
|
||
* @returns {string|false}
|
||
* Decoded reference.
|
||
*/
|
||
export function decodeNamedCharacterReference(value) {
|
||
return own.call(characterEntities, value) ? characterEntities[value] : false
|
||
}
|