\href{https://travis-ci.org/mdevils/node-html-entities}{\texttt{ }} \href{https://coveralls.io/github/mdevils/node-html-entities?branch=master}{\texttt{ }}

Fast html entities library.\hypertarget{md_sfcode_node_modules_html_entities_README_autotoc_md11669}{}\doxysection{Installation}\label{md_sfcode_node_modules_html_entities_README_autotoc_md11669}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install html-\/entities }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_html_entities_README_autotoc_md11670}{}\doxysection{Usage}\label{md_sfcode_node_modules_html_entities_README_autotoc_md11670}
{\bfseries{XML entities}}

HTML validity and XSS attack prevention you can achieve from Xml\+Entities class.


\begin{DoxyCode}{0}
\DoxyCodeLine{const Entities = require('html-\/entities').XmlEntities;}
\DoxyCodeLine{}
\DoxyCodeLine{const entities = new Entities();}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(entities.encode('<>"{}\(\backslash\)'\&©®')); // \&lt;\&gt;\&quot;\&apos;\&amp;©®}
\DoxyCodeLine{console.log(entities.encodeNonUTF('<>"{}\(\backslash\)'\&©®')); // \&lt;\&gt;\&quot;\&apos;\&amp;\&\#169;\&\#174;}
\DoxyCodeLine{console.log(entities.encodeNonASCII('<>"{}\(\backslash\)'\&©®')); // <>"{}\(\backslash\)'\&©®}
\DoxyCodeLine{console.log(entities.decode('\&lt;\&gt;\&quot;\&apos;\&amp;\&copy;\&reg;\&\#8710;')); // <>"{}'\&\&copy;\&reg;∆ }

\end{DoxyCode}


{\bfseries{All HTML entities encoding/decoding}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const Entities = require('html-\/entities').AllHtmlEntities;}
\DoxyCodeLine{}
\DoxyCodeLine{const entities = new Entities();}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(entities.encode('<>"{}\&©®∆')); // \&lt;\&gt;\&quot;\&amp;\&copy;\&reg;∆}
\DoxyCodeLine{console.log(entities.encodeNonUTF('<>"{}\&©®∆')); // \&lt;\&gt;\&quot;\&amp;\&copy;\&reg;\&\#8710;}
\DoxyCodeLine{console.log(entities.encodeNonASCII('<>"{}\&©®∆')); // <>"{}\&©®\&\#8710;}
\DoxyCodeLine{console.log(entities.decode('\&lt;\&gt;\&quot;\&amp;\&copy;\&reg;')); // <>"{}\&©® }

\end{DoxyCode}


{\bfseries{Available classes}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const XmlEntities = require('html-\/entities').XmlEntities, // <>"{}'\& + \&\#...; decoding}
\DoxyCodeLine{      Html4Entities = require('html-\/entities').Html4Entities, // HTML4 entities.}
\DoxyCodeLine{      Html5Entities = require('html-\/entities').Html5Entities, // HTML5 entities.}
\DoxyCodeLine{      AllHtmlEntities = require('html-\/entities').AllHtmlEntities; // Synonym for HTML5 entities. }

\end{DoxyCode}


Supports four methods for every class\+:


\begin{DoxyItemize}
\item encode — encodes, replacing characters to its entity representations. Ignores UTF characters with no entity representation.
\item encode\+Non\+UTF — encodes, replacing characters to its entity representations. Inserts numeric entities for UTF characters.
\item encode\+Non\+ASCII — encodes, replacing only non-\/\+ASCII characters to its numeric entity representations.
\item decode — decodes, replacing entities to characters. Unknown entities are left as is. 
\end{DoxyItemize}