GithubHelp home page GithubHelp logo

node-html-entities's Introduction

html-entities

Build Status Coverage Status

Fast html entities library.

Installation

$ npm install html-entities

Usage

XML entities

HTML validity and XSS attack prevention you can achieve from XmlEntities class.

const Entities = require('html-entities').XmlEntities;

const entities = new Entities();

console.log(entities.encode('<>"\'&©®')); // &lt;&gt;&quot;&apos;&amp;©®
console.log(entities.encodeNonUTF('<>"\'&©®')); // &lt;&gt;&quot;&apos;&amp;&#169;&#174;
console.log(entities.encodeNonASCII('<>"\'&©®')); // <>"\'&©®
console.log(entities.decode('&lt;&gt;&quot;&apos;&amp;&copy;&reg;&#8710;')); // <>"'&&copy;&reg;∆

All HTML entities encoding/decoding

const Entities = require('html-entities').AllHtmlEntities;

const entities = new Entities();

console.log(entities.encode('<>"&©®∆')); // &lt;&gt;&quot;&amp;&copy;&reg;∆
console.log(entities.encodeNonUTF('<>"&©®∆')); // &lt;&gt;&quot;&amp;&copy;&reg;&#8710;
console.log(entities.encodeNonASCII('<>"&©®∆')); // <>"&©®&#8710;
console.log(entities.decode('&lt;&gt;&quot;&amp;&copy;&reg;')); // <>"&©®

Available classes

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

Supports four methods for every class:

  • encode — encodes, replacing characters to its entity representations. Ignores UTF characters with no entity representation.
  • encodeNonUTF — encodes, replacing characters to its entity representations. Inserts numeric entities for UTF characters.
  • encodeNonASCII — encodes, replacing only non-ASCII characters to its numeric entity representations.
  • decode — decodes, replacing entities to characters. Unknown entities are left as is.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.