xmlunidefuse

0.1.4 • Public • Published

xmlunidefuse

Encode the predefined XML entities (amp, lt, gt, apos, quot) and some additional, easily overlooked Unicode characters. Opt-out CharRef 39 for HTML (Why?).

Usage

From test.js:

var xud = require("xmlunidefuse"), eq = require("assert").strictEqual,
  raw = "<​!-- <u snow=\"man'>☃</u -->";
 
eq(xud(raw),        //  HTML compat mode:    v..
  "&lt;&#x200B;!-- &lt;u&#xA0;snow=&quot;man&#39;&gt;☃&lt;/u&#x205F;--&gt;");
 
eq(xud.apos(raw),   //  apos opt-in:         v...
  "&lt;&#x200B;!-- &lt;u&#xA0;snow=&quot;man&apos;&gt;☃&lt;/u&#x205F;--&gt;");
 
//  CDATA mode is implemented but not recommended,
//  because it makes the sneaky chars VERY visible.
eq(xud.cdata(raw),
  '<![CDATA[<]]>&#x200B;<![CDATA[!-- <u]]>&#xA0;<![CDATA[snow="ma' +
  "n'>☃</u]]>&#x205F;<![CDATA[-->]]>");

Related

  • univeil: Unveil sneaky Unicode characters.
  • xmldefuse: Encode only the predefined XML entities.
  • xmldecode: Decode the predefined XML entities, CharRefs and CDATA sections.

License

ISC

Package Sidebar

Install

npm i xmlunidefuse

Weekly Downloads

3

Version

0.1.4

License

ISC

Last publish

Collaborators

  • mk-pmb