UNPKG

html-entities-decode

Version:
23 lines (13 loc) 494 B
/* IMPORT */ import entities from './entities'; /* HTML ENTITIES DECODE */ const re = /&(?:([a-zA-Z0-9]+)|#([0-9]{1,6})|#[xX]([a-fA-F0-9]{1,6}));/g; function decode ( str: string ): string { return str.replace ( re, ( match: string, $1: string, $2: string, $3: string ) => { if ( $1 ) return entities[$1] || match; if ( $2 ) return String.fromCodePoint ( parseInt ( $2 ) ); return String.fromCodePoint ( parseInt ( $3, 16 ) ); }); } /* EXPORT */ export default decode;